mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 19:13:55 +01:00
Make mapper interface independent from Contao models.
This commit is contained in:
@@ -15,7 +15,9 @@ use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class AbstractMapper.
|
||||
* Class AbstractMapper is made for mapping Contao models to the definition.
|
||||
*
|
||||
* For custom sources besides Contao models use your own implementation of the mapper interface.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper
|
||||
*/
|
||||
@@ -149,7 +151,7 @@ abstract class AbstractMapper implements Mapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
$definition = $this->createInstance($model, $mapper, $bounds);
|
||||
|
||||
@@ -163,7 +165,7 @@ abstract class AbstractMapper implements Mapper
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function match(\Model $model)
|
||||
public function match($model, LatLngBounds $bounds = null)
|
||||
{
|
||||
$modelClass = static::$modelClass;
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper;
|
||||
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
|
||||
abstract class AbstractTypeMapper extends AbstractMapper
|
||||
{
|
||||
protected static $type;
|
||||
|
||||
public function match(\Model $model)
|
||||
public function match($model, LatLngBounds $bounds = null)
|
||||
{
|
||||
return parent::match($model) && $model->type === static::$type;
|
||||
}
|
||||
|
||||
@@ -19,20 +19,21 @@ interface Mapper
|
||||
/**
|
||||
* Map model to the definition.
|
||||
*
|
||||
* @param \Model $model The model being built.
|
||||
* @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.
|
||||
*
|
||||
* @return Definition
|
||||
*/
|
||||
public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
|
||||
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
|
||||
|
||||
/**
|
||||
* Check if mapper is responsible for the model.
|
||||
*
|
||||
* @param \Model $model The model being build.
|
||||
* @param \Model $model The model being build.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function match(\Model $model);
|
||||
public function match($model, LatLngBounds $bounds = null);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Path;
|
||||
|
||||
class AbstractVectorMapper extends AbstractTypeMapper
|
||||
{
|
||||
@@ -49,7 +48,7 @@ class AbstractVectorMapper extends AbstractTypeMapper
|
||||
) {
|
||||
parent::build($definition, $model, $builder, $bounds);
|
||||
|
||||
if ($model->addPopup) {
|
||||
if ($definition instanceof Definition\HasPopup && $model->addPopup) {
|
||||
$definition->bindPopup($model->popupContent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user