Add layer group support.

This commit is contained in:
David Molineus
2015-01-07 12:13:26 +01:00
parent 9e1c8499f2
commit b47e6ccb8a
4 changed files with 107 additions and 12 deletions

View File

@@ -41,6 +41,7 @@ $GLOBALS['LEAFLET_MAPPERS'] = array();
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\MapMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\ProviderLayerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\MarkersLayerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\GroupLayerMapper';
$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';
@@ -76,11 +77,6 @@ $GLOBALS['LEAFLET_ENCODERS'][] = 'Netzmacht\Contao\Leaflet\Subscriber\EncoderSub
*/
$GLOBALS['LEAFLET_LAYERS'] = array
(
'default' => array
(
'children' => true,
'icon' => '',
),
'provider' => array
(
'children' => false,
@@ -91,13 +87,6 @@ $GLOBALS['LEAFLET_LAYERS'] = array
'children' => true,
'icon' => 'system/modules/leaflet/assets/img/group.png',
),
'elements' => array
(
'children' => true,
'filter' => 'whitelist',
'layers' => array('markers', 'vectors'),
'icon' => 'system/modules/leaflet/assets/img/map.png',
),
'markers' => array
(
'children' => false,

View File

@@ -127,6 +127,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'+title' => array('markerCluster'),
'+active' => array('deferred')
),
'group extends default' => array(
'+title' => array('groupType'),
) ,
),
'metasubselectpalettes' => array(
@@ -263,5 +266,21 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'eval' => array('tl_class' => 'w50', 'submitOnChange' => false),
'sql' => "char(1) NOT NULL default ''"
),
'groupType' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupType'],
'exclude' => true,
'inputType' => 'select',
'eval' => array(
'mandatory' => true,
'tl_class' => 'w50',
'submitOnChange' => true,
'helpwizard' => true,
),
'default' => 'layer',
'options' => array('layer', 'feature'),
'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes'],
'sql' => "varchar(32) NOT NULL default ''"
),
)
);

View File

@@ -38,3 +38,10 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'][0] = 'Marker cl
$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'][1] = 'Choose a marker cluster layer so that markers get clustered.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'][0] = 'Deferred loading';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'][1] = 'Load data of the layer deferred using ajax.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupType'][0] = 'Group type';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupType'][1] = 'Choose a layer group type.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][0] = 'Layer group';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][1] = 'Basic layer group. <br> See <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">http://leafletjs.com/reference.html#layergroup</a>';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['feature'][0] = 'Feature group';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['feature'][1] = 'Extended layer group with events and popup support. <br>See <a href="http://leafletjs.com/reference.html#featuregroup" target="_blank">http://leafletjs.com/reference.html#featuregroup</a>';

View File

@@ -0,0 +1,80 @@
<?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\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Layer;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
class GroupLayerMapper extends AbstractLayerMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Group\LayerGroup';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'group';
/**
* {@inheritdoc}
*/
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$class = $model->groupType === 'feature'
? 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup'
: static::$definitionClass;
$reflector = new \ReflectionClass($class);
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
return $instance;
}
/**
* {@inheritdoc}
*/
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null
) {
if (!$definition instanceof LayerGroup) {
return;
}
$collection = LayerModel::findBy(
array('pid=?', 'active=1'),
array($model->id),
array('order' => 'sorting')
);
if ($collection) {
foreach ($collection as $layerModel) {
/** @var Layer $layer */
$layer = $mapper->handle($layerModel);
$definition->addLayer($layer);
}
}
}
}