From 150e3706ed0679a171316f3040e8010f1d96ba26 Mon Sep 17 00:00:00 2001 From: David Molineus Date: Fri, 9 Jan 2015 16:10:17 +0100 Subject: [PATCH] Support pointToLayer and onEachFeature customization. --- assets/libs/contao/contao-leaflet.js | 6 ++++ module/dca/tl_leaflet_layer.php | 31 +++++++++++++++++++ module/languages/en/tl_leaflet_layer.php | 7 ++++- .../Mapper/Layer/MarkersLayerMapper.php | 5 ++- .../Mapper/Layer/VectorsLayerMapper.php | 9 ++++-- 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/assets/libs/contao/contao-leaflet.js b/assets/libs/contao/contao-leaflet.js index 85b31d0..33d1595 100644 --- a/assets/libs/contao/contao-leaflet.js +++ b/assets/libs/contao/contao-leaflet.js @@ -36,6 +36,12 @@ L.Contao = L.Class.extend({ } }); }); + + // Set default pointToLayer and onEachFeature handler. + L.GeoJSON.AJAX.prototype.options = L.Util.extend({}, L.GeoJSON.AJAX.prototype.options, { + pointToLayer: this.pointToLayer.bind(this), + onEachFeature: this.onEachFeature.bind(this) + }); }, /** diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php index a7636a6..5d07629 100644 --- a/module/dca/tl_leaflet_layer.php +++ b/module/dca/tl_leaflet_layer.php @@ -124,16 +124,19 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array 'metapalettes' => array( 'default' => array( 'title' => array('title', 'alias', 'type'), + 'expert' => array(':hide'), 'active' => array('active'), ), 'markers extends default' => array( '+title' => array('markerCluster'), + '+expert' => array('pointToLayer'), '+active' => array('deferred') ), 'group extends default' => array( '+title' => array('groupType'), ), 'vectors extends default' => array( + '+expert' => array('onEachFeature', 'pointToLayer'), '+active' => array('deferred'), ), 'reference extends default' => array( @@ -311,5 +314,33 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array ), 'sql' => "int(10) unsigned NOT NULL default '0'", ), + 'onEachFeature' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['onEachFeature'], + 'exclude' => true, + 'inputType' => 'textarea', + 'eval' => array( + 'preserveTags' => true, + 'decodeEntities' => true, + 'allowHtml' => true, + 'rte' => 'ace|javascript', + 'tl_class' => 'clr' + ), + 'sql' => "mediumtext NULL" + ), + 'pointToLayer' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['pointToLayer'], + 'exclude' => true, + 'inputType' => 'textarea', + 'eval' => array( + 'preserveTags' => true, + 'decodeEntities' => true, + 'allowHtml' => true, + 'rte' => 'ace|javascript', + 'tl_class' => 'clr' + ), + 'sql' => "mediumtext NULL" + ), ) ); diff --git a/module/languages/en/tl_leaflet_layer.php b/module/languages/en/tl_leaflet_layer.php index 91f1263..94b81c5 100644 --- a/module/languages/en/tl_leaflet_layer.php +++ b/module/languages/en/tl_leaflet_layer.php @@ -1,7 +1,8 @@ See http://leafletjs.com/reference.html#layergroup'; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php index 27a244b..8893b95 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/MarkersLayerMapper.php @@ -22,6 +22,7 @@ use Netzmacht\LeafletPHP\Definition\Group\GeoJson; use Netzmacht\LeafletPHP\Definition\Group\LayerGroup; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax; +use PhpSpec\Exception\Exception; class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper { @@ -73,7 +74,9 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper } if ($definition instanceof GeoJson) { - $definition->setPointToLayer(new Expression('ContaoLeaflet.pointToLayer.bind(ContaoLeaflet)')); + if ($model->pointToLayer) { + $definition->setPointToLayer(new Expression($model->pointToLayer)); + } } } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php index 6593f5a..29c34cb 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Layer/VectorsLayerMapper.php @@ -74,8 +74,13 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper } if ($definition instanceof GeoJson) { - $definition->setOnEachFeature(new Expression('ContaoLeaflet.onEachFeature.bind(ContaoLeaflet)')); - $definition->setPointToLayer(new Expression('ContaoLeaflet.pointToLayer.bind(ContaoLeaflet)')); + if ($model->pointToLayer) { + $definition->setPointToLayer(new Expression($model->pointToLayer)); + } + + if ($model->onEachFeature) { + $definition->setOnEachFeature(new Expression($model->onEachFeature)); + } } }