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