mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-01 04:24:02 +01:00
78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package contao-leaflet-maps
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
|
* @copyright 2014-2016 netzmacht David Molineus
|
|
* @license LGPL 3.0
|
|
* @filesource
|
|
*
|
|
*/
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
|
|
|
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
|
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;
|
|
|
|
/**
|
|
* Class GroupLayerMapper maps the layer model to the group layer definition.
|
|
*
|
|
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
|
*/
|
|
class GroupLayerMapper extends AbstractLayerMapper
|
|
{
|
|
/**
|
|
* Layer type.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected static $type = 'group';
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null)
|
|
{
|
|
if ($model->groupType === 'feature') {
|
|
return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup';
|
|
}
|
|
|
|
return 'Netzmacht\LeafletPHP\Definition\Group\LayerGroup';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function build(
|
|
Definition $definition,
|
|
\Model $model,
|
|
DefinitionMapper $mapper,
|
|
Filter $filter = null,
|
|
Definition $parent = 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) {
|
|
$layer = $mapper->handle($layerModel);
|
|
|
|
if ($layer instanceof Layer) {
|
|
$definition->addLayer($layer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|