From d4c70f1f11e65bc2d6a55bb4dc4946e069eba251 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Sun, 18 Jan 2015 23:19:52 +0100 Subject: [PATCH] Add markers and vectors as feature to the layer. --- .../Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php | 8 ++++++-- .../Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php index 481c38d..5dda6ad 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php @@ -67,7 +67,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper if ($model->deferred) { if ($model->pointToLayer) { - $layer = new GeoJson($this->getElementId($model, $elementId) . '_1'); + $layer = new GeoJson($this->getElementId($model, $elementId)); $layer->setPointToLayer(new Expression($model->pointToLayer)); return array($this->getElementId($model, $elementId), RequestUrl::create($model->id), array(), $layer); @@ -93,7 +93,11 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper if ($collection) { foreach ($collection as $item) { - $definition->addLayer($mapper->handle($item)); + $marker = $mapper->handle($item); + + if ($marker instanceof Marker) { + $definition->addData($marker->toGeoJsonFeature(), true); + } } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php index 598c84b..b49d1b3 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php @@ -80,7 +80,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper } if (!empty($options)) { - $layer = new GeoJson($this->getElementId($model, $elementId) . '_1'); + $layer = new GeoJson($this->getElementId($model, $elementId)); $layer->setOptions($options); return array($this->getElementId($model, $elementId), RequestUrl::create($model->id), array(), $layer); @@ -108,8 +108,8 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper foreach ($collection as $item) { $vector = $mapper->handle($item); - if ($vector instanceof Layer) { - $definition->addLayer($vector); + if ($vector instanceof ConvertsToGeoJsonFeature) { + $definition->addData($vector->toGeoJsonFeature(), true); } } }