Files
contao-leaflet-maps/src/Mapper/Vector/RectangleMapper.php

65 lines
1.6 KiB
PHP
Raw Normal View History

2015-01-07 18:58:52 +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-07 18:58:52 +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-07 18:58:52 +01:00
* @filesource
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Contao\Model;
2015-01-07 18:58:52 +01:00
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
2017-10-17 18:03:42 +02:00
use Netzmacht\Contao\Leaflet\Mapper\Request;
use Netzmacht\LeafletPHP\Definition\Vector\Rectangle;
use Netzmacht\LeafletPHP\Value\LatLng;
use Netzmacht\LeafletPHP\Value\LatLngBounds;
2015-01-07 18:58:52 +01:00
2015-01-12 19:03:29 +01:00
/**
* Class RectangleMapper maps a database model to its rectangle vector definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
2015-01-07 18:58:52 +01:00
class RectangleMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = Rectangle::class;
2015-01-07 18:58:52 +01:00
/**
* Layer type.
*
* @var string
*/
protected static $type = 'rectangle';
2015-01-12 19:03:29 +01:00
/**
* {@inheritdoc}
*/
2015-01-09 13:41:09 +01:00
protected function buildConstructArguments(
Model $model,
2015-01-09 13:41:09 +01:00
DefinitionMapper $mapper,
Request $request = null,
2015-01-09 13:41:09 +01:00
$elementId = null
) {
2015-01-07 18:58:52 +01:00
$latLngs = array_map(
2015-01-12 19:03:29 +01:00
function ($latLng) {
2015-01-07 18:58:52 +01:00
return LatLng::fromString($latLng);
},
deserialize($model->bounds, true)
);
$arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId);
2015-01-07 18:58:52 +01:00
$arguments[] = new LatLngBounds($latLngs[0], $latLngs[1]);
return $arguments;
}
}