Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php

74 lines
2.0 KiB
PHP
Raw Normal View History

2015-01-07 17:59:56 +01:00
<?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;
2015-01-09 11:53:58 +01:00
use Netzmacht\Contao\Leaflet\Definition\Style;
use Netzmacht\Contao\Leaflet\Filter\Filter;
2015-01-07 17:59:56 +01:00
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
2015-01-09 11:53:58 +01:00
use Netzmacht\Contao\Leaflet\Model\StyleModel;
use Netzmacht\Contao\Leaflet\ServiceContainerTrait;
2015-01-07 17:59:56 +01:00
use Netzmacht\LeafletPHP\Definition;
2015-01-09 11:53:58 +01:00
use Netzmacht\LeafletPHP\Definition\HasPopup;
use Netzmacht\LeafletPHP\Definition\Vector\Path;
2015-01-07 17:59:56 +01:00
2015-01-12 19:03:29 +01:00
/**
* Class AbstractVectorMapper is the base class for the vector model definition mapping.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
2015-01-07 17:59:56 +01:00
class AbstractVectorMapper extends AbstractTypeMapper
{
use ServiceContainerTrait;
2015-01-07 17:59:56 +01:00
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\VectorModel';
2015-01-09 13:41:09 +01:00
/**
* {@inheritdoc}
*/
protected function build(
2015-01-07 17:59:56 +01:00
Definition $definition,
\Model $model,
2015-01-09 11:53:58 +01:00
DefinitionMapper $mapper,
Filter $filter = null,
2015-01-20 16:38:23 +01:00
Definition $parent = null
2015-01-07 17:59:56 +01:00
) {
parent::build($definition, $model, $mapper, $filter);
2015-01-07 17:59:56 +01:00
2015-01-09 11:53:58 +01:00
if ($definition instanceof Path && $model->style) {
$styleModel = StyleModel::findActiveByPk($model->style);
if ($styleModel) {
$style = $mapper->handle($styleModel);
if ($style instanceof Style) {
$style->apply($definition);
}
}
}
if ($definition instanceof HasPopup && $model->addPopup) {
$content = $this
->getServiceContainer()
->getFrontendValueFilter()
->filter($model->popupContent);
$definition->bindPopup($content);
2015-01-07 17:59:56 +01:00
}
}
}