mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 19:13:55 +01:00
Add providers plugin.
This commit is contained in:
127
module/config/leaflet_providers.php
Normal file
127
module/config/leaflet_providers.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Support all providers and variants which are supported by leaflet-providers.
|
||||
* See https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js
|
||||
*/
|
||||
|
||||
$GLOBALS['LEAFLET_TILE_PROVIDERS'] = array
|
||||
(
|
||||
'OpenStreetMap' => array
|
||||
(
|
||||
'variants' => array('Mapnik', 'BlackAndWhite', 'DE', 'HOT'),
|
||||
),
|
||||
'OpenSeaMap' => array(),
|
||||
'Thunderforest' => array
|
||||
(
|
||||
'variants' => array('OpenCycleMap', 'Transport', 'Landscape', 'Outdoors')
|
||||
),
|
||||
'OpenMapSurfer' => array
|
||||
(
|
||||
'variants' => array('Roads', 'AdminBounds', 'Grayscale')
|
||||
),
|
||||
'Hydda' => array(
|
||||
'variants' => array('Full', 'Base', 'RoadsAndLabels')
|
||||
),
|
||||
'MapQuestOpen' => array(
|
||||
'variants' => array('OSM', 'Aerial')
|
||||
),
|
||||
'MaxBox' => array(
|
||||
'class' => 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\MapBoxProvider',
|
||||
'options' => array(
|
||||
'key' => 'tile_provider_key'
|
||||
),
|
||||
),
|
||||
'Stamen' => array(
|
||||
'variants' => array(
|
||||
'Toner',
|
||||
'TonerBackground',
|
||||
'TonerHybrid',
|
||||
'TonerLines',
|
||||
'TonerLabels',
|
||||
'TonerLite',
|
||||
'Terrain',
|
||||
'TerrainBackground',
|
||||
'Watercolor'
|
||||
)
|
||||
),
|
||||
'Esri' => array(
|
||||
'variants' => array(
|
||||
'WorldStreetMap',
|
||||
'DeLorme',
|
||||
'WorldTopoMap',
|
||||
'WorldImagery',
|
||||
'WorldTerrain',
|
||||
'WorldShadedRelief',
|
||||
'WorldPhysical',
|
||||
'OceanBasemap',
|
||||
'NatGeoWorldMap',
|
||||
'WorldGrayCanvas'
|
||||
)
|
||||
),
|
||||
'OpenWeatherMap' => array(
|
||||
'variants' => array(
|
||||
'Clouds',
|
||||
'CloudsClassic',
|
||||
'Precipitation',
|
||||
'PrecipitationClassic',
|
||||
'Rain',
|
||||
'RainClassic',
|
||||
'Pressure',
|
||||
'PressureContour',
|
||||
'Wind',
|
||||
'Temperature',
|
||||
'Snow'
|
||||
)
|
||||
),
|
||||
'HERE' => array(
|
||||
'variants' => array(
|
||||
'normalDay',
|
||||
'normalDayCustom',
|
||||
'normalDayGrey',
|
||||
'normalDayMobile',
|
||||
'normalDayGreyMobile',
|
||||
'normalDayTransit',
|
||||
'normalDayTransitMobile',
|
||||
'normalNight',
|
||||
'normalNightMobile',
|
||||
'normalNightGrey',
|
||||
'normalNightGreyMobile',
|
||||
'carnavDayGrey',
|
||||
'hybridDay',
|
||||
'hybridDayMobile',
|
||||
'pedestrianDay',
|
||||
'pedestrianNight',
|
||||
'satelliteDay',
|
||||
'terrainDay',
|
||||
'terrainDayMobile',
|
||||
),
|
||||
'options' => array(
|
||||
'appId' => 'tile_provider_key',
|
||||
'appCode' => 'tile_provider_code',
|
||||
),
|
||||
'fields' => array('tile_provider_key', 'tile_provider_code'),
|
||||
'class' => 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\HereProvider',
|
||||
),
|
||||
'Acetate' => array(
|
||||
'variants' => array(
|
||||
'basemap',
|
||||
'terrain',
|
||||
'all',
|
||||
'foreground',
|
||||
'roads',
|
||||
'labels',
|
||||
'hillshading',
|
||||
)
|
||||
),
|
||||
'FreeMapSK' => array(),
|
||||
'MtbMap' => array(),
|
||||
'CartoDB' => array(
|
||||
'variants' => array(
|
||||
'Positron',
|
||||
'PositronNoLabels',
|
||||
'DarkMatter',
|
||||
'DarkMatterNoLabels'
|
||||
)
|
||||
)
|
||||
);
|
||||
23
src/Netzmacht/Contao/Leaflet/Mapper/AbstractLayerMapper.php
Normal file
23
src/Netzmacht/Contao/Leaflet/Mapper/AbstractLayerMapper.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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;
|
||||
|
||||
|
||||
abstract class AbstractLayerMapper extends AbstractMapper
|
||||
{
|
||||
protected static $type;
|
||||
|
||||
public function match(\Model $model)
|
||||
{
|
||||
return parent::match($model) && $model->type === static::$type;
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,10 @@ abstract class AbstractMapper implements Mapper
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function initialize();
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Use for specific build methods.
|
||||
@@ -271,12 +274,18 @@ abstract class AbstractMapper implements Mapper
|
||||
* @param Definition $definition The definition being built.
|
||||
* @param \Model $model The model.
|
||||
*/
|
||||
private function applyOptions($options, $definition, $model)
|
||||
protected function applyOptions($options, $definition, $model)
|
||||
{
|
||||
foreach ($options as $option => $mapping) {
|
||||
$setter = 'set' . ucfirst($option);
|
||||
$default = $this->getDefaultOption($option, $definition);
|
||||
|
||||
if ($model->$option != $this->getDefaultOption($option, $definition)) {
|
||||
if ($model->$mapping === '1' || $model->$mapping === '') {
|
||||
if (((bool) $model->$option) !== $default) {
|
||||
$definition->$setter($model->$mapping);
|
||||
}
|
||||
}
|
||||
elseif ($model->$mapping !== $default) {
|
||||
$definition->$setter($model->$mapping);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?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\AbstractLayerMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
|
||||
class ProviderLayerMapper extends AbstractLayerMapper
|
||||
{
|
||||
/**
|
||||
* Class of the model being build.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
protected function createInstance(\Model $model, DefinitionMapper $mapper)
|
||||
{
|
||||
if (isset($this->providers[$model->tile_provider]['class'])) {
|
||||
$class = $this->providers[$model->tile_provider]['class'];
|
||||
} else {
|
||||
$class = static::$definitionClass;
|
||||
}
|
||||
|
||||
$reflector = new \ReflectionClass($class);
|
||||
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper));
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
|
||||
{
|
||||
if (!empty($this->providers[$model->tile_provider]['options'])) {
|
||||
$this->applyOptions(
|
||||
$this->providers[$model->tile_provider]['options'],
|
||||
$definition,
|
||||
$model
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
|
||||
{
|
||||
return array(
|
||||
$model->alias ?: ('layer_' . $model->id),
|
||||
$model->tile_provider,
|
||||
$model->tile_provider_variant ?: null
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user