Rework geojson handling.

This commit is contained in:
David Molineus
2015-01-12 10:45:05 +01:00
parent 9a37da12e6
commit 58b370b22a
2 changed files with 16 additions and 4 deletions

View File

@@ -21,8 +21,8 @@ use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\Group\GeoJson; use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup; use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker;
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax; use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
use PhpSpec\Exception\Exception;
class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{ {
@@ -94,7 +94,11 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
if ($collection) { if ($collection) {
foreach ($collection as $item) { foreach ($collection as $item) {
$feature->addFeature($mapper->handle($item)->toGeoJson()); $marker = $mapper->handle($item);
if ($marker instanceof Marker) {
$feature->addFeature($marker->toGeoJsonFeature());
}
} }
} }

View File

@@ -13,15 +13,17 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper; use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
use Netzmacht\Contao\Leaflet\Model\VectorModel; use Netzmacht\Contao\Leaflet\Model\VectorModel;
use Netzmacht\Contao\Leaflet\Frontend\RequestUrl; use Netzmacht\Contao\Leaflet\Frontend\RequestUrl;
use Netzmacht\Javascript\Type\Value\Expression; use Netzmacht\Javascript\Type\Value\Expression;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\GeoJson\ConvertsToGeoJsonFeature;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection; use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\GeoJson\GeoJsonFeature;
use Netzmacht\LeafletPHP\Definition\Group\GeoJson; use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup; use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector;
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax; use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
@@ -98,7 +100,13 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
if ($collection) { if ($collection) {
foreach ($collection as $item) { foreach ($collection as $item) {
$feature->addFeature($mapper->handle($item)->toGeoJson()); $vector = $mapper->handle($item);
if ($vector instanceof ConvertsToGeoJsonFeature) {
$feature->addFeature($vector->toGeoJsonFeature());
} elseif ($vector instanceof GeoJsonFeature) {
$feature->addFeature($vector);
}
} }
} }