Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Mapper/Vector/PolylineMapper.php
2015-01-20 16:38:23 +01:00

63 lines
1.5 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\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
/**
* Class PolylineMapper maps the database model to the polyline definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class PolylineMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polyline';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'polyline';
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null,
Definition $parent = null
) {
parent::build($definition, $model, $mapper, $bounds);
if ($definition instanceof Polyline) {
array_map(
function ($row) use ($definition) {
$definition->addLatLng(LatLng::fromString($row));
},
explode("\n", $model->data)
);
}
}
}