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\Layer; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Map; |
15
|
|
|
use Ivory\GoogleMap\Overlay\ExtendableInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author GeLo <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class LayerManager |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Map|null |
24
|
|
|
*/ |
25
|
|
|
private $map; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var GeoJsonLayer[] |
29
|
|
|
*/ |
30
|
|
|
private $geoJsonLayers = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var HeatmapLayer[] |
34
|
|
|
*/ |
35
|
|
|
private $heatmapLayers = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var KmlLayer[] |
39
|
|
|
*/ |
40
|
|
|
private $kmlLayers = []; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function hasMap() |
46
|
|
|
{ |
47
|
|
|
return $this->map !== null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return Map|null |
52
|
|
|
*/ |
53
|
|
|
public function getMap() |
54
|
|
|
{ |
55
|
|
|
return $this->map; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param Map $map |
60
|
|
|
*/ |
61
|
|
|
public function setMap(Map $map) |
62
|
|
|
{ |
63
|
|
|
$this->map = $map; |
64
|
|
|
|
65
|
|
|
if ($map->getLayerManager() !== $this) { |
66
|
|
|
$map->setLayerManager($this); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return bool |
72
|
|
|
*/ |
73
|
|
|
public function hasGeoJsonLayers() |
74
|
|
|
{ |
75
|
|
|
return !empty($this->geoJsonLayers); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return GeoJsonLayer[] |
80
|
|
|
*/ |
81
|
|
|
public function getGeoJsonLayers() |
82
|
|
|
{ |
83
|
|
|
return $this->geoJsonLayers; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param GeoJsonLayer[] $geoJsonLayers |
88
|
|
|
*/ |
89
|
|
|
public function setGeoJsonLayers(array $geoJsonLayers) |
90
|
|
|
{ |
91
|
|
|
$this->geoJsonLayers = []; |
92
|
|
|
$this->addGeoJsonLayers($geoJsonLayers); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param GeoJsonLayer[] $geoJsonLayers |
97
|
|
|
*/ |
98
|
|
|
public function addGeoJsonLayers(array $geoJsonLayers) |
99
|
|
|
{ |
100
|
|
|
foreach ($geoJsonLayers as $geoJsonLayer) { |
101
|
|
|
$this->addGeoJsonLayer($geoJsonLayer); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param GeoJsonLayer $geoJsonLayer |
107
|
|
|
* |
108
|
|
|
* @return bool |
109
|
|
|
*/ |
110
|
|
|
public function hasGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
111
|
|
|
{ |
112
|
|
|
return in_array($geoJsonLayer, $this->geoJsonLayers, true); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param GeoJsonLayer $geoJsonLayer |
117
|
|
|
*/ |
118
|
|
|
public function addGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
119
|
|
|
{ |
120
|
|
|
if (!$this->hasGeoJsonLayer($geoJsonLayer)) { |
121
|
|
|
$this->geoJsonLayers[] = $geoJsonLayer; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param GeoJsonLayer $geoJsonLayer |
127
|
|
|
*/ |
128
|
|
|
public function removeGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
129
|
|
|
{ |
130
|
|
|
unset($this->geoJsonLayers[array_search($geoJsonLayer, $this->geoJsonLayers, true)]); |
131
|
|
|
$this->geoJsonLayers = array_values($this->geoJsonLayers); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return bool |
136
|
|
|
*/ |
137
|
|
|
public function hasHeatmapLayers() |
138
|
|
|
{ |
139
|
|
|
return !empty($this->heatmapLayers); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return HeatmapLayer[] |
144
|
|
|
*/ |
145
|
|
|
public function getHeatmapLayers() |
146
|
|
|
{ |
147
|
|
|
return $this->heatmapLayers; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param HeatmapLayer[] $heatmapLayers |
152
|
|
|
*/ |
153
|
|
|
public function setHeatmapLayers(array $heatmapLayers) |
154
|
|
|
{ |
155
|
|
|
foreach ($this->heatmapLayers as $heatmapLayer) { |
156
|
|
|
$this->removeHeatmapLayer($heatmapLayer); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$this->addHeatmapLayers($heatmapLayers); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param HeatmapLayer[] $heatmapLayers |
164
|
|
|
*/ |
165
|
|
|
public function addHeatmapLayers(array $heatmapLayers) |
166
|
|
|
{ |
167
|
|
|
foreach ($heatmapLayers as $heatmapLayer) { |
168
|
|
|
$this->addHeatmapLayer($heatmapLayer); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param HeatmapLayer $heatmapLayer |
174
|
|
|
* |
175
|
|
|
* @return bool |
176
|
|
|
*/ |
177
|
|
|
public function hasHeatmapLayer(HeatmapLayer $heatmapLayer) |
178
|
|
|
{ |
179
|
|
|
return in_array($heatmapLayer, $this->heatmapLayers, true); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param HeatmapLayer $heatmapLayer |
184
|
|
|
*/ |
185
|
|
|
public function addHeatmapLayer(HeatmapLayer $heatmapLayer) |
186
|
|
|
{ |
187
|
|
|
if (!$this->hasHeatmapLayer($heatmapLayer)) { |
188
|
|
|
$this->heatmapLayers[] = $heatmapLayer; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$this->addExtendable($heatmapLayer); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param HeatmapLayer $heatmapLayer |
196
|
|
|
*/ |
197
|
|
|
public function removeHeatmapLayer(HeatmapLayer $heatmapLayer) |
198
|
|
|
{ |
199
|
|
|
unset($this->heatmapLayers[array_search($heatmapLayer, $this->heatmapLayers, true)]); |
200
|
|
|
$this->heatmapLayers = array_values($this->heatmapLayers); |
201
|
|
|
$this->removeExtendable($heatmapLayer); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return bool |
206
|
|
|
*/ |
207
|
|
|
public function hasKmlLayers() |
208
|
|
|
{ |
209
|
|
|
return !empty($this->kmlLayers); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @return KmlLayer[] |
214
|
|
|
*/ |
215
|
|
|
public function getKmlLayers() |
216
|
|
|
{ |
217
|
|
|
return $this->kmlLayers; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @param KmlLayer[] $kmlLayers |
222
|
|
|
*/ |
223
|
|
|
public function setKmlLayers(array $kmlLayers) |
224
|
|
|
{ |
225
|
|
|
foreach ($this->kmlLayers as $kmlLayer) { |
226
|
|
|
$this->removeKmlLayer($kmlLayer); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
$this->addKmlLayers($kmlLayers); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param KmlLayer[] $kmlLayers |
234
|
|
|
*/ |
235
|
|
|
public function addKmlLayers(array $kmlLayers) |
236
|
|
|
{ |
237
|
|
|
foreach ($kmlLayers as $kmlLayer) { |
238
|
|
|
$this->addKmlLayer($kmlLayer); |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @param KmlLayer $kmlLayer |
244
|
|
|
* |
245
|
|
|
* @return bool |
246
|
|
|
*/ |
247
|
|
|
public function hasKmlLayer(KmlLayer $kmlLayer) |
248
|
|
|
{ |
249
|
|
|
return in_array($kmlLayer, $this->kmlLayers, true); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @param KmlLayer $kmlLayer |
254
|
|
|
*/ |
255
|
|
|
public function addKmlLayer(KmlLayer $kmlLayer) |
256
|
|
|
{ |
257
|
|
|
if (!$this->hasKmlLayer($kmlLayer)) { |
258
|
|
|
$this->kmlLayers[] = $kmlLayer; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
$this->addExtendable($kmlLayer); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @param KmlLayer $kmlLayer |
266
|
|
|
*/ |
267
|
|
|
public function removeKmlLayer(KmlLayer $kmlLayer) |
268
|
|
|
{ |
269
|
|
|
unset($this->kmlLayers[array_search($kmlLayer, $this->kmlLayers, true)]); |
270
|
|
|
$this->kmlLayers = array_values($this->kmlLayers); |
271
|
|
|
$this->removeExtendable($kmlLayer); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param ExtendableInterface $extendable |
276
|
|
|
*/ |
277
|
|
|
private function addExtendable(ExtendableInterface $extendable) |
278
|
|
|
{ |
279
|
|
|
if ($this->isAutoZoom()) { |
280
|
|
|
$this->getMap()->getBound()->addExtendable($extendable); |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param ExtendableInterface $extendable |
286
|
|
|
*/ |
287
|
|
|
private function removeExtendable(ExtendableInterface $extendable) |
288
|
|
|
{ |
289
|
|
|
if ($this->isAutoZoom()) { |
290
|
|
|
$this->getMap()->getBound()->removeExtendable($extendable); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @return bool |
296
|
|
|
*/ |
297
|
|
|
private function isAutoZoom() |
298
|
|
|
{ |
299
|
|
|
return $this->hasMap() && $this->getMap()->isAutoZoom(); |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|