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\Overlay; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\Collector\AbstractCollector; |
15
|
|
|
use Ivory\GoogleMap\Map; |
16
|
|
|
use Ivory\GoogleMap\Overlay\InfoWindow; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author GeLo <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class InfoWindowCollector extends AbstractCollector |
22
|
|
|
{ |
23
|
|
|
const STRATEGY_MAP = 1; |
24
|
|
|
const STRATEGY_MARKER = 2; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var MarkerCollector |
28
|
|
|
*/ |
29
|
|
|
private $markerCollector; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|null |
33
|
|
|
*/ |
34
|
|
|
private $type; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param MarkerCollector $markerCollector |
38
|
|
|
* @param string|null $type |
39
|
|
|
*/ |
40
|
|
|
public function __construct(MarkerCollector $markerCollector, $type = null) |
41
|
|
|
{ |
42
|
|
|
$this->setMarkerCollector($markerCollector); |
43
|
|
|
$this->setType($type); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return MarkerCollector |
48
|
|
|
*/ |
49
|
|
|
public function getMarkerCollector() |
50
|
|
|
{ |
51
|
|
|
return $this->markerCollector; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param MarkerCollector $markerCollector |
56
|
|
|
*/ |
57
|
|
|
public function setMarkerCollector(MarkerCollector $markerCollector) |
58
|
|
|
{ |
59
|
|
|
$this->markerCollector = $markerCollector; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return string|null |
64
|
|
|
*/ |
65
|
|
|
public function getType() |
66
|
|
|
{ |
67
|
|
|
return $this->type; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string|null $type |
72
|
|
|
*/ |
73
|
|
|
public function setType($type) |
74
|
|
|
{ |
75
|
|
|
$this->type = $type; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param Map $map |
80
|
|
|
* @param InfoWindow[] $infoWindows |
81
|
|
|
* @param int $strategy |
82
|
|
|
* |
83
|
|
|
* @return InfoWindow[] |
84
|
|
|
*/ |
85
|
|
|
public function collect( |
86
|
|
|
Map $map, |
87
|
|
|
array $infoWindows = [], |
88
|
|
|
$strategy = self::STRATEGY_MAP | self::STRATEGY_MARKER |
89
|
|
|
) { |
90
|
|
|
if ($strategy & self::STRATEGY_MAP) { |
91
|
|
|
$infoWindows = $this->collectValues($map->getOverlayManager()->getInfoWindows(), $infoWindows); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if ($strategy & self::STRATEGY_MARKER) { |
95
|
|
|
foreach ($this->markerCollector->collect($map) as $marker) { |
96
|
|
|
if ($marker->hasInfoWindow()) { |
97
|
|
|
$infoWindows = $this->collectValue($marker->getInfoWindow(), $infoWindows); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $infoWindows; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
protected function collectValue($value, array $defaults = []) |
109
|
|
|
{ |
110
|
|
|
if ($this->type !== null && $value->getType() !== $this->type) { |
111
|
|
|
return $defaults; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return parent::collectValue($value, $defaults); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|