Files
contao-leaflet-maps/src/Mapper/Layer/ProviderLayerMapper.php

101 lines
2.4 KiB
PHP
Raw Normal View History

2014-12-29 16:19:43 +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
2014-12-29 16:19:43 +01:00
* @author David Molineus <david.molineus@netzmacht.de>
2017-10-05 15:45:43 +02:00
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
2014-12-29 16:19:43 +01:00
* @filesource
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Contao\Model;
2014-12-29 16:19:43 +01:00
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Request\Request;
2014-12-29 16:19:43 +01:00
use Netzmacht\LeafletPHP\Definition;
2015-01-12 19:03:29 +01:00
/**
* Class ProviderLayerMapper maps the layer model to the tile provider definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
2015-01-06 14:55:53 +01:00
class ProviderLayerMapper extends AbstractLayerMapper
2014-12-29 16:19:43 +01:00
{
/**
* Layer type.
*
* @var string
*/
protected static $type = 'provider';
/**
* Registered providers.
*
* @var array
*/
private $providers;
/**
* Construct.
*
* @param array $providers Registered providers.
2014-12-29 16:19:43 +01:00
*/
public function __construct(array $providers)
2014-12-29 16:19:43 +01:00
{
$this->providers = $providers;
2014-12-29 16:19:43 +01:00
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function getClassName(Model $model, DefinitionMapper $mapper, Request $request = null)
2014-12-29 16:19:43 +01:00
{
if (isset($this->providers[$model->tile_provider]['class'])) {
return $this->providers[$model->tile_provider]['class'];
2014-12-29 16:19:43 +01:00
}
2015-01-22 11:59:19 +01:00
return 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\Provider';
2014-12-29 16:19:43 +01:00
}
/**
* {@inheritdoc}
*/
2015-01-09 13:41:09 +01:00
protected function build(
Definition $definition,
Model $model,
2015-01-20 16:38:23 +01:00
DefinitionMapper $mapper,
Request $request = null,
2015-01-20 16:38:23 +01:00
Definition $parent = null
2015-01-09 13:41:09 +01:00
) {
2014-12-29 16:19:43 +01:00
if (!empty($this->providers[$model->tile_provider]['options'])) {
OptionsBuilder::applyOptions(
2014-12-29 16:19:43 +01:00
$this->providers[$model->tile_provider]['options'],
$definition,
$model
);
}
}
/**
* {@inheritdoc}
*/
2015-01-09 13:41:09 +01:00
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
) {
2014-12-29 16:19:43 +01:00
return array(
$model->alias ?: ('layer_' . $model->id),
$model->tile_provider,
$model->tile_provider_variant ?: null
);
}
}