Ongoing development.

This commit is contained in:
David Molineus
2015-01-06 14:55:53 +01:00
parent dfb558b655
commit e9d1ec7081
32 changed files with 1050 additions and 95 deletions

View File

@@ -0,0 +1,41 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Controller;
use Netzmacht\Contao\Leaflet\MapService;
class GeoJsonController
{
/**
* @var MapService
*/
private $mapService;
/**
* @var \Input
*/
private $input;
public function __construct(MapService $mapService, \Input $input)
{
$this->mapService = $mapService;
$this->input = $input;
}
public function execute()
{
$collection = $this->mapService->getFeatureCollection(\Input::get('id'));
return json_encode($collection);
}
}

View File

@@ -12,6 +12,9 @@
namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
class Layer
{
private $layers;
@@ -19,7 +22,10 @@ class Layer
public function __construct()
{
$this->layers = &$GLOBALS['LEAFLET_LAYERS'];
\Controller::loadLanguageFile('leaflet_layer');
}
public function getVariants($dataContainer)
{
if ($dataContainer->activeRecord
@@ -32,6 +38,48 @@ class Layer
return array();
}
public function generateRow($row, $label)
{
$alt = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0])
? $row['type']
: $GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0];
$title = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][1])
? $row['type']
: $GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][1];
if (!empty($this->layers[$row['type']]['icon'])) {
$icon = \Image::getHtml($this->layers[$row['type']]['icon'], $alt, sprintf('title="%s"', $title));
} else {
$icon = \Image::getHtml('iconPLAIN.gif', $alt, sprintf('title="%s"', $title));
}
return $icon . ' ' . $label;
}
public function getMarkerClusterLayers()
{
$types = array_keys(
array_filter(
$GLOBALS['LEAFLET_LAYERS'],
function ($item) {
return !empty($item['markerCluster']);
}
)
);
$collection = LayerModel::findMultipleByTypes($types);
$builder = OptionsBuilder::fromCollection(
$collection,
'id',
function($row) {
return sprintf('%s [%s]', $row['title'], $row['type']);
}
);
return $builder->getOptions();
}
// Call paste_button_callback (&$dc, $row, $table, $cr, $childs, $previous, $next)
public function getPasteButtons($dataContainer, $row, $table, $whatever, $children)
{
@@ -76,4 +124,18 @@ class Layer
return $buffer;
}
public function generateMarkersButton($row, $href, $label, $title, $icon, $attributes)
{
if (empty($this->layers[$row['type']]['markers'])) {
return '';
}
return sprintf(
'<a href="%s" title="%s">%s</a> ',
\Backend::addToUrl($href . '&amp;id=' . $row['id']),
$title,
\Image::getHtml($icon, $label, $attributes)
);
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Dca;
class Marker
{
public function generateRow($row)
{
return $row['title'];
}
}

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Event;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Symfony\Component\EventDispatcher\Event;
/**
@@ -37,16 +38,25 @@ class BuildDefinitionEvent extends Event
*/
private $model;
/**
* Optional bounds where elements should be in.
*
* @var LatLngBounds
*/
private $bounds;
/**
* Construct.
*
* @param Definition $definition The leaflet definition.
* @param \Model $model The definition model.
* @param Definition $definition The leaflet definition.
* @param \Model $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*/
public function __construct(Definition $definition, \Model $model)
public function __construct(Definition $definition, \Model $model, LatLngBounds $bounds = null)
{
$this->definition = $definition;
$this->model = $model;
$this->model = $model;
$this->bounds = $bounds;
}
/**
@@ -68,4 +78,14 @@ class BuildDefinitionEvent extends Event
{
return $this->model;
}
/**
* Get the bounds.
*
* @return LatLngBounds|null
*/
public function getBounds()
{
return $this->bounds;
}
}

View File

