forked from Snck3rs/contao-leaflet-maps
Refactor the mappers to use the filters.
This commit is contained in:
@@ -11,12 +11,12 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
|
||||
use Netzmacht\LeafletPHP\Definition\Layer;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class GroupLayerMapper maps the layer model to the group layer definition.
|
||||
@@ -35,7 +35,7 @@ class GroupLayerMapper extends AbstractLayerMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null)
|
||||
{
|
||||
if ($model->groupType === 'feature') {
|
||||
return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup';
|
||||
@@ -51,7 +51,7 @@ class GroupLayerMapper extends AbstractLayerMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if (!$definition instanceof LayerGroup) {
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Layer;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Plugins\MarkerCluster\MarkerClusterGroup;
|
||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\OmnivoreLayer;
|
||||
|
||||
@@ -67,10 +67,10 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $bounds, $parent);
|
||||
parent::build($definition, $model, $mapper, $filter, $parent);
|
||||
|
||||
/** @var MarkerClusterGroup $definition */
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
|
||||
@@ -19,8 +20,6 @@ use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
||||
|
||||
/**
|
||||
* Class MarkersLayerMapper maps the layer model to the markers definition.
|
||||
@@ -39,7 +38,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null)
|
||||
{
|
||||
if ($model->deferred) {
|
||||
return 'Netzmacht\LeafletPHP\Plugins\Omnivore\GeoJson';
|
||||
@@ -54,7 +53,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
protected function buildConstructArguments(
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
$elementId = null
|
||||
) {
|
||||
if ($model->deferred) {
|
||||
@@ -75,7 +74,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
return array($this->getElementId($model, $elementId), RequestUrl::create($model->id));
|
||||
}
|
||||
|
||||
return parent::buildConstructArguments($model, $mapper, $bounds, $elementId);
|
||||
return parent::buildConstructArguments($model, $mapper, $filter, $elementId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +84,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if ($definition instanceof GeoJson) {
|
||||
@@ -115,7 +114,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, Filter $filter = null)
|
||||
{
|
||||
$feature = new FeatureCollection();
|
||||
$collection = $this->loadMarkerModels($model);
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\OptionsBuilder;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class ProviderLayerMapper maps the layer model to the tile provider definition.
|
||||
@@ -52,7 +52,7 @@ class ProviderLayerMapper extends AbstractLayerMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null)
|
||||
{
|
||||
if (isset($this->providers[$model->tile_provider]['class'])) {
|
||||
return $this->providers[$model->tile_provider]['class'];
|
||||
@@ -68,7 +68,7 @@ class ProviderLayerMapper extends AbstractLayerMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if (!empty($this->providers[$model->tile_provider]['options'])) {
|
||||
@@ -86,7 +86,7 @@ class ProviderLayerMapper extends AbstractLayerMapper
|
||||
protected function buildConstructArguments(
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
$elementId = null
|
||||
) {
|
||||
return array(
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class ReferenceLayerMapper maps an reference layer to another layer.
|
||||
@@ -36,7 +36,7 @@ class ReferenceLayerMapper extends AbstractLayerMapper
|
||||
public function handle(
|
||||
$model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
$elementId = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
@@ -48,6 +48,6 @@ class ReferenceLayerMapper extends AbstractLayerMapper
|
||||
|
||||
$elementId = $model->standalone ? $this->getElementId($model, $elementId) : null;
|
||||
|
||||
return $mapper->handle($reference, $bounds, $elementId);
|
||||
return $mapper->handle($reference, $filter, $elementId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Raster\TileLayer;
|
||||
@@ -64,10 +65,10 @@ class TileLayerMapper extends AbstractLayerMapper
|
||||
protected function buildConstructArguments(
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
$elementId = null
|
||||
) {
|
||||
$arguments = parent::buildConstructArguments($model, $mapper, $bounds, $elementId);
|
||||
$arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId);
|
||||
|
||||
$arguments[] = $model->tileUrl;
|
||||
|
||||
@@ -81,24 +82,24 @@ class TileLayerMapper extends AbstractLayerMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $bounds, $parent);
|
||||
parent::build($definition, $model, $mapper, $filter, $parent);
|
||||
|
||||
/** @var TileLayer $definition */
|
||||
$bounds = deserialize($model->bounds);
|
||||
$filter = deserialize($model->bounds);
|
||||
|
||||
if ($bounds[0] && $bounds[1]) {
|
||||
$bounds = array_map(
|
||||
if ($filter[0] && $filter[1]) {
|
||||
$filter = array_map(
|
||||
function ($value) {
|
||||
return explode(',', $value, 3);
|
||||
},
|
||||
$bounds
|
||||
$filter
|
||||
);
|
||||
|
||||
$bounds = LatLngBounds::fromArray($bounds);
|
||||
$definition->setBounds($bounds);
|
||||
$filter = LatLngBounds::fromArray($filter);
|
||||
$definition->setBounds($filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,18 +11,15 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\VectorModel;
|
||||
use Netzmacht\Contao\Leaflet\Frontend\RequestUrl;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\ConvertsToGeoJsonFeature;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\Feature;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\GeoJsonFeature;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector;
|
||||
|
||||
/**
|
||||
@@ -42,7 +39,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null)
|
||||
{
|
||||
if ($model->deferred) {
|
||||
return 'Netzmacht\LeafletPHP\Plugins\Omnivore\GeoJson';
|
||||
@@ -57,7 +54,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
protected function buildConstructArguments(
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
$elementId = null
|
||||
) {
|
||||
if ($model->deferred) {
|
||||
@@ -85,7 +82,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
return array($this->getElementId($model, $elementId), RequestUrl::create($model->id));
|
||||
}
|
||||
|
||||
return parent::buildConstructArguments($model, $mapper, $bounds, $elementId);
|
||||
return parent::buildConstructArguments($model, $mapper, $filter, $elementId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +92,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if ($definition instanceof GeoJson) {
|
||||
@@ -123,7 +120,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, Filter $filter = null)
|
||||
{
|
||||
$definition = new FeatureCollection();
|
||||
$collection = $this->loadVectorModels($model);
|
||||
|
||||
Reference in New Issue
Block a user