How do I load a Leaflet layer attribute from the server?
I have my own Leaflet tile layer extension
L.TileLayer.Foo = L.TileLayer.extend({
options: {
...
},
initialize: function (apiKey, options) {
...
L.TileLayer.prototype.initialize.call(this, url, mergedOptions);
},
getAttribution: function() {
return "hello!";
}
});
Basically, Leaflet will call getAttribution
all layers at some point and build attribution controls. But what if I want to download the attribution text (which I should getAttribution
return) from the server (based on the apiKey
one provided initialize
)?
I don't see an asynchronous way (something to call from an ajax callback) in the docs
source to share
There is no such functionality in the sheet. You need to implement the AJAX call yourself and then add the attribution manually in the xhr callback. So inside there getAttribution
will be something like:
AjaxCall.then(function(responce){
leafletMap.attributionControl.addAttribution(responce.data.Attribution);
});
source to share