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
|
68 |
|
public function __construct( |
65
|
|
|
BoundCollector $boundCollector, |
66
|
|
|
CircleCollector $circleCollector, |
67
|
|
|
InfoWindowCollector $infoWindowCollector, |
68
|
|
|
MarkerCollector $markerCollector, |
69
|
|
|
PolygonCollector $polygonCollector, |
70
|
|
|
PolylineCollector $polylineCollector, |
71
|
|
|
HeatmapLayerCollector $heatmapLayerCollector |
72
|
|
|
) { |
73
|
68 |
|
$this->setBoundCollector($boundCollector); |
74
|
68 |
|
$this->setCircleCollector($circleCollector); |
75
|
68 |
|
$this->setInfoWindowCollector($infoWindowCollector); |
76
|
68 |
|
$this->setMarkerCollector($markerCollector); |
77
|
68 |
|
$this->setPolygonCollector($polygonCollector); |
78
|
68 |
|
$this->setPolylineCollector($polylineCollector); |
79
|
68 |
|
$this->setHeatmapLayerCollector($heatmapLayerCollector); |
80
|
68 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return BoundCollector |
84
|
|
|
*/ |
85
|
4 |
|
public function getBoundCollector() |
86
|
|
|
{ |
87
|
4 |
|
return $this->boundCollector; |
88
|
|
|
} |
89
|
|
|
|
90
|
68 |
|
public function setBoundCollector(BoundCollector $boundCollector) |
91
|
|
|
{ |
92
|
68 |
|
$this->boundCollector = $boundCollector; |
93
|
68 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return CircleCollector |
97
|
|
|
*/ |
98
|
4 |
|
public function getCircleCollector() |
99
|
|
|
{ |
100
|
4 |
|
return $this->circleCollector; |
101
|
|
|
} |
102
|
|
|
|
103
|
68 |
|
public function setCircleCollector(CircleCollector $circleCollector) |
104
|
|
|
{ |
105
|
68 |
|
$this->circleCollector = $circleCollector; |
106
|
68 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return InfoWindowCollector |
110
|
|
|
*/ |
111
|
4 |
|
public function getInfoWindowCollector() |
112
|
|
|
{ |
113
|
4 |
|
return $this->infoWindowCollector; |
114
|
|
|
} |
115
|
|
|
|
116
|
68 |
|
public function setInfoWindowCollector(InfoWindowCollector $infoWindowCollector) |
117
|
|
|
{ |
118
|
68 |
|
$this->infoWindowCollector = $infoWindowCollector; |
119
|
68 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return MarkerCollector |
123
|
|
|
*/ |
124
|
4 |
|
public function getMarkerCollector() |
125
|
|
|
{ |
126
|
4 |
|
return $this->markerCollector; |
127
|
|
|
} |
128
|
|
|
|
129
|
68 |
|
public function setMarkerCollector(MarkerCollector $markerCollector) |
130
|
|
|
{ |
131
|
68 |
|
$this->markerCollector = $markerCollector; |
132
|
68 |
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return PolygonCollector |
136
|
|
|
*/ |
137
|
4 |
|
public function getPolygonCollector() |
138
|
|
|
{ |
139
|
4 |
|
return $this->polygonCollector; |
140
|
|
|
} |
141
|
|
|
|
142
|
68 |
|
public function setPolygonCollector(PolygonCollector $polygonCollector) |
143
|
|
|
{ |
144
|
68 |
|
$this->polygonCollector = $polygonCollector; |
145
|
68 |
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return PolylineCollector |
149
|
|
|
*/ |
150
|
4 |
|
public function getPolylineCollector() |
151
|
|
|
{ |
152
|
4 |
|
return $this->polylineCollector; |
153
|
|
|
} |
154
|
|
|
|
155
|
68 |
|
public function setPolylineCollector(PolylineCollector $polylineCollector) |
156
|
|
|
{ |
157
|
68 |
|
$this->polylineCollector = $polylineCollector; |
158
|
68 |
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return HeatmapLayerCollector |
162
|
|
|
*/ |
163
|
4 |
|
public function getHeatmapLayerCollector() |
164
|
|
|
{ |
165
|
4 |
|
return $this->heatmapLayerCollector; |
166
|
|
|
} |
167
|
|
|
|
168
|
68 |
|
public function setHeatmapLayerCollector(HeatmapLayerCollector $heatmapLayerCollector) |
169
|
|
|
{ |
170
|
68 |
|
$this->heatmapLayerCollector = $heatmapLayerCollector; |
171
|
68 |
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param Coordinate[] $coordinates |
175
|
|
|
* |
176
|
|
|
* @return Coordinate[] |
177
|
|
|
*/ |
178
|
36 |
|
public function collect(Map $map, array $coordinates = []) |
179
|
|
|
{ |
180
|
36 |
|
if (!$map->isAutoZoom()) { |
181
|
32 |
|
$coordinates = $this->collectValue($map->getCenter(), $coordinates); |
182
|
|
|
} |
183
|
|
|
|
184
|
36 |
View Code Duplication |
foreach ($this->boundCollector->collect($map) as $bound) { |
|
|
|
|
185
|
8 |
|
if ($bound->hasCoordinates()) { |
186
|
4 |
|
$coordinates = $this->collectValue($bound->getSouthWest(), $coordinates); |
187
|
6 |
|
$coordinates = $this->collectValue($bound->getNorthEast(), $coordinates); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|
191
|
36 |
|
foreach ($this->circleCollector->collect($map) as $circle) { |
192
|
4 |
|
$coordinates = $this->collectValue($circle->getCenter(), $coordinates); |
193
|
|
|
} |
194
|
|
|
|
195
|
36 |
|
foreach ($this->infoWindowCollector->collect($map) as $infoWindow) { |
196
|
4 |
|
if ($infoWindow->hasPosition()) { |
197
|
4 |
|
$coordinates = $this->collectValue($infoWindow->getPosition(), $coordinates); |
|
|
|
|
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
201
|
36 |
|
foreach ($this->markerCollector->collect($map) as $marker) { |
202
|
4 |
|
$coordinates = $this->collectValue($marker->getPosition(), $coordinates); |
203
|
|
|
} |
204
|
|
|
|
205
|
36 |
|
foreach ($this->polygonCollector->collect($map) as $polygon) { |
206
|
4 |
|
$coordinates = $this->collectValues($polygon->getCoordinates(), $coordinates); |
207
|
|
|
} |
208
|
|
|
|
209
|
36 |
|
foreach ($this->polylineCollector->collect($map) as $polyline) { |
210
|
4 |
|
$coordinates = $this->collectValues($polyline->getCoordinates(), $coordinates); |
211
|
|
|
} |
212
|
|
|
|
213
|
36 |
|
foreach ($this->heatmapLayerCollector->collect($map) as $heatmapLayer) { |
214
|
4 |
|
$coordinates = $this->collectValues($heatmapLayer->getCoordinates(), $coordinates); |
215
|
|
|
} |
216
|
|
|
|
217
|
36 |
|
return $coordinates; |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
|
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.