Skip to content

New features #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions sources/web/js/map-input-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function MapInputWidget ( widget )

var getPattern = function()
{
var pattern = $(widget).data('pattern');
var pattern = $(widget).attr('data-pattern').toString();
return pattern;
};

Expand Down Expand Up @@ -248,10 +248,19 @@ function MapInputWidget ( widget )
// Initializes widget
this.initialize = function()
{

var eventInitializeBefore = jQuery.Event("initializeBefore");
eventInitializeBefore.MapInputWidget = this;
$(widget).trigger(eventInitializeBefore);

initializeComponents();
initializeMap();
initializeWidget();
initializeSearchBar();

var eventInitializeAfter = jQuery.Event("initializeAfter");
eventInitializeAfter.MapInputWidget = this;
$(widget).trigger(eventInitializeAfter);
};

// Returns widget identifier
Expand All @@ -266,7 +275,6 @@ function MapInputWidget ( widget )
// Sets marker position to the corresponding point.
this.setPosition = function ( pointData )
{

if ( map.marker )
{
map.marker.setMap(null);
Expand Down Expand Up @@ -317,8 +325,13 @@ function MapInputWidget ( widget )
);

var pattern = $(widget).data('pattern');
var pointString = makePointString(point);
$(input).prop('value',pointString);

var event = jQuery.Event("makePoint");
event.pointString = makePointString(point);
event.MapInputWidget = this;
$(widget).trigger(event);

$(input).prop('value', event.pointString);

};

Expand All @@ -335,23 +348,10 @@ function MapInputWidget ( widget )
map.setZoom(zoom);
};


};

// A global instance of map inputs manager.
// Use it to get references to widget instances.
var mapInputWidgetManager;

$(window).load
(
function()
// Get google map
this.getMap = function()
{

// Create an instance of widget manager
mapInputWidgetManager = new MapInputWidgetManager();

// Initialize widgets
mapInputWidgetManager.initializeWidgets();

return map;
}
);

};
2 changes: 1 addition & 1 deletion sources/web/js/map-input-widget.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion sources/widgets/MapInputWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class MapInputWidget extends \yii\widgets\InputWidget

public $enableSearchBar = true;

public $viewFile = 'MapInputWidget';

public function run()
{

Expand All @@ -38,7 +40,7 @@ public function run()
$this->configureAssetBundle();

return $this->render(
'MapInputWidget',
$this->viewFile,
[
'id' => $this->getId(),
'model' => $this->model,
Expand Down
104 changes: 67 additions & 37 deletions sources/widgets/views/MapInputWidget.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
<?php
/***
* @var string $id
* @var int $width
* @var int $height
* @var string $latitude
* @var string $longitude
* @var int $zoom
* @var string $pattern
* @var string $mapType
* @var string $animateMarker
* @var string $alignMapCenter
* @var string $enableSearchBar
* @var string $attribute
* @var View $this
*/

use yii\helpers\Html;
use yii\helpers\Url;
use yii\web\View;

// Register asset bundle
\kolyunya\yii2\assets\MapInputAsset::register($this);
Expand All @@ -14,46 +30,60 @@
'style' => "width: $width; height: $height;",
'id' => $id,
'data' =>
[
'latitude' => $latitude,
'longitude' => $longitude,
'zoom' => $zoom,
'pattern' => $pattern,
'map-type' => $mapType,
'animate-marker' => $animateMarker,
'align-map-center' => $alignMapCenter,
'enable-search-bar' => $enableSearchBar,
],
[
'latitude' => $latitude,
'longitude' => $longitude,
'zoom' => $zoom,
'pattern' => $pattern,
'map-type' => $mapType,
'animate-marker' => $animateMarker,
'align-map-center' => $alignMapCenter,
'enable-search-bar' => $enableSearchBar,
],
]
);

// The actual hidden input
echo Html::activeHiddenInput(
$model,
$attribute,
[
'class' => 'kolyunya-map-input-widget-input',
]
);

// Search bar input
echo Html::input(
'text',
null,
null,
[
'class' => 'kolyunya-map-input-widget-search-bar',
]
);

// Map canvas
echo Html::tag(
'div',
'',
[
'class' => 'kolyunya-map-input-widget-canvas',
]
);
// The actual hidden input
echo Html::activeHiddenInput(
$model,
$attribute,
[
'class' => 'kolyunya-map-input-widget-input',
]
);

// Search bar input
echo Html::input(
'text',
null,
null,
[
'class' => 'kolyunya-map-input-widget-search-bar',
]
);

// Map canvas
echo Html::tag(
'div',
'',
[
'class' => 'kolyunya-map-input-widget-canvas',
]
);

// [END] - Map input widget container
echo Html::endTag('div');

$js = <<<JAVASCRIPT
// A global instance of map inputs manager.
// Use it to get references to widget instances.
var mapInputWidgetManager;

// Create an instance of widget manager
mapInputWidgetManager = new MapInputWidgetManager();

// Initialize widgets
mapInputWidgetManager.initializeWidgets();

JAVASCRIPT;
$this->registerJs($js, View::POS_LOAD);