mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 11:04:08 +01:00
35 lines
1012 B
JavaScript
35 lines
1012 B
JavaScript
/**
|
|
* Add update bounds method for geo json layers. It is triggered when map bounds changed and make a new request
|
|
* to get the data in the new bounds.
|
|
*/
|
|
L.GeoJSON.include({
|
|
/**
|
|
* Update bounds.
|
|
*
|
|
* @param {L.Event} e The subscribed event.
|
|
*/
|
|
refreshData: function(e) {
|
|
var dataLayer = L.geoJson(),
|
|
layer = this;
|
|
|
|
dataLayer.on('ready', function() {
|
|
var i, layers = layer.getLayers();
|
|
|
|
// Clear old data.
|
|
for (i = 0; i < layers.length; i++) {
|
|
layer.removeLayer(layers[i]);
|
|
}
|
|
|
|
// Copy data from temporary layer.
|
|
layers = this.getLayers();
|
|
for (i = 0; i < layers.length; i++) {
|
|
this.removeLayer(layers[i]);
|
|
layer.addLayer(layers[i]);
|
|
}
|
|
});
|
|
|
|
// TODO: Allow other data formats.
|
|
omnivore.geojson(L.contao.applyFilterToUrl(this.options.requestUrl, e.target), null, dataLayer);
|
|
}
|
|
});
|