mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 20:13:49 +01:00
Implement the tile layer (Close #3).
This commit is contained in:
104
src/Netzmacht/Contao/Leaflet/Mapper/Layer/TileLayerMapper.php
Normal file
104
src/Netzmacht/Contao/Leaflet/Mapper/Layer/TileLayerMapper.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user