Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Mapper/UI/MarkerMapper.php

101 lines
2.6 KiB
PHP
Raw Normal View History

2015-01-06 18:49:22 +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\UI;
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
2015-01-06 21:30:57 +01:00
use Netzmacht\Contao\Leaflet\Model\IconModel;
2015-01-06 18:49:22 +01:00
use Netzmacht\LeafletPHP\Definition;
2015-01-08 15:21:45 +01:00
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
2015-01-06 18:49:22 +01:00
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker;
2015-01-12 19:03:29 +01:00
/**
* Class MarkerMapper maps the marker model to the marker definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\UI
*/
2015-01-06 18:49:22 +01:00
class MarkerMapper extends AbstractMapper
{
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\MarkerModel';
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\UI\Marker';
/**
* {@inheritdoc}
*/
2015-01-09 13:41:09 +01:00
protected function buildConstructArguments(
\Model $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null,
$elementId = null
) {
$arguments = parent::buildConstructArguments($model, $mapper, $bounds, $elementId);
2015-01-06 18:49:22 +01:00
$arguments[] = $model->coordinates ?: null;
return $arguments;
}
/**
* {@inheritdoc}
*/
protected function initialize()
{
$this
->addConditionalOption('tooltip', 'title', 'tooltip')
->addConditionalOption('alt')
2015-01-08 16:27:55 +01:00
->addConditionalOption('zIndexOffset')
2015-01-06 18:49:22 +01:00
->addOptions('clickable', 'keyboard', 'draggable');
}
/**
* {@inheritdoc}
*/
protected function build(
2015-01-06 18:49:22 +01:00
Definition $definition,
\Model $model,
2015-01-20 16:38:23 +01:00
DefinitionMapper $mapper,
LatLngBounds $bounds = null,
Definition $parent = null
2015-01-06 18:49:22 +01:00
) {
if ($definition instanceof Marker) {
if ($model->addPopup) {
$definition->bindPopup($model->popupContent);
}
2015-01-06 21:30:57 +01:00
if ($model->customIcon) {
$iconModel = IconModel::findBy(
array('id=?', 'active=1'),
array($model->icon),
array('return' => 'Model')
);
if ($iconModel) {
2015-01-08 15:21:45 +01:00
/** @var ImageIcon $icon */
2015-01-20 16:38:23 +01:00
$icon = $mapper->handle($iconModel);
2015-01-06 21:30:57 +01:00
$definition->setIcon($icon);
}
}
2015-01-06 18:49:22 +01:00
}
}
}