forked from Snck3rs/contao-leaflet-maps
Add parent to mapper handle method.
This commit is contained in:
@@ -151,13 +151,18 @@ abstract class AbstractMapper implements Mapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null)
|
||||
{
|
||||
public function handle(
|
||||
$model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
$elementId = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
$definition = $this->createInstance($model, $mapper, $bounds, $elementId);
|
||||
|
||||
$this->buildOptions($definition, $model);
|
||||
$this->buildConditionals($definition, $model);
|
||||
$this->build($definition, $model, $mapper, $bounds);
|
||||
$this->build($definition, $model, $mapper, $bounds, $parent);
|
||||
|
||||
return $definition;
|
||||
}
|
||||
@@ -188,6 +193,7 @@ abstract class AbstractMapper implements Mapper
|
||||
* @param \Model $model The model.
|
||||
* @param DefinitionMapper $mapper The definition mapper.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param Definition|null $parent The parent object.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
@@ -197,7 +203,8 @@ abstract class AbstractMapper implements Mapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,9 @@ class AttributionControlMapper extends AbstractControlMapper
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if (!$definition instanceof Attribution) {
|
||||
return;
|
||||
|
||||
@@ -69,7 +69,8 @@ class LoadingControlMapper extends AbstractControlMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
|
||||
@@ -77,15 +77,16 @@ class DefinitionMapper
|
||||
/**
|
||||
* Build a model.
|
||||
*
|
||||
* @param mixed $model The definition model.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param string $elementId Optional element id. If none given the mapId or alias is used.
|
||||
* @param mixed $model The definition model.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param string $elementId Optional element id. If none given the mapId or alias is used.
|
||||
* @param Definition|null $parent Optional pass the parent object.
|
||||
*
|
||||
* @return Definition|null
|
||||
*
|
||||
* @throws \RuntimeException If model could not be mapped to a definition.
|
||||
*/
|
||||
public function handle($model, LatLngBounds $bounds = null, $elementId = null)
|
||||
public function handle($model, LatLngBounds $bounds = null, $elementId = null, $parent = null)
|
||||
{
|
||||
$hash = $this->getHash($model, $elementId);
|
||||
|
||||
@@ -96,7 +97,7 @@ class DefinitionMapper
|
||||
foreach ($this->builders as $builders) {
|
||||
foreach ($builders as $builder) {
|
||||
if ($builder->match($model)) {
|
||||
$definition = $builder->handle($model, $this, $bounds, $elementId);
|
||||
$definition = $builder->handle($model, $this, $bounds, $elementId, $parent);
|
||||
|
||||
if ($definition) {
|
||||
$event = new BuildDefinitionEvent($definition, $model, $bounds);
|
||||
|
||||
@@ -58,7 +58,8 @@ class GroupLayerMapper extends AbstractLayerMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if (!$definition instanceof LayerGroup) {
|
||||
return;
|
||||
|
||||
@@ -86,7 +86,8 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if ($definition instanceof GeoJson) {
|
||||
$collection = $this->loadMarkerModels($model);
|
||||
|
||||
@@ -73,8 +73,9 @@ class ProviderLayerMapper extends AbstractLayerMapper
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if (!empty($this->providers[$model->tile_provider]['options'])) {
|
||||
$this->applyOptions(
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
@@ -32,7 +33,7 @@ class ReferenceLayerMapper extends AbstractLayerMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null)
|
||||
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null, Definition $parent = null)
|
||||
{
|
||||
$reference = LayerModel::findByPk($model->reference);
|
||||
|
||||
|
||||
@@ -100,7 +100,8 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if ($definition instanceof GeoJson) {
|
||||
$collection = $this->loadVectorModels($model);
|
||||
|
||||
@@ -57,12 +57,17 @@ class MapMapper extends AbstractMapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
|
||||
{
|
||||
protected function build(
|
||||
Definition $map,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if ($map instanceof Map && $model instanceof MapModel) {
|
||||
$this->buildCustomOptions($map, $model);
|
||||
$this->buildControls($map, $model, $builder, $bounds);
|
||||
$this->buildLayers($map, $model, $builder, $bounds);
|
||||
$this->buildControls($map, $model, $mapper, $bounds);
|
||||
$this->buildLayers($map, $model, $mapper, $bounds);
|
||||
$this->buildBoundsCalculation($map, $model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,18 @@ interface Mapper
|
||||
* @param \Model|mixed $model The model being built. Usually a contao model, but can be anything.
|
||||
* @param DefinitionMapper $mapper The definition builder.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param string $elementId Optional element id.
|
||||
* @param string $elementId Optional element.
|
||||
* @param Definition|null $parent Optional passed parent.
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null);
|
||||
public function handle(
|
||||
$model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
$elementId = null,
|
||||
Definition $parent = null
|
||||
);
|
||||
|
||||
/**
|
||||
* Check if mapper is responsible for the model.
|
||||
|
||||
@@ -54,7 +54,8 @@ class DivIconMapper extends AbstractIconMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if ($definition instanceof ImageIcon) {
|
||||
$this->addIcon($definition, $model);
|
||||
|
||||
@@ -73,8 +73,9 @@ class MarkerMapper extends AbstractMapper
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
if ($definition instanceof Marker) {
|
||||
if ($model->addPopup) {
|
||||
@@ -90,7 +91,7 @@ class MarkerMapper extends AbstractMapper
|
||||
|
||||
if ($iconModel) {
|
||||
/** @var ImageIcon $icon */
|
||||
$icon = $builder->handle($iconModel);
|
||||
$icon = $mapper->handle($iconModel);
|
||||
$definition->setIcon($icon);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ class AbstractVectorMapper extends AbstractTypeMapper
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
|
||||
@@ -54,10 +54,11 @@ class CircleMapper extends AbstractVectorMapper
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $builder, $bounds);
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
if ($definition instanceof Circle) {
|
||||
$definition->setLatLng(LatLng::fromString($model->coordinates));
|
||||
|
||||
@@ -44,10 +44,11 @@ class MultiPolygonMapper extends MultiPolylineMapper
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $builder, $bounds);
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
if ($definition instanceof MultiPolygon) {
|
||||
$this->createLatLngs($definition, $model);
|
||||
|
||||
@@ -45,10 +45,11 @@ class MultiPolylineMapper extends AbstractVectorMapper
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $builder, $bounds);
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
if ($definition instanceof MultiPolyline) {
|
||||
$this->createLatLngs($definition, $model);
|
||||
|
||||
@@ -44,10 +44,11 @@ class PolylineMapper extends AbstractVectorMapper
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $builder,
|
||||
LatLngBounds $bounds = null
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $builder, $bounds);
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
if ($definition instanceof Polyline) {
|
||||
array_map(
|
||||
|
||||
Reference in New Issue
Block a user