diff --git a/module/config/leaflet_providers.php b/module/config/leaflet_providers.php new file mode 100644 index 0000000..d1764de --- /dev/null +++ b/module/config/leaflet_providers.php @@ -0,0 +1,127 @@ + 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' + ) + ) +); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractLayerMapper.php new file mode 100644 index 0000000..875c587 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractLayerMapper.php @@ -0,0 +1,23 @@ + + * @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; + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php index 04f9da8..0713928 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php @@ -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); + $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); } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php new file mode 100644 index 0000000..6636b52 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/ProviderLayerMapper.php @@ -0,0 +1,103 @@ + + * @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 + ); + } +}