forked from Snck3rs/contao-leaflet-maps
Support bounds changing after files got loaded.
This commit is contained in:
@@ -48,6 +48,8 @@ parameters:
|
||||
file:
|
||||
children: false
|
||||
icon: 'bundles/netzmachtcontaoleaflet/img/file.png'
|
||||
boundsMode:
|
||||
extend: true
|
||||
|
||||
services:
|
||||
_defaults:
|
||||
|
||||
@@ -219,7 +219,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
|
||||
],
|
||||
|
||||
'file extends default' => [
|
||||
'+config' => ['file'],
|
||||
'+config' => ['file', 'boundsMode'],
|
||||
'+expert' => [
|
||||
'onEachFeature',
|
||||
'pointToLayer',
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -124,6 +124,10 @@ class FileLayerMapper extends AbstractLayerMapper
|
||||
|
||||
$customLayer = $definition->getCustomLayer();
|
||||
if ($customLayer instanceof GeoJson) {
|
||||
if ($model->boundsMode) {
|
||||
$customLayer->setOption('boundsMode', $model->boundsMode);
|
||||
}
|
||||
|
||||
if ($model->pointToLayer) {
|
||||
$customLayer->setPointToLayer(new Expression($model->pointToLayer));
|
||||
}
|
||||
|
||||
@@ -89,16 +89,15 @@ class EncoderSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
$value = $event->getValue();
|
||||
$encoder = $event->getEncoder();
|
||||
$template = 'L.contao.load(%s, %s, %s, %s, map);';
|
||||
$template = 'L.contao.%s(%s, %s, %s, %s, map);';
|
||||
$method = 'loadFile';
|
||||
|
||||
if ($value instanceof OmnivoreLayer) {
|
||||
$url = $value->getUrl();
|
||||
|
||||
if ($url instanceof RequestUrl) {
|
||||
$url = $url->getHash();
|
||||
} elseif (strpos($url, '/') !== false) {
|
||||
// Slash found, not a Contao leaflet hash, do not replace encoding.
|
||||
return;
|
||||
$method = 'load';
|
||||
}
|
||||
|
||||
if ($value->getCustomLayer()) {
|
||||
@@ -111,6 +110,7 @@ class EncoderSubscriber implements EventSubscriberInterface
|
||||
$event->addLine(
|
||||
sprintf(
|
||||
$template,
|
||||
$method,
|
||||
$encoder->encodeValue($url),
|
||||
$encoder->encodeValue(strtolower(str_replace('Omnivore.', '', $value->getType()))),
|
||||
$encoder->encodeArray($value->getOptions(), JSON_FORCE_OBJECT),
|
||||
|
||||
Reference in New Issue
Block a user