2015-01-22 13:34:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-05 15:45:43 +02:00
|
|
|
* Leaflet maps for Contao CMS.
|
|
|
|
|
*
|
2016-10-11 10:40:15 +02:00
|
|
|
* @package contao-leaflet-maps
|
2015-01-22 13:34:07 +01:00
|
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
2017-10-11 15:00:48 +02:00
|
|
|
* @copyright 2014-2017 netzmacht David Molineus. All rights reserved.
|
2017-10-05 15:45:43 +02:00
|
|
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
|
2015-01-22 13:34:07 +01:00
|
|
|
* @filesource
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
|
|
|
|
|
2017-10-11 14:27:37 +02:00
|
|
|
use Contao\Model;
|
|
|
|
|
use Contao\StringUtil;
|
2015-01-22 13:34:07 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
2017-10-11 14:27:37 +02:00
|
|
|
use Netzmacht\Contao\Leaflet\Request\Request;
|
2015-01-22 13:34:07 +01:00
|
|
|
use Netzmacht\LeafletPHP\Definition;
|
|
|
|
|
use Netzmacht\LeafletPHP\Definition\Raster\TileLayer;
|
2015-01-27 12:41:11 +01:00
|
|
|
use Netzmacht\LeafletPHP\Value\LatLngBounds;
|
2015-01-22 13:34:07 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
2017-10-11 14:27:37 +02:00
|
|
|
Model $model,
|
2015-01-22 13:34:07 +01:00
|
|
|
DefinitionMapper $mapper,
|
2017-10-11 14:27:37 +02:00
|
|
|
Request $request = null,
|
2015-01-22 13:34:07 +01:00
|
|
|
$elementId = null
|
|
|
|
|
) {
|
2017-10-11 14:27:37 +02:00
|
|
|
$arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId);
|
2015-01-22 13:34:07 +01:00
|
|
|
|
|
|
|
|
$arguments[] = $model->tileUrl;
|
|
|
|
|
|
|
|
|
|
return $arguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
protected function build(
|
|
|
|
|
Definition $definition,
|
2017-10-11 14:27:37 +02:00
|
|
|
Model $model,
|
2015-01-22 13:34:07 +01:00
|
|
|
DefinitionMapper $mapper,
|
2017-10-11 14:27:37 +02:00
|
|
|
Request $request = null,
|
2015-01-22 13:34:07 +01:00
|
|
|
Definition $parent = null
|
|
|
|
|
) {
|
2017-10-11 14:27:37 +02:00
|
|
|
parent::build($definition, $model, $mapper, $request, $parent);
|
2015-01-22 13:34:07 +01:00
|
|
|
|
|
|
|
|
/** @var TileLayer $definition */
|
2017-10-11 14:27:37 +02:00
|
|
|
$bounds = StringUtil::deserialize($model->bounds);
|
2015-01-22 13:34:07 +01:00
|
|
|
|
2017-10-11 14:27:37 +02:00
|
|
|
if ($request[0] && $request[1]) {
|
|
|
|
|
$bounds = array_map(
|
2015-01-22 13:34:07 +01:00
|
|
|
function ($value) {
|
|
|
|
|
return explode(',', $value, 3);
|
|
|
|
|
},
|
2017-10-11 14:27:37 +02:00
|
|
|
$bounds
|
2015-01-22 13:34:07 +01:00
|
|
|
);
|
|
|
|
|
|
2017-10-11 14:27:37 +02:00
|
|
|
$bounds = LatLngBounds::fromArray($bounds);
|
|
|
|
|
$definition->setBounds($bounds);
|
2015-01-22 13:34:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|