@@ -52,7 +52,7 @@ class LeafletMapElement extends \ContentElement
{
try {
$mapId = 'map_' . ($this->cssID[0] ?: $this->id);
$map = $this->mapService->getJavascript($this->leaflet_map, $mapId);
$map = $this->mapService->getJavascript($this->leaflet_map, null, $mapId);
$GLOBALS['TL_BODY'][] = '<script>' . $map .'</script>';

View File

@@ -13,9 +13,13 @@ namespace Netzmacht\Contao\Leaflet;
use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\LeafletPHP\Assets;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollectionAggregate;
use Netzmacht\LeafletPHP\Definition\Map;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Leaflet;
use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcher;
@@ -61,16 +65,17 @@ class MapService
/**
* Get map definition.
*
* @param int $mapId The map database id.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
* @param int $mapId The map database id.
* @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.
*
* @return Map
*/
public function getDefinition($mapId, $elementId = null)
public function getDefinition($mapId, LatLngBounds $bounds = null, $elementId = null)
{
$model = $this->getModel($mapId);
return $this->mapper->handle($model, $elementId);
return $this->mapper->handle($model, $bounds, $elementId);
}
/**
@@ -96,16 +101,15 @@ class MapService
/**
* Get map javascript.
*
* @param int $mapId The map id.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
* @param int $mapId The map id.
* @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.
*
* @return string
*
* @throws \Exception If an error occurred in the process.
*/
public function getJavascript($mapId, $elementId = null)
public function getJavascript($mapId, LatLngBounds $bounds = null, $elementId = null)
{
$definition = $this->getDefinition($mapId, $elementId);
$definition = $this->getDefinition($mapId, $bounds, $elementId);
$assets = new ContaoAssets();
$javascript = $this->leaflet->build($definition, $assets);
@@ -114,4 +118,23 @@ class MapService
return $event->getJavascript();
}
/**
* Get feature collection of a layer.
*
* @param int $layerId The layer id.
* @param LatLngBounds $bounds Filter features in the bounds.
*
* @return FeatureCollection
*/
public function getFeatureCollection($layerId, LatLngBounds $bounds = null)
{
$model = LayerModel::findByPK($layerId);
if (!$model || !$model->active) {
throw new \InvalidArgumentException(sprintf('Could not find layer "%s"', $layerId));
}
return $this->mapper->handleGeoJson($model, $bounds);
}
}

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class AbstractBuilder.
@@ -148,13 +149,13 @@ abstract class AbstractMapper implements Mapper
/**
* {@inheritdoc}
*/
public function handle(\Model $model, DefinitionMapper $builder)
public function handle(\Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
$definition = $this->createInstance($model, $builder);
$definition = $this->createInstance($model, $builder, $bounds);
$this->buildOptions($definition, $model);
$this->buildConditionals($definition, $model);
$this->doBuild($definition, $model, $builder);
$this->doBuild($definition, $model, $builder, $bounds);
return $definition;
}
@@ -182,14 +183,19 @@ abstract class AbstractMapper implements Mapper
/**
* Use for specific build methods.
*
* @param Definition $definition The definition being built.
* @param \Model $model The model.
* @param DefinitionMapper $builder The definition builder.
* @param Definition $definition The definition being built.
* @param \Model $model The model.
* @param DefinitionMapper $builder The definition builder.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return void
*/
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
{
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
}
/**
@@ -197,13 +203,14 @@ 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.
*
* @return Definition
*/
protected function createInstance(\Model $model, DefinitionMapper $mapper)
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$reflector = new \ReflectionClass(static::$definitionClass);
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper));
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
return $instance;
}
@@ -213,10 +220,11 @@ 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.
*
* @return array
*/
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
return array(
$model->alias ?: (str_replace('tl_leaflet_', '', $model->getTable()) . '_' . $model->id)

View File

@@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Control\Attribution;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* AttributionControlMapper maps the the attribution database definition to the definition class.
@@ -49,7 +50,7 @@ class AttributionControlMapper extends AbstractControlMapper
/**
* {@inheritdoc}
*/
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
if (!$definition instanceof Attribution) {
return;

View File

@@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
class LayersControlMapper extends AbstractControlMapper
{
@@ -31,9 +32,9 @@ class LayersControlMapper extends AbstractControlMapper
*/
protected static $type = 'layers';
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$arguments = parent::buildConstructArguments($model, $mapper);
$arguments = parent::buildConstructArguments($model, $mapper, $bounds);
$arguments[1] = array();
$arguments[2] = array();
@@ -44,7 +45,7 @@ class LayersControlMapper extends AbstractControlMapper
foreach ($collection as $layer) {
$argument = ($definition[$layer->id] === 'overlay') ? 2 : 1;
$arguments[$argument][] = $mapper->handle($layer);
$arguments[$argument][] = $mapper->handle($layer, $bounds);
}
}

View File

@@ -13,6 +13,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\Contao\Leaflet\Event\BuildDefinitionEvent;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\GeoJson\Feature;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcher;
/**
@@ -70,6 +73,8 @@ class DefinitionMapper
{
$this->builders[$priority][] = $builder;
ksort($this->builders);
return $this;
}
@@ -86,12 +91,13 @@ class DefinitionMapper
/**
* Build a model.
*
* @param \Model $model The definition model.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
* @param \Model $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.
*
* @return Definition
*/
public function handle(\Model $model, $elementId = null)
public function handle(\Model $model, LatLngBounds $bounds = null, $elementId = null)
{
$hash = $model->getTable() . '.' . $model->{$model->getPk()};
@@ -99,16 +105,14 @@ class DefinitionMapper
return $this->mapped[$hash];
}
krsort($this->builders);
$this->mapId = $elementId ?: ($model->alias ?: ('map_' . $model->id));
foreach ($this->builders as $builders) {
foreach($builders as $builder) {
if ($builder->match($model)) {
$definition = $builder->handle($model, $this);
$definition = $builder->handle($model, $this, $bounds);
$event = new BuildDefinitionEvent($definition, $model);
$event = new BuildDefinitionEvent($definition, $model, $bounds);
$this->eventDispatcher->dispatch($event::NAME, $event);
$this->mapped[$hash] = $definition;
@@ -126,4 +130,43 @@ class DefinitionMapper
)
);
}
/**
* Build a model.
*
* @param \Model $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return FeatureCollection|Feature
*/
public function handleGeoJson(\Model $model, LatLngBounds $bounds = null)
{
foreach ($this->builders as $builders) {
foreach ($builders as $builder) {
if (!$builder->match($model)) {
continue;
}
if ($builder instanceof GeoJsonMapper) {
return $builder->handleGeoJson($model, $this, $bounds);
}
throw new \RuntimeException(
sprintf(
'Builder for model "%s::%s" is not a GeoJsonMapper',
$model->getTable(),
$model->{$model->getPk()}
)
);
}
}
throw new \RuntimeException(
sprintf(
'Could not build geo json of model "%s::%s". No matching builders found.',
$model->getTable(),
$model->{$model->getPk()}
)
);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
interface GeoJsonMapper
{
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
class AbstractLayerMapper extends AbstractTypeMapper
{
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker;
class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Group\GeoJson';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'markers';
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
if ($definition instanceof LayerGroup) {
$collection = MarkerModel::findBy(
array('active=1', 'pid=?'),
array($model->id)
);
if ($collection) {
foreach ($collection as $item) {
$marker = new Marker('marker_' . $item->id, $item->coordinates);
$marker->setTitle($item->tooltip);
$definition->addLayer($marker);
}
}
}
}
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$feature = new FeatureCollection();
$collection = MarkerModel::findBy(
array('active=1', 'pid=?'),
array($model->id)
);
if ($collection) {
foreach ($collection as $item) {
$marker = new Marker('marker_' . $item->id, $item->coordinates);
$marker->setTitle($item->tooltip);
$feature->addFeature($marker->getFeature());
}
}
return $feature;
}
}

View File

@@ -11,20 +11,12 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
class ProviderLayerMapper extends AbstractTypeMapper
class ProviderLayerMapper extends AbstractLayerMapper
{
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
/**
* Class of the definition being created.
*
@@ -61,7 +53,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
/**
* {@inheritdoc}
*/
protected function createInstance(\Model $model, DefinitionMapper $mapper)
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
if (isset($this->providers[$model->tile_provider]['class'])) {
$class = $this->providers[$model->tile_provider]['class'];
@@ -70,7 +62,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
}
$reflector = new \ReflectionClass($class);
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper));
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
return $instance;
}
@@ -78,7 +70,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
/**
* {@inheritdoc}
*/
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
if (!empty($this->providers[$model->tile_provider]['options'])) {
$this->applyOptions(
@@ -92,7 +84,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
/**
* {@inheritdoc}
*/
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
return array(
$model->alias ?: ('layer_' . $model->id),

View File

@@ -16,6 +16,7 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Map;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Plugins\LeafletProviders\Provider;
class MapMapper extends AbstractMapper
@@ -50,19 +51,19 @@ class MapMapper extends AbstractMapper
/**
* @inheritdoc
*/
protected function doBuild(Definition $map, \Model $model, DefinitionMapper $builder)
protected function doBuild(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
if ($map instanceof Map && $model instanceof MapModel) {
$this->buildCustomOptions($map, $model);
$this->buildControls($map, $model, $builder);
$this->buildLayers($map, $model, $builder);
$this->buildControls($map, $model, $builder, $bounds);
$this->buildLayers($map, $model, $builder, $bounds);
}
}
/**
* @inheritdoc
*/
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
return array(
$mapper->getMapId(),
@@ -91,8 +92,9 @@ class MapMapper extends AbstractMapper
* @param Map $map The map being built.
* @param MapModel $model The map model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds.
*/
private function buildControls(Map $map, MapModel$model, DefinitionMapper $mapper)
private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$collection = ControlModel::findBy(
array('pid=?', 'active=1'),
@@ -102,7 +104,7 @@ class MapMapper extends AbstractMapper
if ($collection) {
foreach ($collection as $control) {
$control = $mapper->handle($control);
$control = $mapper->handle($control, $bounds);
$map->addControl($control);
}
}
@@ -114,16 +116,22 @@ class MapMapper extends AbstractMapper
* @param Map $map The map being built.
* @param MapModel $model The map model.
* @param DefinitionMapper $mapper Definition mapper.
* @param LatLngBounds $bounds Optional bounds.
*/
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper)
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$ids = deserialize($model->layers, true);
$collection = LayerModel::findMultipleByIds($ids);
if ($collection) {
foreach ($collection as $layer) {
if (!$layer->active) {
continue;
}
$layer = $mapper->handle($layer, $bounds);
/** @var Provider $layer */
$layer = $mapper->handle($layer);
$map->addLayer($layer);
}
}

View File

@@ -12,21 +12,23 @@
namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
interface Mapper
{
/**
* Map model to the definition.
*
* @param \Model $model The model being built.
* @param DefinitionMapper $builder The definition builder.
* @param \Model $model The model being built.
* @param DefinitionMapper $mapper The definition builder.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return Definition
*/
public function handle(\Model $model, DefinitionMapper $builder);
public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
/**
* Check if builder is responsible for the model.
* Check if mapper is responsible for the model.
*
* @param \Model $model The model being build.
*

View File

@@ -16,4 +16,21 @@ class LayerModel extends \Model
{
protected static $strTable = 'tl_leaflet_layer';
public static function findMultipleByTypes(array $types, $options = array())
{
if (empty($types)) {
return null;
}
$options['column'] = array(
sprintf(
'type IN (%s)',
substr(str_repeat('?,', count($types)), 0, -1)
)
);
$options['value'] = $types;
return static::find($options);
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
class MarkerModel extends \Model
{
protected static $strTable = 'tl_leaflet_marker';
}