Support bounds changing after files got loaded.

This commit is contained in:
David Molineus
2017-10-17 17:43:12 +02:00
parent 01b3962b78
commit 46e6dcc2fa
6 changed files with 28 additions and 8 deletions

View File

@@ -124,8 +124,22 @@ L.Contao = L.Evented.extend({
* @param map Pass a map object so that the data loading events are passed to the map. * @param map Pass a map object so that the data loading events are passed to the map.
*/ */
load: function (hash, type, options, customLayer, map) { load: function (hash, type, options, customLayer, map) {
var url = this.createRequestUrl(hash, map), var url = this.createRequestUrl(hash, map);
layer = omnivore[type](url, options, customLayer);
return this.loadFile(url, type, options, customLayer, map);
},
/**
* Load data from an url into a layer using omnivore.
*
* @param url A file url.
* @param type The response content format.
* @param options Parser options
* @param customLayer optional custom layer.
* @param map Pass a map object so that the data loading events are passed to the map.
*/
loadFile: function (url, type, options, customLayer, map) {
var layer = omnivore[type](url, options, customLayer);
if (map) { if (map) {
// Required because Control.Loading tries to get _leafet_id which is created here. // Required because Control.Loading tries to get _leafet_id which is created here.

View File

@@ -48,6 +48,8 @@ parameters:
file: file:
children: false children: false
icon: 'bundles/netzmachtcontaoleaflet/img/file.png' icon: 'bundles/netzmachtcontaoleaflet/img/file.png'
boundsMode:
extend: true
services: services:
_defaults: _defaults:

View File

@@ -219,7 +219,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
], ],
'file extends default' => [ 'file extends default' => [
'+config' => ['file'], '+config' => ['file', 'boundsMode'],
'+expert' => [ '+expert' => [
'onEachFeature', 'onEachFeature',
'pointToLayer', 'pointToLayer',

File diff suppressed because one or more lines are too long

View File

@@ -124,6 +124,10 @@ class FileLayerMapper extends AbstractLayerMapper
$customLayer = $definition->getCustomLayer(); $customLayer = $definition->getCustomLayer();
if ($customLayer instanceof GeoJson) { if ($customLayer instanceof GeoJson) {
if ($model->boundsMode) {
$customLayer->setOption('boundsMode', $model->boundsMode);
}
if ($model->pointToLayer) { if ($model->pointToLayer) {
$customLayer->setPointToLayer(new Expression($model->pointToLayer)); $customLayer->setPointToLayer(new Expression($model->pointToLayer));
} }

View File

@@ -89,16 +89,15 @@ class EncoderSubscriber implements EventSubscriberInterface
{ {
$value = $event->getValue(); $value = $event->getValue();
$encoder = $event->getEncoder(); $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) { if ($value instanceof OmnivoreLayer) {
$url = $value->getUrl(); $url = $value->getUrl();
if ($url instanceof RequestUrl) { if ($url instanceof RequestUrl) {
$url = $url->getHash(); $url = $url->getHash();
} elseif (strpos($url, '/') !== false) { $method = 'load';
// Slash found, not a Contao leaflet hash, do not replace encoding.
return;
} }
if ($value->getCustomLayer()) { if ($value->getCustomLayer()) {
@@ -111,6 +110,7 @@ class EncoderSubscriber implements EventSubscriberInterface
$event->addLine( $event->addLine(
sprintf( sprintf(
$template, $template,
$method,
$encoder->encodeValue($url), $encoder->encodeValue($url),
$encoder->encodeValue(strtolower(str_replace('Omnivore.', '', $value->getType()))), $encoder->encodeValue(strtolower(str_replace('Omnivore.', '', $value->getType()))),
$encoder->encodeArray($value->getOptions(), JSON_FORCE_OBJECT), $encoder->encodeArray($value->getOptions(), JSON_FORCE_OBJECT),