From 1bb9fb4d7a8c22e6a07510057c5142548df4a9d6 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 5 Oct 2016 10:54:05 +0200 Subject: [PATCH] Change multi polyline and multi polygone to work with leaflet v1. --- .../Mapper/Vector/MultiPolygonMapper.php | 6 ++--- .../Mapper/Vector/MultiPolylineMapper.php | 22 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php index 8f3e2a2..72fb405 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolygonMapper.php @@ -14,7 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\LeafletPHP\Definition; -use Netzmacht\LeafletPHP\Definition\Vector\MultiPolygon; +use Netzmacht\LeafletPHP\Definition\Vector\Polygon; /** * Class MultiPolygonMapper maps the multi polygon database model to its definition. @@ -28,7 +28,7 @@ class MultiPolygonMapper extends MultiPolylineMapper * * @var string */ - protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\MultiPolygon'; + protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polygon'; /** * Layer type. @@ -49,7 +49,7 @@ class MultiPolygonMapper extends MultiPolylineMapper ) { parent::build($definition, $model, $mapper, $filter); - if ($definition instanceof MultiPolygon) { + if ($definition instanceof Polygon) { $this->createLatLngs($definition, $model); } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php index a744b7a..7ecbc82 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/MultiPolylineMapper.php @@ -14,8 +14,8 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Definition\Vector\Polyline; use Netzmacht\LeafletPHP\Value\LatLng; -use Netzmacht\LeafletPHP\Definition\Vector\MultiPolyline; /** * Class MultiPolylineMapper maps the databse model it the multi polyline definition. @@ -29,7 +29,7 @@ class MultiPolylineMapper extends AbstractVectorMapper * * @var string */ - protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\MultiPolyline'; + protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polyline'; /** * Layer type. @@ -50,7 +50,7 @@ class MultiPolylineMapper extends AbstractVectorMapper ) { parent::build($definition, $model, $mapper, $filter); - if ($definition instanceof MultiPolyline) { + if ($definition instanceof Polyline) { $this->createLatLngs($definition, $model); } } @@ -58,24 +58,22 @@ class MultiPolylineMapper extends AbstractVectorMapper /** * Create lat lngs for the definition. * - * @param MultiPolyline $definition The multi polyline. - * @param \Model $model The definition model. + * @param Polyline $definition The multi polyline. + * @param \Model $model The definition model. * * @return void */ - protected function createLatLngs(MultiPolyline $definition, \Model $model) + protected function createLatLngs(Polyline $definition, \Model $model) { - $latLngs = array(); - - foreach (deserialize($model->multiData, true) as $data) { - $latLngs[] = array_map( + foreach (deserialize($model->multiData, true) as $ring => $data) { + $latLngs = array_map( function ($row) { return LatLng::fromString($row); }, explode("\n", $data) ); - } - $definition->setLatLngs($latLngs); + $definition->addLatLngs($latLngs, $ring); + } } }