mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 19:13:55 +01:00
Improve handling of omnivore data loading.
This commit is contained in:
@@ -113,7 +113,7 @@ L.contao = new (L.Class.extend({
|
||||
* @param customLayer optional custom layer.
|
||||
* @param map Pass a map object so that the data loading events are passed to the map.
|
||||
*/
|
||||
loadLayer: function(hash, type, options, customLayer, map) {
|
||||
load: function(hash, type, options, customLayer, map) {
|
||||
var url = this.createRequestUrl(hash);
|
||||
var layer = omnivore[type](url, options, customLayer);
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class EncoderSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
$value = $event->getValue();
|
||||
$encoder = $event->getEncoder();
|
||||
$ref = $encoder->encodeReference($value);
|
||||
$template = 'L.contao.load(%s, %s, %s, %s, map);';
|
||||
|
||||
if ($value instanceof OmnivoreLayer) {
|
||||
$url = $value->getUrl();
|
||||
@@ -97,18 +97,24 @@ class EncoderSubscriber implements EventSubscriberInterface
|
||||
if ($url instanceof RequestUrl) {
|
||||
$url = $url->getHash();
|
||||
} elseif (strpos($url, '/') !== false) {
|
||||
// Slash found, not contao leaflet hash, do not replace encoding.
|
||||
// Slash found, not a Contao leaflet hash, do not replace encoding.
|
||||
return;
|
||||
}
|
||||
|
||||
if ($value->getCustomLayer()) {
|
||||
$ref = $encoder->encodeReference($value->getCustomLayer());
|
||||
} else {
|
||||
$template = $encoder->encodeReference($value) . ' = ' . $template;
|
||||
$ref = 'null';
|
||||
}
|
||||
|
||||
$event->addLine(
|
||||
sprintf(
|
||||
'%s = L.contao.loadLayer(%s, %s, %s, %s, map);',
|
||||
$ref,
|
||||
$template,
|
||||
$encoder->encodeValue($url),
|
||||
$encoder->encodeValue(strtolower(str_replace('Omnivore.', '', $value->getType()))),
|
||||
$encoder->encodeArray($value->getOptions(), JSON_FORCE_OBJECT),
|
||||
$this->encodeCustomLayer($value, $encoder)
|
||||
$ref
|
||||
)
|
||||
);
|
||||
|
||||
@@ -121,28 +127,4 @@ class EncoderSubscriber implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a custom layer for the omnivore plugin.
|
||||
*
|
||||
* @param OmnivoreLayer $layer The layer.
|
||||
* @param Encoder $encoder The javascript encoder.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function encodeCustomLayer(OmnivoreLayer $layer, Encoder $encoder)
|
||||
{
|
||||
$customLayer = $layer->getCustomLayer();
|
||||
|
||||
if ($customLayer instanceof GeoJson && !$customLayer->getMethodCalls()) {
|
||||
return sprintf(
|
||||
'L.geoJson(null, %s)',
|
||||
$encoder->encodeValue($customLayer->getOptions())
|
||||
);
|
||||
} elseif ($customLayer) {
|
||||
return $encoder->encodeReference($customLayer);
|
||||
}
|
||||
|
||||
return 'null';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user