Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Mapper/Control/LayersControlMapper.php

83 lines
2.0 KiB
PHP
Raw Normal View History

2015-01-05 12:25:46 +01:00
<?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;
2015-01-05 14:58:37 +01:00
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
2015-01-06 14:55:53 +01:00
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
2015-01-05 14:58:37 +01:00
2015-01-05 12:25:46 +01:00
class LayersControlMapper extends AbstractControlMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Control\Layers';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'layers';
2015-01-05 14:58:37 +01:00
2015-01-09 13:41:09 +01:00
/**
* {@inheritdoc}
*/
protected function buildConstructArguments(
\Model $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null,
$elementId = null
) {
$arguments = parent::buildConstructArguments($model, $mapper, $bounds, $elementId);
2015-01-05 14:58:37 +01:00
$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;
2015-01-06 14:55:53 +01:00
$arguments[$argument][] = $mapper->handle($layer, $bounds);
2015-01-05 14:58:37 +01:00
}
}
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;
}
2015-01-05 12:25:46 +01:00
}