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\Helper\Collector\Base; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Base\Coordinate; |
15
|
|
|
use Ivory\GoogleMap\Helper\Collector\AbstractCollector; |
16
|
|
|
use Ivory\GoogleMap\Helper\Collector\Layer\HeatmapLayerCollector; |
17
|
|
|
use Ivory\GoogleMap\Helper\Collector\Overlay\CircleCollector; |
18
|
|
|
use Ivory\GoogleMap\Helper\Collector\Overlay\InfoWindowCollector; |
19
|
|
|
use Ivory\GoogleMap\Helper\Collector\Overlay\MarkerCollector; |
20
|
|
|
use Ivory\GoogleMap\Helper\Collector\Overlay\PolygonCollector; |
21
|
|
|
use Ivory\GoogleMap\Helper\Collector\Overlay\PolylineCollector; |
22
|
|
|
use Ivory\GoogleMap\Map; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author GeLo <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class CoordinateCollector extends AbstractCollector |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var BoundCollector |
31
|
|
|
*/ |
32
|
|
|
private $boundCollector; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var CircleCollector |
36
|
|
|
*/ |
37
|
|
|
private $circleCollector; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var InfoWindowCollector |
41
|
|
|
*/ |
42
|
|
|
private $infoWindowCollector; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var MarkerCollector |
46
|
|
|
*/ |
47
|
|
|
private $markerCollector; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var PolygonCollector |
51
|
|
|
*/ |
52
|
|
|
private $polygonCollector; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var PolylineCollector |
56
|
|
|
*/ |
57
|
|
|
private $polylineCollector; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var HeatmapLayerCollector |
61
|
|
|
*/ |
62
|
|
|
private $heatmapLayerCollector; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param BoundCollector $boundCollector |
66
|
|
|
* @param CircleCollector $circleCollector |
67
|
|
|
* @param InfoWindowCollector $infoWindowCollector |
68
|
|
|
* @param MarkerCollector $markerCollector |
69
|
|
|
* @param PolygonCollector $polygonCollector |
70
|
|
|
* @param PolylineCollector $polylineCollector |
71
|
|
|
* @param HeatmapLayerCollector $heatmapLayerCollector |
72
|
|
|
*/ |
73
|
284 |
|
public function __construct( |
74
|
|
|
BoundCollector $boundCollector, |
75
|
|
|
CircleCollector $circleCollector, |
76
|
|
|
InfoWindowCollector $infoWindowCollector, |
77
|
|
|
MarkerCollector $markerCollector, |
78
|
|
|
PolygonCollector $polygonCollector, |
79
|
|
|
PolylineCollector $polylineCollector, |
80
|
|
|
HeatmapLayerCollector $heatmapLayerCollector |
81
|
|
|
) { |
82
|
284 |
|
$this->setBoundCollector($boundCollector); |
83
|
284 |
|
$this->setCircleCollector($circleCollector); |
84
|
284 |
|
$this->setInfoWindowCollector($infoWindowCollector); |
85
|
284 |
|
$this->setMarkerCollector($markerCollector); |
86
|
284 |
|
$this->setPolygonCollector($polygonCollector); |
87
|
284 |
|
$this->setPolylineCollector($polylineCollector); |
88
|
284 |
|
$this->setHeatmapLayerCollector($heatmapLayerCollector); |
89
|
284 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return BoundCollector |
93
|
|
|
*/ |
94
|
4 |
|
public function getBoundCollector() |
95
|
|
|
{ |
96
|
4 |
|
return $this->boundCollector; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param BoundCollector $boundCollector |
101
|
|
|
*/ |
102
|
284 |
|
public function setBoundCollector(BoundCollector $boundCollector) |
103
|
|
|
{ |
104
|
284 |
|
$this->boundCollector = $boundCollector; |
105
|
284 |
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return CircleCollector |
109
|
|
|
*/ |
110
|
4 |
|
public function getCircleCollector() |
111
|
|
|
{ |
112
|
4 |
|
return $this->circleCollector; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param CircleCollector $circleCollector |
117
|
|
|
*/ |
118
|
284 |
|
public function setCircleCollector(CircleCollector $circleCollector) |
119
|
|
|
{ |
120
|
284 |
|
$this->circleCollector = $circleCollector; |
121
|
284 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return InfoWindowCollector |
125
|
|
|
*/ |
126
|
4 |
|
public function getInfoWindowCollector() |
127
|
|
|
{ |
128
|
4 |
|
return $this->infoWindowCollector; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param InfoWindowCollector $infoWindowCollector |
133
|
|
|
*/ |
134
|
284 |
|
public function setInfoWindowCollector(InfoWindowCollector $infoWindowCollector) |
135
|
|
|
{ |
136
|
284 |
|
$this->infoWindowCollector = $infoWindowCollector; |
137
|
284 |
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return MarkerCollector |
141
|
|
|
*/ |
142
|
4 |
|
public function getMarkerCollector() |
143
|
|
|
{ |
144
|
4 |
|
return $this->markerCollector; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param MarkerCollector $markerCollector |
149
|
|
|
*/ |
150
|
284 |
|
public function setMarkerCollector(MarkerCollector $markerCollector) |
151
|
|
|
{ |
152
|
284 |
|
$this->markerCollector = $markerCollector; |
153
|
284 |
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return PolygonCollector |
157
|
|
|
*/ |
158
|
4 |
|
public function getPolygonCollector() |
159
|
|
|
{ |
160
|
4 |
|
return $this->polygonCollector; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param PolygonCollector $polygonCollector |
165
|
|
|
*/ |
166
|
284 |
|
public function setPolygonCollector(PolygonCollector $polygonCollector) |
167
|
|
|
{ |
168
|
284 |
|
$this->polygonCollector = $polygonCollector; |
169
|
284 |
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return PolylineCollector |
173
|
|
|
*/ |
174
|
4 |
|
public function getPolylineCollector() |
175
|
|
|
{ |
176
|
4 |
|
return $this->polylineCollector; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param PolylineCollector $polylineCollector |
181
|
|
|
*/ |
182
|
284 |
|
public function setPolylineCollector(PolylineCollector $polylineCollector) |
183
|
|
|
{ |
184
|
284 |
|
$this->polylineCollector = $polylineCollector; |
185
|
284 |
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @return HeatmapLayerCollector |
189
|
|
|
*/ |
190
|
4 |
|
public function getHeatmapLayerCollector() |
191
|
|
|
{ |
192
|
4 |
|
return $this->heatmapLayerCollector; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param HeatmapLayerCollector $heatmapLayerCollector |
197
|
|
|
*/ |
198
|
284 |
|
public function setHeatmapLayerCollector(HeatmapLayerCollector $heatmapLayerCollector) |
199
|
|
|
{ |
200
|
284 |
|
$this->heatmapLayerCollector = $heatmapLayerCollector; |
201
|
284 |
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @param Map $map |
205
|
|
|
* @param Coordinate[] $coordinates |
206
|
|
|
* |
207
|
|
|
* @return Coordinate[] |
208
|
|
|
*/ |
209
|
252 |
|
public function collect(Map $map, array $coordinates = []) |
210
|
|
|
{ |
211
|
252 |
|
if (!$map->isAutoZoom()) { |
212
|
188 |
|
$coordinates = $this->collectValue($map->getCenter(), $coordinates); |
213
|
94 |
|
} |
214
|
|
|
|
215
|
252 |
View Code Duplication |
foreach ($this->boundCollector->collect($map) as $bound) { |
|
|
|
|
216
|
76 |
|
if ($bound->hasCoordinates()) { |
217
|
20 |
|
$coordinates = $this->collectValue($bound->getSouthWest(), $coordinates); |
218
|
48 |
|
$coordinates = $this->collectValue($bound->getNorthEast(), $coordinates); |
219
|
10 |
|
} |
220
|
126 |
|
} |
221
|
|
|
|
222
|
252 |
|
foreach ($this->circleCollector->collect($map) as $circle) { |
223
|
12 |
|
$coordinates = $this->collectValue($circle->getCenter(), $coordinates); |
224
|
126 |
|
} |
225
|
|
|
|
226
|
252 |
|
foreach ($this->infoWindowCollector->collect($map) as $infoWindow) { |
227
|
52 |
|
if ($infoWindow->hasPosition()) { |
228
|
44 |
|
$coordinates = $this->collectValue($infoWindow->getPosition(), $coordinates); |
|
|
|
|
229
|
18 |
|
} |
230
|
126 |
|
} |
231
|
|
|
|
232
|
252 |
|
foreach ($this->markerCollector->collect($map) as $marker) { |
233
|
52 |
|
$coordinates = $this->collectValue($marker->getPosition(), $coordinates); |
234
|
126 |
|
} |
235
|
|
|
|
236
|
252 |
|
foreach ($this->polygonCollector->collect($map) as $polygon) { |
237
|
12 |
|
$coordinates = $this->collectValues($polygon->getCoordinates(), $coordinates); |
238
|
126 |
|
} |
239
|
|
|
|
240
|
252 |
|
foreach ($this->polylineCollector->collect($map) as $polyline) { |
241
|
16 |
|
$coordinates = $this->collectValues($polyline->getCoordinates(), $coordinates); |
242
|
126 |
|
} |
243
|
|
|
|
244
|
252 |
|
foreach ($this->heatmapLayerCollector->collect($map) as $heatmapLayer) { |
245
|
12 |
|
$coordinates = $this->collectValues($heatmapLayer->getCoordinates(), $coordinates); |
246
|
126 |
|
} |
247
|
|
|
|
248
|
252 |
|
return $coordinates; |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.