mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-02 13:03:43 +01:00
105 lines
2.7 KiB
PHP
105 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @package dev
|
||
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
||
|
|
* @copyright 2015 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;
|
||
|
|
use Netzmacht\LeafletPHP\Definition\Raster\TileLayer;
|
||
|
|
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Class TileLayerMapper maps the database model to the tile layer definition.
|
||
|
|
*
|
||
|
|
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||
|
|
*/
|
||
|
|
class TileLayerMapper extends AbstractLayerMapper
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The definition class.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Raster\TileLayer';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The layer type.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected static $type = 'tile';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* {@inheritdoc}
|
||
|
|
*/
|
||
|
|
protected function initialize()
|
||
|
|
{
|
||
|
|
parent::initialize();
|
||
|
|
|
||
|
|
$this->optionsBuilder
|
||
|
|
->addConditionalOption('minZoom')
|
||
|
|
->addConditionalOption('maxZoom')
|
||
|
|
->addConditionalOption('maxNativeZoom')
|
||
|
|
->addConditionalOption('tileSize')
|
||
|
|
->addConditionalOption('subdomain')
|
||
|
|
->addConditionalOption('errorTileUrl')
|
||
|
|
->addOptions('attribution', 'tms', 'continuousWorld', 'noWrap', 'zoomReverse')
|
||
|
|
->addConditionalOption('zoomOffset')
|
||
|
|
->addConditionalOption('opacity')
|
||
|
|
->addOption('zIndex')
|
||
|
|
->addOptions('unloadvisibleTiles', 'updateWhenIdle', 'detectRetina', 'reuseTiles');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* {@inheritdoc}
|
||
|
|
*/
|
||
|
|
protected function buildConstructArguments(
|
||
|
|
\Model $model,
|
||
|
|
DefinitionMapper $mapper,
|
||
|
|
LatLngBounds $bounds = null,
|
||
|
|
$elementId = null
|
||
|
|
) {
|
||
|
|
$arguments = parent::buildConstructArguments($model, $mapper, $bounds, $elementId);
|
||
|
|
|
||
|
|
$arguments[] = $model->tileUrl;
|
||
|
|
|
||
|
|
return $arguments;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* {@inheritdoc}
|
||
|
|
*/
|
||
|
|
protected function build(
|
||
|
|
Definition $definition,
|
||
|
|
\Model $model,
|
||
|
|
DefinitionMapper $mapper,
|
||
|
|
LatLngBounds $bounds = null,
|
||
|
|
Definition $parent = null
|
||
|
|
) {
|
||
|
|
parent::build($definition, $model, $mapper, $bounds, $parent);
|
||
|
|
|
||
|
|
/** @var TileLayer $definition */
|
||
|
|
$bounds = deserialize($model->bounds);
|
||
|
|
|
||
|
|
if ($bounds[0] && $bounds[1]) {
|
||
|
|
$bounds = array_map(
|
||
|
|
function ($value) {
|
||
|
|
return explode(',', $value, 3);
|
||
|
|
},
|
||
|
|
$bounds
|
||
|
|
);
|
||
|
|
|
||
|
|
$bounds = LatLngBounds::fromArray($bounds);
|
||
|
|
$definition->setBounds($bounds);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|