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
|
|
|
/** |
88
|
|
|
* @var string[] |
89
|
|
|
*/ |
90
|
|
|
private $htmlAttributes = []; |
91
|
|
|
|
92
|
|
|
public function __construct() |
93
|
|
|
{ |
94
|
|
|
$this->setVariablePrefix('map'); |
95
|
|
|
$this->setCenter(new Coordinate()); |
96
|
|
|
$this->setBound(new Bound()); |
97
|
|
|
$this->setControlManager(new ControlManager()); |
98
|
|
|
$this->setEventManager(new EventManager()); |
99
|
|
|
$this->setOverlayManager(new OverlayManager()); |
100
|
|
|
$this->setLayerManager(new LayerManager()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function getHtmlId() |
107
|
|
|
{ |
108
|
|
|
return $this->htmlId; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $htmlId |
113
|
|
|
*/ |
114
|
|
|
public function setHtmlId($htmlId) |
115
|
|
|
{ |
116
|
|
|
$this->htmlId = $htmlId; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return bool |
121
|
|
|
*/ |
122
|
|
|
public function isAutoZoom() |
123
|
|
|
{ |
124
|
|
|
return $this->autoZoom; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param bool $autoZoom |
129
|
|
|
*/ |
130
|
|
|
public function setAutoZoom($autoZoom) |
131
|
|
|
{ |
132
|
|
|
$this->autoZoom = $autoZoom; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return Coordinate |
137
|
|
|
*/ |
138
|
|
|
public function getCenter() |
139
|
|
|
{ |
140
|
|
|
return $this->center; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param Coordinate $center |
145
|
|
|
*/ |
146
|
|
|
public function setCenter(Coordinate $center) |
147
|
|
|
{ |
148
|
|
|
$this->center = $center; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return Bound |
153
|
|
|
*/ |
154
|
|
|
public function getBound() |
155
|
|
|
{ |
156
|
|
|
return $this->bound; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param Bound $bound |
161
|
|
|
*/ |
162
|
|
|
public function setBound(Bound $bound) |
163
|
|
|
{ |
164
|
|
|
$this->bound = $bound; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return ControlManager |
169
|
|
|
*/ |
170
|
|
|
public function getControlManager() |
171
|
|
|
{ |
172
|
|
|
return $this->controlManager; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param ControlManager $controlManager |
177
|
|
|
*/ |
178
|
|
|
public function setControlManager(ControlManager $controlManager) |
179
|
|
|
{ |
180
|
|
|
$this->controlManager = $controlManager; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return EventManager |
185
|
|
|
*/ |
186
|
|
|
public function getEventManager() |
187
|
|
|
{ |
188
|
|
|
return $this->eventManager; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param EventManager $eventManager |
193
|
|
|
*/ |
194
|
|
|
public function setEventManager(EventManager $eventManager) |
195
|
|
|
{ |
196
|
|
|
$this->eventManager = $eventManager; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return LayerManager |
201
|
|
|
*/ |
202
|
|
|
public function getLayerManager() |
203
|
|
|
{ |
204
|
|
|
return $this->layerManager; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param LayerManager $layerManager |
209
|
|
|
*/ |
210
|
|
|
public function setLayerManager(LayerManager $layerManager) |
211
|
|
|
{ |
212
|
|
|
$this->layerManager = $layerManager; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return OverlayManager |
217
|
|
|
*/ |
218
|
|
|
public function getOverlayManager() |
219
|
|
|
{ |
220
|
|
|
return $this->overlayManager; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param OverlayManager $overlayManager |
225
|
|
|
*/ |
226
|
|
|
public function setOverlayManager(OverlayManager $overlayManager) |
227
|
|
|
{ |
228
|
|
|
$this->overlayManager = $overlayManager; |
229
|
|
|
|
230
|
|
|
if ($overlayManager->getMap() !== $this) { |
231
|
|
|
$overlayManager->setMap($this); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @return bool |
237
|
|
|
*/ |
238
|
|
|
public function hasLibraries() |
239
|
|
|
{ |
240
|
|
|
return !empty($this->libraries); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return string[] |
245
|
|
|
*/ |
246
|
|
|
public function getLibraries() |
247
|
|
|
{ |
248
|
|
|
return $this->libraries; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @param string[] $libraries |
253
|
|
|
*/ |
254
|
|
|
public function setLibraries(array $libraries) |
255
|
|
|
{ |
256
|
|
|
$this->libraries = []; |
257
|
|
|
$this->addLibraries($libraries); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @param string[] $libraries |
262
|
|
|
*/ |
263
|
|
|
public function addLibraries(array $libraries) |
264
|
|
|
{ |
265
|
|
|
foreach ($libraries as $library) { |
266
|
|
|
$this->addLibrary($library); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @param string $library |
272
|
|
|
* |
273
|
|
|
* @return bool |
274
|
|
|
*/ |
275
|
|
|
public function hasLibrary($library) |
276
|
|
|
{ |
277
|
|
|
return in_array($library, $this->libraries, true); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @param string $library |
282
|
|
|
*/ |
283
|
|
|
public function addLibrary($library) |
284
|
|
|
{ |
285
|
|
|
if (!$this->hasLibrary($library)) { |
286
|
|
|
$this->libraries[] = $library; |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param string $library |
292
|
|
|
*/ |
293
|
|
|
public function removeLibrary($library) |
294
|
|
|
{ |
295
|
|
|
unset($this->libraries[array_search($library, $this->libraries, true)]); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return bool |
300
|
|
|
*/ |
301
|
|
|
public function hasMapOptions() |
302
|
|
|
{ |
303
|
|
|
return !empty($this->mapOptions); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @return mixed[] |
308
|
|
|
*/ |
309
|
|
|
public function getMapOptions() |
310
|
|
|
{ |
311
|
|
|
return $this->mapOptions; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @param mixed[] $mapOptions |
316
|
|
|
*/ |
317
|
|
|
public function setMapOptions(array $mapOptions) |
318
|
|
|
{ |
319
|
|
|
$this->mapOptions = []; |
320
|
|
|
$this->addMapOptions($mapOptions); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @param mixed[] $mapOptions |
325
|
|
|
*/ |
326
|
|
|
public function addMapOptions(array $mapOptions) |
327
|
|
|
{ |
328
|
|
|
foreach ($mapOptions as $mapOption => $value) { |
329
|
|
|
$this->setMapOption($mapOption, $value); |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @param string $mapOption |
335
|
|
|
* |
336
|
|
|
* @return bool |
337
|
|
|
*/ |
338
|
|
|
public function hasMapOption($mapOption) |
339
|
|
|
{ |
340
|
|
|
return isset($this->mapOptions[$mapOption]); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @param string $mapOption |
345
|
|
|
* |
346
|
|
|
* @return mixed |
347
|
|
|
*/ |
348
|
|
|
public function getMapOption($mapOption) |
349
|
|
|
{ |
350
|
|
|
return $this->hasMapOption($mapOption) ? $this->mapOptions[$mapOption] : null; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @param string $mapOption |
355
|
|
|
* @param mixed $value |
356
|
|
|
*/ |
357
|
|
|
public function setMapOption($mapOption, $value) |
358
|
|
|
{ |
359
|
|
|
$this->mapOptions[$mapOption] = $value; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @param string $mapOption |
364
|
|
|
*/ |
365
|
|
|
public function removeMapOption($mapOption) |
366
|
|
|
{ |
367
|
|
|
unset($this->mapOptions[$mapOption]); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @return bool |
372
|
|
|
*/ |
373
|
|
|
public function hasStylesheetOptions() |
374
|
|
|
{ |
375
|
|
|
return !empty($this->stylesheetOptions); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @return string[] |
380
|
|
|
*/ |
381
|
|
|
public function getStylesheetOptions() |
382
|
|
|
{ |
383
|
|
|
return $this->stylesheetOptions; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @param string[] $stylesheetOptions |
388
|
|
|
*/ |
389
|
|
|
public function setStylesheetOptions(array $stylesheetOptions) |
390
|
|
|
{ |
391
|
|
|
$this->stylesheetOptions = []; |
392
|
|
|
$this->addStylesheetOptions($stylesheetOptions); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* @param string[] $stylesheetOptions |
397
|
|
|
*/ |
398
|
|
|
public function addStylesheetOptions(array $stylesheetOptions) |
399
|
|
|
{ |
400
|
|
|
foreach ($stylesheetOptions as $stylesheetOption => $value) { |
401
|
|
|
$this->setStylesheetOption($stylesheetOption, $value); |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* @param string $stylesheetOption |
407
|
|
|
* |
408
|
|
|
* @return bool |
409
|
|
|
*/ |
410
|
|
|
public function hasStylesheetOption($stylesheetOption) |
411
|
|
|
{ |
412
|
|
|
return isset($this->stylesheetOptions[$stylesheetOption]); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @param string $stylesheetOption |
417
|
|
|
* |
418
|
|
|
* @return string|null |
419
|
|
|
*/ |
420
|
|
|
public function getStylesheetOption($stylesheetOption) |
421
|
|
|
{ |
422
|
|
|
return $this->hasStylesheetOption($stylesheetOption) ? $this->stylesheetOptions[$stylesheetOption] : null; |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* @param string $stylesheetOption |
427
|
|
|
* @param string $value |
428
|
|
|
*/ |
429
|
|
|
public function setStylesheetOption($stylesheetOption, $value) |
430
|
|
|
{ |
431
|
|
|
$this->stylesheetOptions[$stylesheetOption] = $value; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @param string $stylesheetOption |
436
|
|
|
*/ |
437
|
|
|
public function removeStylesheetOption($stylesheetOption) |
438
|
|
|
{ |
439
|
|
|
unset($this->stylesheetOptions[$stylesheetOption]); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return bool |
444
|
|
|
*/ |
445
|
|
|
public function hasHtmlAttributes() |
446
|
|
|
{ |
447
|
|
|
return !empty($this->htmlAttributes); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @return string[] |
452
|
|
|
*/ |
453
|
|
|
public function getHtmlAttributes() |
454
|
|
|
{ |
455
|
|
|
return $this->htmlAttributes; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @param string[] $htmlAttributes |
460
|
|
|
*/ |
461
|
|
|
public function setHtmlAttributes(array $htmlAttributes) |
462
|
|
|
{ |
463
|
|
|
$this->htmlAttributes = []; |
464
|
|
|
$this->addHtmlAttributes($htmlAttributes); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* @param string[] $htmlAttributes |
469
|
|
|
*/ |
470
|
|
|
public function addHtmlAttributes(array $htmlAttributes) |
471
|
|
|
{ |
472
|
|
|
foreach ($htmlAttributes as $htmlAttribute => $value) { |
473
|
|
|
$this->setHtmlAttribute($htmlAttribute, $value); |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @param string $htmlAttribute |
479
|
|
|
* |
480
|
|
|
* @return bool |
481
|
|
|
*/ |
482
|
|
|
public function hasHtmlAttribute($htmlAttribute) |
483
|
|
|
{ |
484
|
|
|
return isset($this->htmlAttributes[$htmlAttribute]); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* @param string $htmlAttribute |
489
|
|
|
* |
490
|
|
|
* @return string|null |
491
|
|
|
*/ |
492
|
|
|
public function getHtmlAttribute($htmlAttribute) |
493
|
|
|
{ |
494
|
|
|
return $this->hasHtmlAttribute($htmlAttribute) ? $this->htmlAttributes[$htmlAttribute] : null; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* @param string $htmlAttribute |
499
|
|
|
* @param string $value |
500
|
|
|
*/ |
501
|
|
|
public function setHtmlAttribute($htmlAttribute, $value) |
502
|
|
|
{ |
503
|
|
|
$this->htmlAttributes[$htmlAttribute] = $value; |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* @param string $htmlAttribute |
508
|
|
|
*/ |
509
|
|
|
public function removeHtmlAttribute($htmlAttribute) |
510
|
|
|
{ |
511
|
|
|
unset($this->htmlAttributes[$htmlAttribute]); |
512
|
|
|
} |
513
|
|
|
} |
514
|
|
|
|