mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 20:13:49 +01:00
Add popup support.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\PopupModel;
|
||||
|
||||
/**
|
||||
* Class Marker is the dca helper class for the tl_leaflet_marker dca.
|
||||
@@ -52,6 +53,19 @@ class Marker
|
||||
return $builder->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all popups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPopups()
|
||||
{
|
||||
$collection = PopupModel::findAll(array('order' => 'title'));
|
||||
$builder = OptionsBuilder::fromCollection($collection, 'id', 'title');
|
||||
|
||||
return $builder->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the coordinates.
|
||||
*
|
||||
|
||||
@@ -15,10 +15,12 @@ use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\PopupModel;
|
||||
use Netzmacht\Contao\Leaflet\ServiceContainerTrait;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Popup;
|
||||
|
||||
/**
|
||||
* Class MarkerMapper maps the marker model to the marker definition.
|
||||
@@ -53,7 +55,7 @@ class MarkerMapper extends AbstractMapper
|
||||
$elementId = null
|
||||
) {
|
||||
$arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId);
|
||||
$arguments[] = $model->coordinates ?: null;
|
||||
$arguments[] = array($model->latitude, $model->longitude, $model->altitude ?: null) ?: null;
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
@@ -82,12 +84,25 @@ class MarkerMapper extends AbstractMapper
|
||||
) {
|
||||
if ($definition instanceof Marker) {
|
||||
if ($model->addPopup) {
|
||||
$popup = null;
|
||||
$content = $this
|
||||
->getServiceContainer()
|
||||
->getFrontendValueFilter()
|
||||
->filter($model->popupContent);
|
||||
|
||||
$definition->bindPopup($content);
|
||||
if ($model->popup) {
|
||||
$popupModel = PopupModel::findActiveByPK($model->popup);
|
||||
|
||||
if ($popupModel) {
|
||||
$popup = $mapper->handle($popupModel, $filter, null, $definition);
|
||||
}
|
||||
}
|
||||
|
||||
if ($popup instanceof Popup) {
|
||||
$definition->bindPopup($content, $popup->getOptions());
|
||||
} else {
|
||||
$definition->bindPopup($content);
|
||||
}
|
||||
}
|
||||
|
||||
if ($model->customIcon) {
|
||||
|
||||
117
src/Netzmacht/Contao/Leaflet/Mapper/UI/PopupMapper.php
Normal file
117
src/Netzmacht/Contao/Leaflet/Mapper/UI/PopupMapper.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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\Filter\Filter;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\PopupModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Popup;
|
||||
|
||||
/**
|
||||
* Class PopupMapper.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\UI
|
||||
*/
|
||||
class PopupMapper extends AbstractMapper
|
||||
{
|
||||
/**
|
||||
* The definition class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\UI\Popup';
|
||||
|
||||
/**
|
||||
* The model class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\PopupModel';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->optionsBuilder
|
||||
->addConditionalOption('maxWidth')
|
||||
->addConditionalOption('minWidth')
|
||||
->addConditionalOption('maxHeight')
|
||||
->addConditionalOption('className')
|
||||
->addOptions('autoPan', 'keepInView', 'closeButton', 'zoomAnimation');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
Filter $filter = null,
|
||||
Definition $parent = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $filter, $parent);
|
||||
|
||||
/** @var Popup $definition */
|
||||
/** @var PopupModel $model */
|
||||
|
||||
$this->deserializePoint('offset', $definition, $model);
|
||||
|
||||
if ($model->autoPan) {
|
||||
$padding = array_map(
|
||||
function ($value) {
|
||||
return array_map('intval', trimsplit(',', $value));
|
||||
},
|
||||
deserialize($model->autoPanPadding, true)
|
||||
);
|
||||
|
||||
if ($padding[0] === $padding[1]) {
|
||||
$definition->setAutoPanPadding($padding[0]);
|
||||
} else {
|
||||
if ($padding[0]) {
|
||||
$definition->setAutoPanPaddingTopLeft($padding[0]);
|
||||
}
|
||||
if ($padding[1]) {
|
||||
$definition->setAutoPanPaddingBottomRight($padding[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$model->closeOnClick) {
|
||||
$definition->setCloseOnClick(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize point value and add it as option.
|
||||
*
|
||||
* @param string $option The option name.
|
||||
* @param Popup $definition The popup definition.
|
||||
* @param PopupModel $model The popup model.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function deserializePoint($option, Popup $definition, PopupModel $model)
|
||||
{
|
||||
if ($model->$option) {
|
||||
$setter = 'set' . ucfirst($option);
|
||||
$definition->$setter(array_map('intval', explode(',', $model->$option, 2)));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
29
src/Netzmacht/Contao/Leaflet/Model/PopupModel.php
Normal file
29
src/Netzmacht/Contao/Leaflet/Model/PopupModel.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Model;
|
||||
|
||||
/**
|
||||
* Class PopupModel.
|
||||
*
|
||||
* @property mixed|null offset
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class PopupModel extends AbstractActiveModel
|
||||
{
|
||||
/**
|
||||
* The table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_popup';
|
||||
}
|
||||
@@ -63,6 +63,10 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
||||
if ($definition->getPopupContent()) {
|
||||
$feature->setProperty('popupContent', $definition->getPopupContent());
|
||||
}
|
||||
|
||||
if ($definition->getPopupOptions()) {
|
||||
$feature->setProperty('popupOptions', $definition->getPopupOptions());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user