-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathMapInputWidget.php
89 lines (78 loc) · 1.88 KB
/
MapInputWidget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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);
// [BEGIN] - Map input widget container
echo Html::beginTag(
'div',
[
'class' => 'kolyunya-map-input-widget',
'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,
],
]
);
// 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);