Add more controls.

This commit is contained in:
David Molineus
2015-01-05 14:58:37 +01:00
parent be9060795d
commit c00d08c872
8 changed files with 173 additions and 5 deletions

View File

@@ -34,7 +34,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\ProviderL
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ZoomControlMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ScaleControlMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\LayersControlMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\AttributionControlMapper';
/*
* Leaflet encoders.

View File

@@ -62,6 +62,16 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
),
'toggle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['toggle'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => \Netzmacht\Contao\DevTools\Dca::createToggleIconCallback(
'tl_leaflet_control',
'active'
)
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['show'],
@@ -89,6 +99,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
),
'scale extends default' => array(
'config' => array('maxWidth', 'metric', 'imperial', 'updateWhenIdle')
),
'attribution extends default' => array(
'config' => array('attributions', 'prefix')
)
),
@@ -225,7 +238,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Control', 'getLayers'),
'eval' => array(
'style' => 'width: 200px',
'style' => 'width: 300px',
'chosen' => true,
'includeBlankOption' => true
),
@@ -279,5 +292,21 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'prefix' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['prefix'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'attributions' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['attributions'],
'exclude' => true,
'inputType' => 'listWizard',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'clr', 'allowHtml' => true),
'sql' => "mediumblob NULL"
),
),
);

View File

@@ -32,7 +32,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
(
'layers' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['layersBtn'],
'href' => 'table=tl_leaflet_layer',
'icon' => 'system/modules/leaflet/assets/img/layers.png',
'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"'

View File

@@ -6,8 +6,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_map']['zoom_legend'] = 'Center and zoom';
$GLOBALS['TL_LANG']['tl_leaflet_map']['controls_legend'] = 'Control widgets';
$GLOBALS['TL_LANG']['tl_leaflet_map']['expert_legend'] = 'Expert settings';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][0] = 'Manage layers';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][1] = 'Manage leaflet layers';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layersBtn'][0] = 'Manage layers';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layersBtn'][1] = 'Manage leaflet layers';
$GLOBALS['TL_LANG']['tl_leaflet_map']['new'][0] = 'Create map';
$GLOBALS['TL_LANG']['tl_leaflet_map']['new'][1] = 'Create new map';
$GLOBALS['TL_LANG']['tl_leaflet_map']['edit'][0] = 'Edit map';
@@ -61,6 +61,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_map']['options'][0] = 'Extra options'
$GLOBALS['TL_LANG']['tl_leaflet_map']['options'][1] = 'Add extra map options as valid json. See <a href="http://leafletjs.com/reference.html#map-options">http://leafletjs.com/reference.html#map-options</a>';
$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustZoomExtra'][0] = 'Adjust extra zoom settings';
$GLOBALS['TL_LANG']['tl_leaflet_map']['adjustZoomExtra'][1] = 'Enable if you want to adjust minimum and maximum zoom as well';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][0] = 'Default layers';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'][1] = 'Inital visible layers of the map. For optional layers use the layers control.';
$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomValues'][''][0] = 'Disable';
$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomValues'][''][1] = 'Disable zoom function.';

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}