|
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\Layer; |
|
13
|
|
|
|
|
14
|
|
|
use Ivory\GoogleMap\Helper\Collector\Layer\GeoJsonLayerCollector; |
|
15
|
|
|
use Ivory\GoogleMap\Helper\Event\MapEvent; |
|
16
|
|
|
use Ivory\GoogleMap\Helper\Event\MapEvents; |
|
17
|
|
|
use Ivory\GoogleMap\Helper\Formatter\Formatter; |
|
18
|
|
|
use Ivory\GoogleMap\Helper\Renderer\Layer\GeoJsonLayerRenderer; |
|
19
|
|
|
use Ivory\GoogleMap\Helper\Subscriber\AbstractSubscriber; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author GeLo <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class GeoJsonLayerSubscriber extends AbstractSubscriber |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var GeoJsonLayerCollector |
|
28
|
|
|
*/ |
|
29
|
|
|
private $geoJsonLayerCollector; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var GeoJsonLayerRenderer |
|
33
|
|
|
*/ |
|
34
|
|
|
private $geoJsonLayerRenderer; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Formatter $formatter |
|
38
|
|
|
* @param GeoJsonLayerCollector $geoJsonLayerCollector |
|
39
|
|
|
* @param GeoJsonLayerRenderer $geoJsonLayerRenderer |
|
40
|
|
|
*/ |
|
41
|
220 |
|
public function __construct( |
|
42
|
|
|
Formatter $formatter, |
|
43
|
|
|
GeoJsonLayerCollector $geoJsonLayerCollector, |
|
44
|
|
|
GeoJsonLayerRenderer $geoJsonLayerRenderer |
|
45
|
|
|
) { |
|
46
|
220 |
|
parent::__construct($formatter); |
|
47
|
|
|
|
|
48
|
220 |
|
$this->setGeoJsonLayerCollector($geoJsonLayerCollector); |
|
49
|
220 |
|
$this->setGeoJsonLayerRenderer($geoJsonLayerRenderer); |
|
50
|
220 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return GeoJsonLayerCollector |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getGeoJsonLayerCollector() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->geoJsonLayerCollector; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param GeoJsonLayerCollector $geoJsonLayerCollector |
|
62
|
|
|
*/ |
|
63
|
220 |
|
public function setGeoJsonLayerCollector(GeoJsonLayerCollector $geoJsonLayerCollector) |
|
64
|
|
|
{ |
|
65
|
220 |
|
$this->geoJsonLayerCollector = $geoJsonLayerCollector; |
|
66
|
220 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return GeoJsonLayerRenderer |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getGeoJsonLayerRenderer() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->geoJsonLayerRenderer; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param GeoJsonLayerRenderer $geoJsonLayerRenderer |
|
78
|
|
|
*/ |
|
79
|
220 |
|
public function setGeoJsonLayerRenderer(GeoJsonLayerRenderer $geoJsonLayerRenderer) |
|
80
|
|
|
{ |
|
81
|
220 |
|
$this->geoJsonLayerRenderer = $geoJsonLayerRenderer; |
|
82
|
220 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param MapEvent $event |
|
86
|
|
|
*/ |
|
87
|
216 |
|
public function handleMap(MapEvent $event) |
|
88
|
|
|
{ |
|
89
|
216 |
|
$formatter = $this->getFormatter(); |
|
90
|
216 |
|
$map = $event->getMap(); |
|
91
|
|
|
|
|
92
|
216 |
|
foreach ($this->geoJsonLayerCollector->collect($map) as $geoJsonLayer) { |
|
93
|
4 |
|
$event->addCode($formatter->renderCode($this->geoJsonLayerRenderer->render($geoJsonLayer, $map))); |
|
94
|
108 |
|
} |
|
95
|
216 |
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* {@inheritdoc} |
|
99
|
|
|
*/ |
|
100
|
220 |
|
public static function getSubscribedEvents() |
|
101
|
|
|
{ |
|
102
|
220 |
|
return [MapEvents::JAVASCRIPT_LAYER_GEO_JSON_LAYER => 'handleMap']; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|