mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2026-03-03 10:38:14 +01:00
Switch to PSR-4.
This commit is contained in:
105
src/Mapper/Layer/TileLayerMapper.php
Normal file
105
src/Mapper/Layer/TileLayerMapper.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package contao-leaflet-maps
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014-2016 netzmacht David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Raster\TileLayer;
|
||||
use Netzmacht\LeafletPHP\Value\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,
|
||||
Filter $filter = null,
|
||||
$elementId = null
|
||||
) {
|
||||
$arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId);
|
||||
|
||||
$arguments[] = $model->tileUrl;
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $filter, $parent);
|
||||
|
||||
/** @var TileLayer $definition */
|
||||
$filter = deserialize($model->bounds);
|
||||
|
||||
if ($filter[0] && $filter[1]) {
|
||||
$filter = array_map(
|
||||
function ($value) {
|
||||
return explode(',', $value, 3);
|
||||
},
|
||||
$filter
|
||||
);
|
||||
|
||||
$filter = LatLngBounds::fromArray($filter);
|
||||
$definition->setBounds($filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user