mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-29 03:24:37 +01:00
Add more controls.
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
|
||||
class Control
|
||||
{
|
||||
public function generateRow($row)
|
||||
@@ -22,4 +24,18 @@ class Control
|
||||
$row['type']
|
||||
);
|
||||
}
|
||||
|
||||
public function getLayers()
|
||||
{
|
||||
$options = array();
|
||||
$collection = LayerModel::findBy('pid', '0', array('order' => 'title'));
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $model) {
|
||||
$options[$model->id] = $model->title;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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\Control;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Control\Attribution;
|
||||
|
||||
/**
|
||||
* AttributionControlMapper maps the the attribution database definition to the definition class.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Control
|
||||
*/
|
||||
class AttributionControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
* Class of the definition being created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Control\Attribution';
|
||||
|
||||
/**
|
||||
* Layer type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'attribution';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->addConditionalOption('prefix');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
|
||||
{
|
||||
if (!$definition instanceof Attribution) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attributions = deserialize($model->attributions, true);
|
||||
|
||||
foreach ($attributions as $attribution) {
|
||||
$definition->addAttribution($attribution);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Control;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
|
||||
class LayersControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
@@ -27,4 +30,45 @@ class LayersControlMapper extends AbstractControlMapper
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'layers';
|
||||
|
||||
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
|
||||
{
|
||||
$arguments = parent::buildConstructArguments($model, $mapper);
|
||||
$arguments[1] = array();
|
||||
$arguments[2] = array();
|
||||
|
||||
$definition = $this->getLayersDefinition($model);
|
||||
$collection = LayerModel::findMultipleByIds(array_keys($definition));
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $layer) {
|
||||
$argument = ($definition[$layer->id] === 'overlay') ? 2 : 1;
|
||||
|
||||
$arguments[$argument][] = $mapper->handle($layer);
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get layers definition from the control model.
|
||||
*
|
||||
* @param \Model $model The control model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getLayersDefinition(\Model $model)
|
||||
{
|
||||
$layers = deserialize($model->layers, true);
|
||||
$definition = array();
|
||||
|
||||
foreach ($layers as $layer) {
|
||||
if ($layer['layer']) {
|
||||
$definition[$layer['layer']] = $layer['mode'];
|
||||
}
|
||||
}
|
||||
|
||||
return $definition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,11 @@ class DefinitionMapper
|
||||
*/
|
||||
private $mapId;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $mapped = array();
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
@@ -88,6 +93,12 @@ class DefinitionMapper
|
||||
*/
|
||||
public function handle(\Model $model, $elementId = null)
|
||||
{
|
||||
$hash = $model->getTable() . '.' . $model->{$model->getPk()};
|
||||
|
||||
if (isset($this->mapped[$hash])) {
|
||||
return $this->mapped[$hash];
|
||||
}
|
||||
|
||||
krsort($this->builders);
|
||||
|
||||
$this->mapId = $elementId ?: ($model->alias ?: ('map_' . $model->id));
|
||||
@@ -100,6 +111,8 @@ class DefinitionMapper
|
||||
$event = new BuildDefinitionEvent($definition, $model);
|
||||
$this->eventDispatcher->dispatch($event::NAME, $event);
|
||||
|
||||
$this->mapped[$hash] = $definition;
|
||||
|
||||
return $definition;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user