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\Subscriber\Overlay; |
13
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\Collector\Overlay\DefaultInfoWindowCollector; |
15
|
|
|
use Ivory\GoogleMap\Helper\Collector\Overlay\InfoWindowCollector; |
16
|
|
|
use Ivory\GoogleMap\Helper\Event\MapEvent; |
17
|
|
|
use Ivory\GoogleMap\Helper\Event\MapEvents; |
18
|
|
|
use Ivory\GoogleMap\Helper\Formatter\Formatter; |
19
|
|
|
use Ivory\GoogleMap\Helper\Renderer\Overlay\DefaultInfoWindowRenderer; |
20
|
|
|
use Ivory\GoogleMap\Map; |
21
|
|
|
use Ivory\GoogleMap\Overlay\InfoWindow; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author GeLo <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class DefaultInfoWindowSubscriber extends AbstractInfoWindowSubscriber |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var DefaultInfoWindowRenderer |
30
|
|
|
*/ |
31
|
|
|
private $infoWindowRenderer; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Formatter $formatter |
35
|
|
|
* @param DefaultInfoWindowCollector $infoWindowCollector |
36
|
|
|
* @param DefaultInfoWindowRenderer $infoWindowRenderer |
37
|
|
|
*/ |
38
|
4 |
|
public function __construct( |
39
|
|
|
Formatter $formatter, |
40
|
|
|
DefaultInfoWindowCollector $infoWindowCollector, |
41
|
|
|
DefaultInfoWindowRenderer $infoWindowRenderer |
42
|
|
|
) { |
43
|
4 |
|
parent::__construct($formatter, $infoWindowCollector); |
44
|
|
|
|
45
|
4 |
|
$this->setInfoWindowRenderer($infoWindowRenderer); |
46
|
4 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return DefaultInfoWindowRenderer |
50
|
|
|
*/ |
51
|
|
|
public function getInfoWindowRenderer() |
52
|
|
|
{ |
53
|
|
|
return $this->infoWindowRenderer; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param DefaultInfoWindowRenderer $infoWindowRenderer |
58
|
|
|
*/ |
59
|
4 |
|
public function setInfoWindowRenderer(DefaultInfoWindowRenderer $infoWindowRenderer) |
60
|
|
|
{ |
61
|
4 |
|
$this->infoWindowRenderer = $infoWindowRenderer; |
62
|
4 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param MapEvent $event |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public function handleMap(MapEvent $event) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$map = $event->getMap(); |
70
|
|
|
$collector = $this->getInfoWindowCollector(); |
71
|
|
|
|
72
|
|
|
foreach ($collector->collect($map, [], InfoWindowCollector::STRATEGY_MAP) as $infoWindow) { |
73
|
|
|
$event->addCode($this->renderInfoWindow($map, $infoWindow)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
foreach ($collector->collect($map, [], InfoWindowCollector::STRATEGY_MARKER) as $infoWindow) { |
77
|
|
|
$event->addCode($this->renderInfoWindow($map, $infoWindow, false)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
4 |
|
public static function getSubscribedEvents() |
85
|
|
|
{ |
86
|
4 |
|
return [MapEvents::JAVASCRIPT_OVERLAY_INFO_WINDOW => 'handleMap']; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param Map $map |
91
|
|
|
* @param InfoWindow $infoWindow |
92
|
|
|
* @param bool $position |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
private function renderInfoWindow(Map $map, InfoWindow $infoWindow, $position = true) |
97
|
|
|
{ |
98
|
|
|
return $this->getFormatter()->renderContainerAssignment( |
99
|
|
|
$map, |
100
|
|
|
$this->infoWindowRenderer->render($infoWindow, $position), |
101
|
|
|
'overlays.info_windows', |
102
|
|
|
$infoWindow |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.