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

79 lines
1.9 KiB
PHP
Raw Normal View History

2015-01-05 12:25:46 +01:00
<?php
/**
2017-10-05 15:45:43 +02:00
* Leaflet maps for Contao CMS.
*
2016-10-11 10:40:15 +02:00
* @package contao-leaflet-maps
2015-01-05 12:25:46 +01:00
* @author David Molineus <david.molineus@netzmacht.de>
2017-10-11 15:00:48 +02:00
* @copyright 2014-2017 netzmacht David Molineus. All rights reserved.
2017-10-05 15:45:43 +02:00
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
2015-01-05 12:25:46 +01:00
* @filesource
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Contao\Model;
2015-01-05 14:58:37 +01:00
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
2015-01-09 22:33:57 +01:00
use Netzmacht\Contao\Leaflet\Model\ControlModel;
use Netzmacht\Contao\Leaflet\Request\Request;
use Netzmacht\LeafletPHP\Definition\Control\Layers;
2015-01-05 14:58:37 +01:00
2015-01-12 19:03:29 +01:00
/**
* Class LayersControlMapper maps the control model to the layers control definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Control
*/
2015-01-05 12:25:46 +01:00
class LayersControlMapper extends AbstractControlMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = Layers::class;
2015-01-05 12:25:46 +01:00
/**
* 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,
2015-01-09 13:41:09 +01:00
DefinitionMapper $mapper,
Request $request = null,
2015-01-09 13:41:09 +01:00
$elementId = null
) {
$arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId);
2015-01-05 14:58:37 +01:00
$arguments[1] = array();
$arguments[2] = array();
2015-01-09 22:33:57 +01:00
/** @var ControlModel $model */
2015-01-09 23:48:25 +01:00
$collection = $model->findActiveLayers();
2015-01-05 14:58:37 +01:00
if ($collection) {
foreach ($collection as $layer) {
2015-01-09 22:33:57 +01:00
$argument = ($layer->controlMode === 'overlay') ? 2 : 1;
2015-01-05 14:58:37 +01:00
$arguments[$argument][] = $mapper->handle($layer, $request);
2015-01-05 14:58:37 +01:00
}
}
return $arguments;
}
2017-10-11 11:32:25 +02:00
/**
* {@inheritDoc}
*/
protected function initialize()
{
parent::initialize();
2017-10-11 11:35:58 +02:00
$this->optionsBuilder->addOptions(['collapsed', 'autoZIndex']);
2017-10-11 11:32:25 +02:00
}
2015-01-05 12:25:46 +01:00
}