1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Google Map package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Bound; |
15
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
16
|
|
|
use Ivory\GoogleMap\Control\ControlManager; |
17
|
|
|
use Ivory\GoogleMap\Event\EventManager; |
18
|
|
|
use Ivory\GoogleMap\Layer\LayerManager; |
19
|
|
|
use Ivory\GoogleMap\Overlay\OverlayManager; |
20
|
|
|
use Ivory\GoogleMap\Utility\VariableAwareInterface; |
21
|
|
|
use Ivory\GoogleMap\Utility\VariableAwareTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Map |
25
|
|
|
* |
26
|
|
|
* @author GeLo <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class Map implements VariableAwareInterface |
29
|
|
|
{ |
30
|
|
|
use VariableAwareTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $htmlId = 'map_canvas'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
private $autoZoom = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Coordinate |
44
|
|
|
*/ |
45
|
|
|
private $center; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var Bound |
49
|
|
|
*/ |
50
|
|
|
private $bound; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var ControlManager |
54
|
|
|
*/ |
55
|
|
|
private $controlManager; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var EventManager |
59
|
|
|
*/ |
60
|
|
|
private $eventManager; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var LayerManager |
64
|
|
|
*/ |
65
|
|
|
private $layerManager; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var OverlayManager |
69
|
|
|
*/ |
70
|
|
|
private $overlayManager; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string[] |
74
|
|
|
*/ |
75
|
|
|
private $libraries = []; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var mixed[] |
79
|
|
|
*/ |
80
|
|
|
private $mapOptions = []; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var string[] |
84
|
|
|
*/ |
85
|
|
|
private $stylesheetOptions = []; |
86
|
|
|
|
87
|
|
|
public function __construct() |
88
|
|
|
{ |
89
|
|
|
$this->setVariablePrefix('map'); |
90
|
|
|
$this->setCenter(new Coordinate()); |
91
|
|
|
$this->setBound(new Bound()); |
92
|
|
|
$this->setControlManager(new ControlManager()); |
93
|
|
|
$this->setEventManager(new EventManager()); |
94
|
|
|
$this->setOverlayManager(new OverlayManager()); |
95
|
|
|
$this->setLayerManager(new LayerManager()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getHtmlId() |
102
|
|
|
{ |
103
|
|
|
return $this->htmlId; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $htmlId |
108
|
|
|
*/ |
109
|
|
|
public function setHtmlId($htmlId) |
110
|
|
|
{ |
111
|
|
|
$this->htmlId = $htmlId; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return bool |
116
|
|
|
*/ |
117
|
|
|
public function isAutoZoom() |
118
|
|
|
{ |
119
|
|
|
return $this->autoZoom; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param bool $autoZoom |
124
|
|
|
*/ |
125
|
|
|
public function setAutoZoom($autoZoom) |
126
|
|
|
{ |
127
|
|
|
$this->autoZoom = $autoZoom; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return Coordinate |
132
|
|
|
*/ |
133
|
|
|
public function getCenter() |
134
|
|
|
{ |
135
|
|
|
return $this->center; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param Coordinate $center |
140
|
|
|
*/ |
141
|
|
|
public function setCenter(Coordinate $center) |
142
|
|
|
{ |
143
|
|
|
$this->center = $center; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return Bound |
148
|
|
|
*/ |
149
|
|
|
public function getBound() |
150
|
|
|
{ |
151
|
|
|
return $this->bound; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param Bound $bound |
156
|
|
|
*/ |
157
|
|
|
public function setBound(Bound $bound) |
158
|
|
|
{ |
159
|
|
|
$this->bound = $bound; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return ControlManager |
164
|
|
|
*/ |
165
|
|
|
public function getControlManager() |
166
|
|
|
{ |
167
|
|
|
return $this->controlManager; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param ControlManager $controlManager |
172
|
|
|
*/ |
173
|
|
|
public function setControlManager(ControlManager $controlManager) |
174
|
|
|
{ |
175
|
|
|
$this->controlManager = $controlManager; |
176
|
|
|
|
177
|
|
|
if ($controlManager->getMap() !== $this) { |
178
|
|
|
$controlManager->setMap($this); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return EventManager |
184
|
|
|
*/ |
185
|
|
|
public function getEventManager() |
186
|
|
|
{ |
187
|
|
|
return $this->eventManager; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param EventManager $eventManager |
192
|
|
|
*/ |
193
|
|
|
public function setEventManager(EventManager $eventManager) |
194
|
|
|
{ |
195
|
|
|
$this->eventManager = $eventManager; |
196
|
|
|
|
197
|
|
|
if ($eventManager->getMap() !== $this) { |
198
|
|
|
$eventManager->setMap($this); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @return LayerManager |
204
|
|
|
*/ |
205
|
|
|
public function getLayerManager() |
206
|
|
|
{ |
207
|
|
|
return $this->layerManager; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param LayerManager $layerManager |
212
|
|
|
*/ |
213
|
|
|
public function setLayerManager(LayerManager $layerManager) |
214
|
|
|
{ |
215
|
|
|
$this->layerManager = $layerManager; |
216
|
|
|
|
217
|
|
|
if ($layerManager->getMap() !== $this) { |
218
|
|
|
$layerManager->setMap($this); |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return OverlayManager |
224
|
|
|
*/ |
225
|
|
|
public function getOverlayManager() |
226
|
|
|
{ |
227
|
|
|
return $this->overlayManager; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param OverlayManager $overlayManager |
232
|
|
|
*/ |
233
|
|
|
public function setOverlayManager(OverlayManager $overlayManager) |
234
|
|
|
{ |
235
|
|
|
$this->overlayManager = $overlayManager; |
236
|
|
|
|
237
|
|
|
if ($overlayManager->getMap() !== $this) { |
238
|
|
|
$overlayManager->setMap($this); |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return bool |
244
|
|
|
*/ |
245
|
|
|
public function hasLibraries() |
246
|
|
|
{ |
247
|
|
|
return !empty($this->libraries); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return string[] |
252
|
|
|
*/ |
253
|
|
|
public function getLibraries() |
254
|
|
|
{ |
255
|
|
|
return $this->libraries; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param string[] $libraries |
260
|
|
|
*/ |
261
|
|
|
public function setLibraries(array $libraries) |
262
|
|
|
{ |
263
|
|
|
$this->libraries = []; |
264
|
|
|
$this->addLibraries($libraries); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param string[] $libraries |
269
|
|
|
*/ |
270
|
|
|
public function addLibraries(array $libraries) |
271
|
|
|
{ |
272
|
|
|
foreach ($libraries as $library) { |
273
|
|
|
$this->addLibrary($library); |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @param string $library |
279
|
|
|
* |
280
|
|
|
* @return bool |
281
|
|
|
*/ |
282
|
|
|
public function hasLibrary($library) |
283
|
|
|
{ |
284
|
|
|
return in_array($library, $this->libraries, true); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param string $library |
289
|
|
|
*/ |
290
|
|
|
public function addLibrary($library) |
291
|
|
|
{ |
292
|
|
|
if (!$this->hasLibrary($library)) { |
293
|
|
|
$this->libraries[] = $library; |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @param string $library |
299
|
|
|
*/ |
300
|
|
|
public function removeLibrary($library) |
301
|
|
|
{ |
302
|
|
|
unset($this->libraries[array_search($library, $this->libraries, true)]); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return bool |
307
|
|
|
*/ |
308
|
|
|
public function hasMapOptions() |
309
|
|
|
{ |
310
|
|
|
return !empty($this->mapOptions); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @return mixed[] |
315
|
|
|
*/ |
316
|
|
|
public function getMapOptions() |
317
|
|
|
{ |
318
|
|
|
return $this->mapOptions; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* @param mixed[] $mapOptions |
323
|
|
|
*/ |
324
|
|
|
public function setMapOptions(array $mapOptions) |
325
|
|
|
{ |
326
|
|
|
$this->mapOptions = []; |
327
|
|
|
$this->addMapOptions($mapOptions); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @param mixed[] $mapOptions |
332
|
|
|
*/ |
333
|
|
|
public function addMapOptions(array $mapOptions) |
334
|
|
|
{ |
335
|
|
|
foreach ($mapOptions as $mapOption => $value) { |
336
|
|
|
$this->setMapOption($mapOption, $value); |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @param string $mapOption |
342
|
|
|
* |
343
|
|
|
* @return bool |
344
|
|
|
*/ |
345
|
|
|
public function hasMapOption($mapOption) |
346
|
|
|
{ |
347
|
|
|
return isset($this->mapOptions[$mapOption]); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @param string $mapOption |
352
|
|
|
* |
353
|
|
|
* @return mixed |
354
|
|
|
*/ |
355
|
|
|
public function getMapOption($mapOption) |
356
|
|
|
{ |
357
|
|
|
return $this->hasMapOption($mapOption) ? $this->mapOptions[$mapOption] : null; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @param string $mapOption |
362
|
|
|
* @param mixed $value |
363
|
|
|
*/ |
364
|
|
|
public function setMapOption($mapOption, $value) |
365
|
|
|
{ |
366
|
|
|
$this->mapOptions[$mapOption] = $value; |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @param string $mapOption |
371
|
|
|
*/ |
372
|
|
|
public function removeMapOption($mapOption) |
373
|
|
|
{ |
374
|
|
|
unset($this->mapOptions[$mapOption]); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
/** |
378
|
|
|
* @return bool |
379
|
|
|
*/ |
380
|
|
|
public function hasStylesheetOptions() |
381
|
|
|
{ |
382
|
|
|
return !empty($this->stylesheetOptions); |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* @return string[] |
387
|
|
|
*/ |
388
|
|
|
public function getStylesheetOptions() |
389
|
|
|
{ |
390
|
|
|
return $this->stylesheetOptions; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* @param string[] $stylesheetOptions |
395
|
|
|
*/ |
396
|
|
|
public function setStylesheetOptions(array $stylesheetOptions) |
397
|
|
|
{ |
398
|
|
|
$this->stylesheetOptions = []; |
399
|
|
|
$this->addStylesheetOptions($stylesheetOptions); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @param string[] $stylesheetOptions |
404
|
|
|
*/ |
405
|
|
|
public function addStylesheetOptions(array $stylesheetOptions) |
406
|
|
|
{ |
407
|
|
|
foreach ($stylesheetOptions as $stylesheetOption => $value) { |
408
|
|
|
$this->setStylesheetOption($stylesheetOption, $value); |
409
|
|
|
} |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param string $stylesheetOption |
414
|
|
|
* |
415
|
|
|
* @return bool |
416
|
|
|
*/ |
417
|
|
|
public function hasStylesheetOption($stylesheetOption) |
418
|
|
|
{ |
419
|
|
|
return isset($this->stylesheetOptions[$stylesheetOption]); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @param string $stylesheetOption |
424
|
|
|
* |
425
|
|
|
* @return string|null |
426
|
|
|
*/ |
427
|
|
|
public function getStylesheetOption($stylesheetOption) |
428
|
|
|
{ |
429
|
|
|
return $this->hasStylesheetOption($stylesheetOption) ? $this->stylesheetOptions[$stylesheetOption] : null; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @param string $stylesheetOption |
434
|
|
|
* @param string $value |
435
|
|
|
*/ |
436
|
|
|
public function setStylesheetOption($stylesheetOption, $value) |
437
|
|
|
{ |
438
|
|
|
$this->stylesheetOptions[$stylesheetOption] = $value; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* @param string $stylesheetOption |
443
|
|
|
*/ |
444
|
|
|
public function removeStylesheetOption($stylesheetOption) |
445
|
|
|
{ |
446
|
|
|
unset($this->stylesheetOptions[$stylesheetOption]); |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
|