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