mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-01 12:33:45 +01:00
Ongoing development.
This commit is contained in:
25
src/Netzmacht/Contao/Leaflet/Dca/Control.php
Normal file
25
src/Netzmacht/Contao/Leaflet/Dca/Control.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\Dca;
|
||||
|
||||
|
||||
class Control
|
||||
{
|
||||
public function generateRow($row)
|
||||
{
|
||||
return sprintf(
|
||||
'%s <span class="tl_gray">[%s]</span>',
|
||||
$row['title'],
|
||||
$row['type']
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,12 @@ namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
class Layer
|
||||
{
|
||||
private $layers;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->layers = &$GLOBALS['LEAFLET_LAYERS'];
|
||||
}
|
||||
public function getVariants($dataContainer)
|
||||
{
|
||||
if ($dataContainer->activeRecord
|
||||
@@ -25,4 +31,49 @@ class Layer
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
// Call paste_button_callback (&$dc, $row, $table, $cr, $childs, $previous, $next)
|
||||
public function getPasteButtons($dataContainer, $row, $table, $whatever, $children)
|
||||
{
|
||||
$pasteAfterUrl = \Controller::addToUrl(
|
||||
'act='.$children['mode'].'&mode=1&pid='.$row['id']
|
||||
.(!is_array($children['id']) ? '&id='.$children['id'] : '')
|
||||
);
|
||||
|
||||
$buffer = sprintf(
|
||||
'<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ',
|
||||
$pasteAfterUrl,
|
||||
specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])),
|
||||
\Image::getHtml(
|
||||
'pasteafter.gif',
|
||||
sprintf($GLOBALS['TL_LANG'][$table]['pasteafter'][1], $row['id'])
|
||||
)
|
||||
);
|
||||
|
||||
if (!empty($this->layers[$row['type']]['children'])) {
|
||||
$pasteIntoUrl = \Controller::addToUrl(
|
||||
sprintf(
|
||||
'act=%s&mode=2&pid=%s%s',
|
||||
$children['mode'],
|
||||
$row['id'],
|
||||
!is_array($children['id']) ? '&id='.$children['id'] : ''
|
||||
)
|
||||
);
|
||||
|
||||
$buffer .= sprintf(
|
||||
'<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ',
|
||||
$pasteIntoUrl,
|
||||
specialchars(sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])),
|
||||
\Image::getHtml(
|
||||
'pasteinto.gif',
|
||||
sprintf($GLOBALS['TL_LANG'][$table]['pasteinto'][1], $row['id'])
|
||||
)
|
||||
);
|
||||
|
||||
} elseif ($row['id'] > 0) {
|
||||
$buffer .= \Image::getHtml('pasteinto_.gif');
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ use Netzmacht\LeafletPHP\Definition;
|
||||
*/
|
||||
abstract class AbstractMapper implements Mapper
|
||||
{
|
||||
const VALUE_NOT_EMPTY = '__value_not_empty__';
|
||||
const VALUE_EMPTY = '__value_empty__';
|
||||
|
||||
/**
|
||||
* Class of the model being build.
|
||||
*
|
||||
@@ -109,8 +112,10 @@ abstract class AbstractMapper implements Mapper
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addConditionalOption($column, $option, $mapping = null, $value = '1')
|
||||
public function addConditionalOption($column, $option = null, $mapping = null, $value = self::VALUE_NOT_EMPTY)
|
||||
{
|
||||
$option = $option ?: $column;
|
||||
|
||||
if (!isset($this->conditional[$column][$value][$option])) {
|
||||
$this->conditional[$column][$value][$option] = $this->getMapping($option, $mapping);
|
||||
}
|
||||
@@ -127,7 +132,7 @@ abstract class AbstractMapper implements Mapper
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addConditionalOptions($column, array $options, $value = '1')
|
||||
public function addConditionalOptions($column, array $options, $value = self::VALUE_NOT_EMPTY)
|
||||
{
|
||||
foreach ($options as $key => $option) {
|
||||
if (is_numeric($key)) {
|
||||
@@ -214,7 +219,7 @@ abstract class AbstractMapper implements Mapper
|
||||
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
|
||||
{
|
||||
return array(
|
||||
$model->alias ?: $model->id
|
||||
$model->alias ?: (str_replace('tl_leaflet_', '', $model->getTable()) . '_' . $model->id)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -243,7 +248,11 @@ abstract class AbstractMapper implements Mapper
|
||||
{
|
||||
foreach ($this->conditional as $column => $conditions) {
|
||||
foreach ($conditions as $value => $options) {
|
||||
if ($model->$column == $value) {
|
||||
if ($value === static::VALUE_EMPTY && empty($model->$column)) {
|
||||
$this->applyOptions($options, $definition, $model);
|
||||
} elseif ($value === static::VALUE_NOT_EMPTY && !empty($model->$column)) {
|
||||
$this->applyOptions($options, $definition, $model);
|
||||
} elseif ($model->$column == $value) {
|
||||
$this->applyOptions($options, $definition, $model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper;
|
||||
|
||||
|
||||
abstract class AbstractLayerMapper extends AbstractMapper
|
||||
abstract class AbstractTypeMapper extends AbstractMapper
|
||||
{
|
||||
protected static $type;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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\Control;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
|
||||
class AbstractControlMapper extends AbstractTypeMapper
|
||||
{
|
||||
/**
|
||||
* Class of the model being build.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\ControlModel';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
$this->addOption('position');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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\Control;
|
||||
|
||||
|
||||
class LayersControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
* Class of the definition being created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Control\Layers';
|
||||
|
||||
/**
|
||||
* Layer type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'layers';
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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\Control;
|
||||
|
||||
/**
|
||||
* Class ScaleControlMapper maps the database item of the type "scale" to the scale control.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Control
|
||||
*/
|
||||
class ScaleControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
* Class of the definition being created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Control\Scale';
|
||||
|
||||
/**
|
||||
* Layer type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'scale';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->addOptions('maxWidth', 'metric', 'imperial', 'updateWhenIdle');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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\Control;
|
||||
|
||||
/**
|
||||
* Class ZoomControlMapper maps the zoom database definition to the zoom control.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Control
|
||||
*/
|
||||
class ZoomControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
* Class of the definition being created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Control\Zoom';
|
||||
|
||||
/**
|
||||
* Layer type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'zoom';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this
|
||||
->addConditionalOption('zoomInText')
|
||||
->addConditionalOption('zoomOutText')
|
||||
->addConditionalOption('zoomInTitle')
|
||||
->addConditionalOption('zoomOutTitle');
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,11 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractLayerMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
|
||||
class ProviderLayerMapper extends AbstractLayerMapper
|
||||
class ProviderLayerMapper extends AbstractTypeMapper
|
||||
{
|
||||
/**
|
||||
* Class of the model being build.
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
@@ -93,6 +94,18 @@ class MapMapper extends AbstractMapper
|
||||
*/
|
||||
private function buildControls(Map $map, MapModel$model, DefinitionMapper $mapper)
|
||||
{
|
||||
$collection = ControlModel::findBy(
|
||||
array('pid=?', 'active=1'),
|
||||
array($model->id),
|
||||
array('order' => 'sorting')
|
||||
);
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $control) {
|
||||
$control = $mapper->handle($control);
|
||||
$map->addControl($control);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
17
src/Netzmacht/Contao/Leaflet/Model/ControlModel.php
Normal file
17
src/Netzmacht/Contao/Leaflet/Model/ControlModel.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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 ControlModel extends \Model
|
||||
{
|
||||
protected static $strTable = 'tl_leaflet_control';
|
||||
}
|
||||
@@ -47,8 +47,9 @@ class EncoderSubscriber implements EventSubscriberInterface
|
||||
|
||||
if ($object instanceof Map) {
|
||||
$attribution = <<<HTML
|
||||
map.map.attributionControl.addAttribution(
|
||||
'<a href="http://www.netzmacht.de/contao-leaflet">netzmacht <em>creative</em></a>'
|
||||
map.map.attributionControl.setPrefix(
|
||||
'<a href="http://www.leafletjs.com" title="A JS library for interactive maps">Leaflet</a> | ' +
|
||||
'<a href="http://www.netzmacht.de/contao-leaflet" title="Leaflet extension for Contao CMS">netzmacht <em>creative</em></a>'
|
||||
);
|
||||
HTML;
|
||||
$event->getOutput()->addLine($attribution);
|
||||
|
||||
Reference in New Issue
Block a user