diff --git a/module/config/config.php b/module/config/config.php index 9a94685..1ff685b 100644 --- a/module/config/config.php +++ b/module/config/config.php @@ -98,6 +98,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\MarkersLa $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\GroupLayerMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\VectorsLayerMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\ReferenceLayerMapper'; +$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\OverpassLayerMapper'; $GLOBALS['LEAFLET_MAPPERS'][] = function () { return new \Netzmacht\Contao\Leaflet\Mapper\Layer\MarkerClusterLayerMapper( $GLOBALS['container'][\Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::MAP_ASSETS] diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php index 9c9988c..cc42fd3 100644 --- a/module/dca/tl_leaflet_layer.php +++ b/module/dca/tl_leaflet_layer.php @@ -213,7 +213,20 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'reuseTiles', 'bounds' ) - ) + ), + 'overpass extends default' => array( + 'config' => array( + 'overpassQuery', + 'overpassEndpoint', + 'overpassCallback', + 'minZoom', + ), + '+expert' => array( + 'minZoomIndicatorPosition', + 'minZoomIndicatorMessageNoLayer', + 'minZoomIndicatorMessage', + ), + ), ), 'metasubselectpalettes' => array( @@ -783,5 +796,72 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'eval' => array('maxlength' => 5, 'rgxp' => 'digit', 'tl_class' => 'w50', 'nullIfEmpty' => true), 'sql' => "int(9) NOT NULL default '0'" ), + 'overpassQuery' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['overpassQuery'], + 'exclude' => true, + 'inputType' => 'textarea', + 'eval' => array( + 'preserveTags' => true, + 'decodeEntities' => true, + 'allowHtml' => true, + 'rte' => 'ace', + 'tl_class' => 'clr' + ), + 'sql' => "mediumtext NULL" + ), + 'overpassEndpoint' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['overpassEndpoint'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('tl_class' => 'long'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'overpassCallback' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['overpassCallback'], + 'exclude' => true, + 'inputType' => 'textarea', + 'eval' => array( + 'preserveTags' => true, + 'decodeEntities' => true, + 'allowHtml' => true, + 'rte' => 'ace|javascript', + 'tl_class' => 'clr' + ), + 'sql' => "mediumtext NULL" + ), + 'minZoomIndicatorPosition' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['minZoomIndicatorPosition'], + 'exclude' => true, + 'inputType' => 'select', + 'filter' => true, + 'sorting' => true, + 'options' => array('topleft', 'topright', 'bottomleft', 'bottomright'), + 'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_layer'], + 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50', 'helpwizard' => true), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'minZoomIndicatorMessage' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['minZoomIndicatorMessage'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('tl_class' => 'long'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'minZoomIndicatorMessageNoLayer' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['minZoomIndicatorMessageNoLayer'], + 'exclude' => true, + 'inputType' => 'text', + 'default' => null, + 'eval' => array('tl_class' => 'long'), + 'sql' => "varchar(255) NOT NULL default ''" + ), ) ); diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php new file mode 100644 index 0000000..ca6da15 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/OverpassLayerMapper.php @@ -0,0 +1,74 @@ + + * @copyright 2016 netzmacht David Molineus. All rights reserved. + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Mapper\Layer; + +use Netzmacht\Contao\Leaflet\Filter\Filter; +use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Mapper\OptionsBuilder; +use Netzmacht\JavascriptBuilder\Type\Expression; +use Netzmacht\LeafletPHP\Definition; +use Netzmacht\LeafletPHP\Plugins\OverpassLayer\OverpassLayer; + +/** + * Class OverpassLayerMapper + * + * @package Netzmacht\Contao\Leaflet\Mapper\Layer + */ +class OverpassLayerMapper extends AbstractLayerMapper +{ + /** + * The definition type. + * + * @var string + */ + protected static $type = 'overpass'; + + /** + * {@inheritdoc} + */ + protected function initialize() + { + parent::initialize(); + + $this->optionsBuilder + ->addOption('overpassQuery', 'query') + ->addConditionalOption('minZoom') + ->addConditionalOption('overpassEndpoint', 'endpoint'); + } + + /** + * {@inheritdoc} + */ + protected function build( + Definition $definition, + \Model $model, + DefinitionMapper $mapper, + Filter $filter = null, + Definition $parent = null + ) { + if (!$definition instanceof OverpassLayer) { + return; + } + + $minZoomIndicatorOptions = $definition->getMinZoomIndicatorOptions(); + $minZoomIndicatorOptionsBuilder = new OptionsBuilder(); + $minZoomIndicatorOptionsBuilder + ->addConditionalOption('minZoomIndicatorPosition', 'position') + ->addConditionalOption('minZoomIndicatorMessageNoLayer', 'minZoomMessageNoLayer') + ->addConditionalOption('minZoomIndicatorMessage', 'minZoomMessage'); + + $minZoomIndicatorOptionsBuilder->build($minZoomIndicatorOptions, $model); + + if ($model->overpassCallback) { + $definition->setCallback(new Expression($model->overpassCallback)); + } + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/OptionsBuilder.php b/src/Netzmacht/Contao/Leaflet/Mapper/OptionsBuilder.php index e1e9d17..377e7f0 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/OptionsBuilder.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/OptionsBuilder.php @@ -162,7 +162,7 @@ class OptionsBuilder * * @return void */ - private function buildConditionals(Definition $definition, \Model $model) + private function buildConditionals($definition, \Model $model) { foreach ($this->conditional as $column => $conditions) { foreach ($conditions as $value => $options) {