mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 19:13:55 +01:00
Support pointToLayer and onEachFeature customization.
This commit is contained in:
@@ -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)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -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"
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['title_legend'] = 'Layer';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['title_legend'] = 'Layer';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['active_legend'] = 'Activation';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['expert_legend'] = 'Expert settings';
|
||||
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['map'][0] = 'Manage maps';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['map'][1] = 'Manage leaflet maps';
|
||||
@@ -44,6 +45,10 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'][0] = 'Deferred
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'][1] = 'Load data of the layer deferred using ajax.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupType'][0] = 'Group type';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupType'][1] = 'Choose a layer group type.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['onEachFeature'][0] = 'onEachFeature expression';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['onEachFeature'][1] = 'Use a custom onEachFeature expression. Can be a anonymous function or method reference. If defined the extension does not handle popup adding for you.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['pointToLayer'][0] = 'pointToLayer expression';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['pointToLayer'][1] = 'Use a custom pointToLayer expression. Can be a anonymous function or method reference. If defined the extension does not handle popup or icon adding for you.';
|
||||
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][0] = 'Layer group';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][1] = 'Basic layer group. <br> See <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">http://leafletjs.com/reference.html#layergroup</a>';
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user