2014-12-29 16:19:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package dev
|
|
|
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
|
|
|
|
* @copyright 2014 netzmacht creative David Molineus
|
|
|
|
|
* @license LGPL 3.0
|
|
|
|
|
* @filesource
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
|
|
|
|
|
|
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
|
|
|
|
use Netzmacht\LeafletPHP\Definition;
|
2015-01-06 14:55:53 +01:00
|
|
|
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
2014-12-29 16:19:43 +01:00
|
|
|
|
2015-01-06 14:55:53 +01:00
|
|
|
class ProviderLayerMapper extends AbstractLayerMapper
|
2014-12-29 16:19:43 +01:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Class of the definition being created.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected static $definitionClass = 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\Provider';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Layer type.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected static $type = 'provider';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Registered providers.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
private $providers;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct.
|
|
|
|
|
*
|
|
|
|
|
* @SuppressWarnings(PHPMD.Superglobals)
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->providers = &$GLOBALS['LEAFLET_TILE_PROVIDERS'];
|
|
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2015-01-06 14:55:53 +01:00
|
|
|
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
2014-12-29 16:19:43 +01:00
|
|
|
{
|
|
|
|
|
if (isset($this->providers[$model->tile_provider]['class'])) {
|
|
|
|
|
$class = $this->providers[$model->tile_provider]['class'];
|
|
|
|
|
} else {
|
|
|
|
|
$class = static::$definitionClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$reflector = new \ReflectionClass($class);
|
2015-01-06 14:55:53 +01:00
|
|
|
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
|
2014-12-29 16:19:43 +01:00
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2015-01-08 09:51:43 +01:00
|
|
|
protected function build(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
|
2014-12-29 16:19:43 +01:00
|
|
|
{
|
|
|
|
|
if (!empty($this->providers[$model->tile_provider]['options'])) {
|
|
|
|
|
$this->applyOptions(
|
|
|
|
|
$this->providers[$model->tile_provider]['options'],
|
|
|
|
|
$definition,
|
|
|
|
|
$model
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2015-01-06 14:55:53 +01:00
|
|
|
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
2014-12-29 16:19:43 +01:00
|
|
|
{
|
|
|
|
|
return array(
|
|
|
|
|
$model->alias ?: ('layer_' . $model->id),
|
|
|
|
|
$model->tile_provider,
|
|
|
|
|
$model->tile_provider_variant ?: null
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|