mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-29 19:43:50 +01:00
Apply geojson default listeners to the GeoJSON layer as well.
This commit is contained in:
@@ -24,26 +24,9 @@ L.Contao = L.Class.extend({
|
|||||||
initialize: function() {
|
initialize: function() {
|
||||||
L.Icon.Default.imagePath = 'assets/leaflet/libs/leaflet/images';
|
L.Icon.Default.imagePath = 'assets/leaflet/libs/leaflet/images';
|
||||||
|
|
||||||
// Bind triggered data:loading and data:loaded events to the map so that the loading indicator
|
this.bindDataLoadingEvents();
|
||||||
// is aware of that. Dataloading and dataloaded are the default events which leaflet uses but leaflet.ajax not.
|
this.setGeoJsonListeners(L.GeoJSON);
|
||||||
L.Map.addInitHook(function () {
|
this.setGeoJsonListeners(L.GeoJSON.AJAX);
|
||||||
var map = this;
|
|
||||||
|
|
||||||
this.on('layeradd', function(e) {
|
|
||||||
if (e.layer.on) {
|
|
||||||
e.layer.on('data:loading', function() { map.fire('dataloading'); });
|
|
||||||
e.layer.on('data:loaded', function() { map.fire('dataload'); });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (L.GeoJSON.AJAX) {
|
|
||||||
// Set default pointToLayer and onEachFeature handler.
|
|
||||||
L.GeoJSON.AJAX.prototype.options = {
|
|
||||||
pointToLayer: this.pointToLayer.bind(this),
|
|
||||||
onEachFeature: this.onEachFeature.bind(this)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,7 +181,42 @@ L.Contao = L.Class.extend({
|
|||||||
obj.bindPopup(feature.properties.popupContent);
|
obj.bindPopup(feature.properties.popupContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind triggered data:loading and data:loaded events to the map.
|
||||||
|
*
|
||||||
|
* These events are fired by leaflet.ajax. The loading indicator listens to the map dataloading and dataloaded
|
||||||
|
* events which is also used by the tile layers.
|
||||||
|
*/
|
||||||
|
bindDataLoadingEvents: function() {
|
||||||
|
//
|
||||||
|
L.Map.addInitHook(function () {
|
||||||
|
var map = this;
|
||||||
|
|
||||||
|
this.on('layeradd', function(e) {
|
||||||
|
if (e.layer.on) {
|
||||||
|
e.layer.on('data:loading', function() { map.fire('dataloading'); });
|
||||||
|
e.layer.on('data:loaded', function() { map.fire('dataload'); });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default geojson listeners to the prototype.
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
*/
|
||||||
|
setGeoJsonListeners: function(obj) {
|
||||||
|
if (obj && obj.prototype) {
|
||||||
|
obj.prototype.options = {
|
||||||
|
pointToLayer: this.pointToLayer.bind(this),
|
||||||
|
onEachFeature: this.onEachFeature.bind(this)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
window.ContaoLeaflet = new L.Contao();
|
window.ContaoLeaflet = new L.Contao();
|
||||||
|
|||||||
Reference in New Issue
Block a user