1 | <?php |
||
30 | class LeafLet extends Component |
||
31 | { |
||
32 | // JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK |
||
33 | const JSON_OPTIONS = 352; |
||
34 | |||
35 | /** |
||
36 | * @var integer a counter used to generate [[name]] for layers. |
||
37 | * @internal |
||
38 | */ |
||
39 | public static $counter = 0; |
||
40 | /** |
||
41 | * @var string the prefix to the automatically generated object names. |
||
42 | * @see [[generateName()]] |
||
43 | */ |
||
44 | public static $autoNamePrefix = 'l'; |
||
45 | /** |
||
46 | * @var string the name to give to the variable. The name of the map specified on the |
||
47 | * [[TileLayer]] component overrides this one. |
||
48 | */ |
||
49 | public $name = 'map'; |
||
50 | /** |
||
51 | * @var int the zoom level of the map |
||
52 | */ |
||
53 | public $zoom = 13; |
||
54 | /** |
||
55 | * @var array the options for the underlying LeafLetJs JS component. |
||
56 | * Please refer to the LeafLetJs api reference for possible |
||
57 | * [options](http://leafletjs.com/reference.html). |
||
58 | */ |
||
59 | public $clientOptions = []; |
||
60 | /** |
||
61 | * @var array the event handlers for the underlying LeafletJs JS plugin. |
||
62 | * Please refer to the LeafLetJs js api object options for possible events. |
||
63 | */ |
||
64 | public $clientEvents = []; |
||
65 | /** |
||
66 | * @var Layer[] holding ui layers (do not confuse with map layers, these are markers, popups, polygons, etc) |
||
67 | */ |
||
68 | private $_layers = []; |
||
69 | /** |
||
70 | * @var LayerGroup[] holding layer groups |
||
71 | */ |
||
72 | private $_layerGroups = []; |
||
73 | /** |
||
74 | * @var LatLng sets the center of the map |
||
75 | */ |
||
76 | private $_center; |
||
77 | |||
78 | /** |
||
79 | * Returns the center of the map. |
||
80 | * @return LatLng center of the map. |
||
81 | */ |
||
82 | 33 | public function getCenter() |
|
86 | |||
87 | /** |
||
88 | * Sets the center of the map. |
||
89 | * |
||
90 | * @param LatLng $value center of the map. |
||
91 | */ |
||
92 | 30 | public function setCenter(LatLng $value) |
|
96 | |||
97 | /** |
||
98 | * @var Control[] holding controls to be added to the map. |
||
99 | */ |
||
100 | private $_controls = []; |
||
101 | |||
102 | /** |
||
103 | * @param \dosamigos\leaflet\controls\Control[] $controls |
||
104 | * |
||
105 | * @throws \yii\base\InvalidParamException |
||
106 | */ |
||
107 | 3 | public function setControls(array $controls) |
|
116 | |||
117 | /** |
||
118 | * @return \dosamigos\leaflet\controls\Control[] |
||
119 | */ |
||
120 | 21 | public function getControls() |
|
124 | |||
125 | /** |
||
126 | * @param Control $control |
||
127 | */ |
||
128 | 3 | public function addControl(Control $control) |
|
132 | |||
133 | /** |
||
134 | * @var \dosamigos\leaflet\layers\TileLayer |
||
135 | */ |
||
136 | private $_tileLayer; |
||
137 | |||
138 | /** |
||
139 | * @param \dosamigos\leaflet\layers\TileLayer $tileLayer |
||
140 | * |
||
141 | * @return static the component itself |
||
142 | */ |
||
143 | 18 | public function setTileLayer(TileLayer $tileLayer) |
|
155 | |||
156 | /** |
||
157 | * @return \dosamigos\leaflet\layers\TileLayer |
||
158 | */ |
||
159 | 15 | public function getTileLayer() |
|
163 | |||
164 | /** |
||
165 | * @var array holds the js script lines to be registered. |
||
166 | */ |
||
167 | private $_js = []; |
||
168 | |||
169 | /** |
||
170 | * @param string|array $js custom javascript code to be registered. |
||
171 | * *Warning*: This method overrides any previous settings. |
||
172 | * |
||
173 | * @return static the component itself |
||
174 | */ |
||
175 | 3 | public function setJs($js) |
|
180 | |||
181 | /** |
||
182 | * @param string $js appends javascript code to be registered. |
||
183 | * |
||
184 | * @return static the component itself |
||
185 | */ |
||
186 | 3 | public function appendJs($js) |
|
191 | |||
192 | /** |
||
193 | * @return array the queued javascript code to be registered. |
||
194 | * *Warning*: This method does not include map initialization. |
||
195 | */ |
||
196 | 18 | public function getJs() |
|
219 | |||
220 | /** |
||
221 | * @var PluginManager |
||
222 | */ |
||
223 | private $_plugins; |
||
224 | |||
225 | /** |
||
226 | * @return PluginManager |
||
227 | */ |
||
228 | 21 | public function getPlugins() |
|
232 | |||
233 | /** |
||
234 | * Installs a plugin |
||
235 | * |
||
236 | * @param Plugin $plugin |
||
237 | */ |
||
238 | 18 | public function installPlugin(Plugin $plugin) |
|
243 | |||
244 | /** |
||
245 | * Removes an installed plugin |
||
246 | * |
||
247 | * @param $plugin |
||
248 | * |
||
249 | * @return mixed|null |
||
250 | */ |
||
251 | 3 | public function removePlugin($plugin) |
|
255 | |||
256 | /** |
||
257 | * Initializes the widget. |
||
258 | */ |
||
259 | 33 | public function init() |
|
269 | |||
270 | /** |
||
271 | * Helper method to render the widget. It is also possible to use the widget directly: |
||
272 | * ``` |
||
273 | * echo Map::widget(['leafLet' => $leafLetObject, ...]); |
||
274 | * ``` |
||
275 | * |
||
276 | * @param array $config |
||
277 | * |
||
278 | * @return string |
||
279 | */ |
||
280 | 12 | public function widget($config = []) |
|
289 | |||
290 | /** |
||
291 | * @param Layer $layer the layer script to add to the js script code. It could be any object extending from [[Layer]] |
||
292 | * component (markers, polylines, popup, etc) |
||
293 | * |
||
294 | * @return static the component itself |
||
295 | */ |
||
296 | 18 | public function addLayer(Layer $layer) |
|
301 | |||
302 | /** |
||
303 | * @return Layer[] the stored layers |
||
304 | */ |
||
305 | 18 | public function getLayers() |
|
309 | |||
310 | /** |
||
311 | * @param LayerGroup $group sets a layer group |
||
312 | * |
||
313 | * @return static the component itself |
||
314 | */ |
||
315 | 6 | public function addLayerGroup(LayerGroup $group) |
|
320 | |||
321 | /** |
||
322 | * @return layers\LayerGroup[] all stored layer groups |
||
323 | */ |
||
324 | 21 | public function getLayerGroups() |
|
328 | |||
329 | /** |
||
330 | * Clears all stored layer groups |
||
331 | * @return static the component itself |
||
332 | */ |
||
333 | 3 | public function clearLayerGroups() |
|
338 | |||
339 | /** |
||
340 | * @param Control[] $controls |
||
341 | * |
||
342 | * @return array |
||
343 | */ |
||
344 | 18 | public function getEncodedControls($controls) |
|
348 | |||
349 | /** |
||
350 | * @param LayerGroup[] $groups |
||
351 | * |
||
352 | * @return array |
||
353 | */ |
||
354 | 18 | public function getEncodedLayerGroups($groups) |
|
358 | |||
359 | /** |
||
360 | * @param Plugin[] $plugins |
||
361 | * |
||
362 | * @return array |
||
363 | */ |
||
364 | 18 | public function getEncodedPlugins($plugins) |
|
368 | |||
369 | /** |
||
370 | * @return string |
||
371 | */ |
||
372 | 45 | public static function generateName() |
|
376 | |||
377 | /** |
||
378 | * @param $objects |
||
379 | * |
||
380 | * @return array |
||
381 | */ |
||
382 | 18 | protected function getEncodedObjects($objects) |
|
393 | } |
||
394 |