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
|
|
|
/** |
15
|
|
|
* @author GeLo <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class LayerManager |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var GeoJsonLayer[] |
21
|
|
|
*/ |
22
|
|
|
private $geoJsonLayers = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var HeatmapLayer[] |
26
|
|
|
*/ |
27
|
|
|
private $heatmapLayers = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var KmlLayer[] |
31
|
|
|
*/ |
32
|
|
|
private $kmlLayers = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return bool |
36
|
|
|
*/ |
37
|
|
|
public function hasGeoJsonLayers() |
38
|
|
|
{ |
39
|
|
|
return !empty($this->geoJsonLayers); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return GeoJsonLayer[] |
44
|
|
|
*/ |
45
|
|
|
public function getGeoJsonLayers() |
46
|
|
|
{ |
47
|
|
|
return $this->geoJsonLayers; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param GeoJsonLayer[] $geoJsonLayers |
52
|
|
|
*/ |
53
|
|
|
public function setGeoJsonLayers(array $geoJsonLayers) |
54
|
|
|
{ |
55
|
|
|
$this->geoJsonLayers = []; |
56
|
|
|
$this->addGeoJsonLayers($geoJsonLayers); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param GeoJsonLayer[] $geoJsonLayers |
61
|
|
|
*/ |
62
|
|
|
public function addGeoJsonLayers(array $geoJsonLayers) |
63
|
|
|
{ |
64
|
|
|
foreach ($geoJsonLayers as $geoJsonLayer) { |
65
|
|
|
$this->addGeoJsonLayer($geoJsonLayer); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param GeoJsonLayer $geoJsonLayer |
71
|
|
|
* |
72
|
|
|
* @return bool |
73
|
|
|
*/ |
74
|
|
|
public function hasGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
75
|
|
|
{ |
76
|
|
|
return in_array($geoJsonLayer, $this->geoJsonLayers, true); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param GeoJsonLayer $geoJsonLayer |
81
|
|
|
*/ |
82
|
|
|
public function addGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
83
|
|
|
{ |
84
|
|
|
if (!$this->hasGeoJsonLayer($geoJsonLayer)) { |
85
|
|
|
$this->geoJsonLayers[] = $geoJsonLayer; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param GeoJsonLayer $geoJsonLayer |
91
|
|
|
*/ |
92
|
|
|
public function removeGeoJsonLayer(GeoJsonLayer $geoJsonLayer) |
93
|
|
|
{ |
94
|
|
|
unset($this->geoJsonLayers[array_search($geoJsonLayer, $this->geoJsonLayers, true)]); |
95
|
|
|
$this->geoJsonLayers = array_values($this->geoJsonLayers); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
public function hasHeatmapLayers() |
102
|
|
|
{ |
103
|
|
|
return !empty($this->heatmapLayers); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return HeatmapLayer[] |
108
|
|
|
*/ |
109
|
|
|
public function getHeatmapLayers() |
110
|
|
|
{ |
111
|
|
|
return $this->heatmapLayers; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param HeatmapLayer[] $heatmapLayers |
116
|
|
|
*/ |
117
|
|
|
public function setHeatmapLayers(array $heatmapLayers) |
118
|
|
|
{ |
119
|
|
|
$this->heatmapLayers = []; |
120
|
|
|
$this->addHeatmapLayers($heatmapLayers); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param HeatmapLayer[] $heatmapLayers |
125
|
|
|
*/ |
126
|
|
|
public function addHeatmapLayers(array $heatmapLayers) |
127
|
|
|
{ |
128
|
|
|
foreach ($heatmapLayers as $heatmapLayer) { |
129
|
|
|
$this->addHeatmapLayer($heatmapLayer); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param HeatmapLayer $heatmapLayer |
135
|
|
|
* |
136
|
|
|
* @return bool |
137
|
|
|
*/ |
138
|
|
|
public function hasHeatmapLayer(HeatmapLayer $heatmapLayer) |
139
|
|
|
{ |
140
|
|
|
return in_array($heatmapLayer, $this->heatmapLayers, true); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param HeatmapLayer $heatmapLayer |
145
|
|
|
*/ |
146
|
|
|
public function addHeatmapLayer(HeatmapLayer $heatmapLayer) |
147
|
|
|
{ |
148
|
|
|
if (!$this->hasHeatmapLayer($heatmapLayer)) { |
149
|
|
|
$this->heatmapLayers[] = $heatmapLayer; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param HeatmapLayer $heatmapLayer |
155
|
|
|
*/ |
156
|
|
|
public function removeHeatmapLayer(HeatmapLayer $heatmapLayer) |
157
|
|
|
{ |
158
|
|
|
unset($this->heatmapLayers[array_search($heatmapLayer, $this->heatmapLayers, true)]); |
159
|
|
|
$this->heatmapLayers = array_values($this->heatmapLayers); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return bool |
164
|
|
|
*/ |
165
|
|
|
public function hasKmlLayers() |
166
|
|
|
{ |
167
|
|
|
return !empty($this->kmlLayers); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return KmlLayer[] |
172
|
|
|
*/ |
173
|
|
|
public function getKmlLayers() |
174
|
|
|
{ |
175
|
|
|
return $this->kmlLayers; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param KmlLayer[] $kmlLayers |
180
|
|
|
*/ |
181
|
|
|
public function setKmlLayers(array $kmlLayers) |
182
|
|
|
{ |
183
|
|
|
$this->kmlLayers = []; |
184
|
|
|
$this->addKmlLayers($kmlLayers); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param KmlLayer[] $kmlLayers |
189
|
|
|
*/ |
190
|
|
|
public function addKmlLayers(array $kmlLayers) |
191
|
|
|
{ |
192
|
|
|
foreach ($kmlLayers as $kmlLayer) { |
193
|
|
|
$this->addKmlLayer($kmlLayer); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param KmlLayer $kmlLayer |
199
|
|
|
* |
200
|
|
|
* @return bool |
201
|
|
|
*/ |
202
|
|
|
public function hasKmlLayer(KmlLayer $kmlLayer) |
203
|
|
|
{ |
204
|
|
|
return in_array($kmlLayer, $this->kmlLayers, true); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param KmlLayer $kmlLayer |
209
|
|
|
*/ |
210
|
|
|
public function addKmlLayer(KmlLayer $kmlLayer) |
211
|
|
|
{ |
212
|
|
|
if (!$this->hasKmlLayer($kmlLayer)) { |
213
|
|
|
$this->kmlLayers[] = $kmlLayer; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param KmlLayer $kmlLayer |
219
|
|
|
*/ |
220
|
|
|
public function removeKmlLayer(KmlLayer $kmlLayer) |
221
|
|
|
{ |
222
|
|
|
unset($this->kmlLayers[array_search($kmlLayer, $this->kmlLayers, true)]); |
223
|
|
|
$this->kmlLayers = array_values($this->kmlLayers); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|