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
|
|
|
if ($layerManager->getMap() !== $this) { |
215
|
|
|
$layerManager->setMap($this); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return OverlayManager |
221
|
|
|
*/ |
222
|
|
|
public function getOverlayManager() |
223
|
|
|
{ |
224
|
|
|
return $this->overlayManager; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param OverlayManager $overlayManager |
229
|
|
|
*/ |
230
|
|
|
public function setOverlayManager(OverlayManager $overlayManager) |
231
|
|
|
{ |
232
|
|
|
$this->overlayManager = $overlayManager; |
233
|
|
|
|
234
|
|
|
if ($overlayManager->getMap() !== $this) { |
235
|
|
|
$overlayManager->setMap($this); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @return bool |
241
|
|
|
*/ |
242
|
|
|
public function hasLibraries() |
243
|
|
|
{ |
244
|
|
|
return !empty($this->libraries); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return string[] |
249
|
|
|
*/ |
250
|
|
|
public function getLibraries() |
251
|
|
|
{ |
252
|
|
|
return $this->libraries; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @param string[] $libraries |
257
|
|
|
*/ |
258
|
|
|
public function setLibraries(array $libraries) |
259
|
|
|
{ |
260
|
|
|
$this->libraries = []; |
261
|
|
|
$this->addLibraries($libraries); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @param string[] $libraries |
266
|
|
|
*/ |
267
|
|
|
public function addLibraries(array $libraries) |
268
|
|
|
{ |
269
|
|
|
foreach ($libraries as $library) { |
270
|
|
|
$this->addLibrary($library); |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param string $library |
276
|
|
|
* |
277
|
|
|
* @return bool |
278
|
|
|
*/ |
279
|
|
|
public function hasLibrary($library) |
280
|
|
|
{ |
281
|
|
|
return in_array($library, $this->libraries, true); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param string $library |
286
|
|
|
*/ |
287
|
|
|
public function addLibrary($library) |
288
|
|
|
{ |
289
|
|
|
if (!$this->hasLibrary($library)) { |
290
|
|
|
$this->libraries[] = $library; |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param string $library |
296
|
|
|
*/ |
297
|
|
|
public function removeLibrary($library) |
298
|
|
|
{ |
299
|
|
|
unset($this->libraries[array_search($library, $this->libraries, true)]); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @return bool |
304
|
|
|
*/ |
305
|
|
|
public function hasMapOptions() |
306
|
|
|
{ |
307
|
|
|
return !empty($this->mapOptions); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @return mixed[] |
312
|
|
|
*/ |
313
|
|
|
public function getMapOptions() |
314
|
|
|
{ |
315
|
|
|
return $this->mapOptions; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @param mixed[] $mapOptions |
320
|
|
|
*/ |
321
|
|
|
public function setMapOptions(array $mapOptions) |
322
|
|
|
{ |
323
|
|
|
$this->mapOptions = []; |
324
|
|
|
$this->addMapOptions($mapOptions); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @param mixed[] $mapOptions |
329
|
|
|
*/ |
330
|
|
|
public function addMapOptions(array $mapOptions) |
331
|
|
|
{ |
332
|
|
|
foreach ($mapOptions as $mapOption => $value) { |
333
|
|
|
$this->setMapOption($mapOption, $value); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @param string $mapOption |
339
|
|
|
* |
340
|
|
|
* @return bool |
341
|
|
|
*/ |
342
|
|
|
public function hasMapOption($mapOption) |
343
|
|
|
{ |
344
|
|
|
return isset($this->mapOptions[$mapOption]); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @param string $mapOption |
349
|
|
|
* |
350
|
|
|
* @return mixed |
351
|
|
|
*/ |
352
|
|
|
public function getMapOption($mapOption) |
353
|
|
|
{ |
354
|
|
|
return $this->hasMapOption($mapOption) ? $this->mapOptions[$mapOption] : null; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @param string $mapOption |
359
|
|
|
* @param mixed $value |
360
|
|
|
*/ |
361
|
|
|
public function setMapOption($mapOption, $value) |
362
|
|
|
{ |
363
|
|
|
$this->mapOptions[$mapOption] = $value; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @param string $mapOption |
368
|
|
|
*/ |
369
|
|
|
public function removeMapOption($mapOption) |
370
|
|
|
{ |
371
|
|
|
unset($this->mapOptions[$mapOption]); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* @return bool |
376
|
|
|
*/ |
377
|
|
|
public function hasStylesheetOptions() |
378
|
|
|
{ |
379
|
|
|
return !empty($this->stylesheetOptions); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* @return string[] |
384
|
|
|
*/ |
385
|
|
|
public function getStylesheetOptions() |
386
|
|
|
{ |
387
|
|
|
return $this->stylesheetOptions; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @param string[] $stylesheetOptions |
392
|
|
|
*/ |
393
|
|
|
public function setStylesheetOptions(array $stylesheetOptions) |
394
|
|
|
{ |
395
|
|
|
$this->stylesheetOptions = []; |
396
|
|
|
$this->addStylesheetOptions($stylesheetOptions); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @param string[] $stylesheetOptions |
401
|
|
|
*/ |
402
|
|
|
public function addStylesheetOptions(array $stylesheetOptions) |
403
|
|
|
{ |
404
|
|
|
foreach ($stylesheetOptions as $stylesheetOption => $value) { |
405
|
|
|
$this->setStylesheetOption($stylesheetOption, $value); |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @param string $stylesheetOption |
411
|
|
|
* |
412
|
|
|
* @return bool |
413
|
|
|
*/ |
414
|
|
|
public function hasStylesheetOption($stylesheetOption) |
415
|
|
|
{ |
416
|
|
|
return isset($this->stylesheetOptions[$stylesheetOption]); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* @param string $stylesheetOption |
421
|
|
|
* |
422
|
|
|
* @return string|null |
423
|
|
|
*/ |
424
|
|
|
public function getStylesheetOption($stylesheetOption) |
425
|
|
|
{ |
426
|
|
|
return $this->hasStylesheetOption($stylesheetOption) ? $this->stylesheetOptions[$stylesheetOption] : null; |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @param string $stylesheetOption |
431
|
|
|
* @param string $value |
432
|
|
|
*/ |
433
|
|
|
public function setStylesheetOption($stylesheetOption, $value) |
434
|
|
|
{ |
435
|
|
|
$this->stylesheetOptions[$stylesheetOption] = $value; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* @param string $stylesheetOption |
440
|
|
|
*/ |
441
|
|
|
public function removeStylesheetOption($stylesheetOption) |
442
|
|
|
{ |
443
|
|
|
unset($this->stylesheetOptions[$stylesheetOption]); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* @return bool |
448
|
|
|
*/ |
449
|
|
|
public function hasHtmlAttributes() |
450
|
|
|
{ |
451
|
|
|
return !empty($this->htmlAttributes); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* @return string[] |
456
|
|
|
*/ |
457
|
|
|
public function getHtmlAttributes() |
458
|
|
|
{ |
459
|
|
|
return $this->htmlAttributes; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* @param string[] $htmlAttributes |
464
|
|
|
*/ |
465
|
|
|
public function setHtmlAttributes(array $htmlAttributes) |
466
|
|
|
{ |
467
|
|
|
$this->htmlAttributes = []; |
468
|
|
|
$this->addHtmlAttributes($htmlAttributes); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* @param string[] $htmlAttributes |
473
|
|
|
*/ |
474
|
|
|
public function addHtmlAttributes(array $htmlAttributes) |
475
|
|
|
{ |
476
|
|
|
foreach ($htmlAttributes as $htmlAttribute => $value) { |
477
|
|
|
$this->setHtmlAttribute($htmlAttribute, $value); |
478
|
|
|
} |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* @param string $htmlAttribute |
483
|
|
|
* |
484
|
|
|
* @return bool |
485
|
|
|
*/ |
486
|
|
|
public function hasHtmlAttribute($htmlAttribute) |
487
|
|
|
{ |
488
|
|
|
return isset($this->htmlAttributes[$htmlAttribute]); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* @param string $htmlAttribute |
493
|
|
|
* |
494
|
|
|
* @return string|null |
495
|
|
|
*/ |
496
|
|
|
public function getHtmlAttribute($htmlAttribute) |
497
|
|
|
{ |
498
|
|
|
return $this->hasHtmlAttribute($htmlAttribute) ? $this->htmlAttributes[$htmlAttribute] : null; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* @param string $htmlAttribute |
503
|
|
|
* @param string $value |
504
|
|
|
*/ |
505
|
|
|
public function setHtmlAttribute($htmlAttribute, $value) |
506
|
|
|
{ |
507
|
|
|
$this->htmlAttributes[$htmlAttribute] = $value; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* @param string $htmlAttribute |
512
|
|
|
*/ |
513
|
|
|
public function removeHtmlAttribute($htmlAttribute) |
514
|
|
|
{ |
515
|
|
|
unset($this->htmlAttributes[$htmlAttribute]); |
516
|
|
|
} |
517
|
|
|
} |
518
|
|
|
|