mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-16 16:45:22 +00:00
L.Control.Attribution: encapsulate some code from L.Layer (#7764)
This commit is contained in:
@ -45,9 +45,24 @@ export var Attribution = Control.extend({
|
||||
|
||||
this._update();
|
||||
|
||||
map.on('layeradd', this._addAttribution, this);
|
||||
|
||||
return this._container;
|
||||
},
|
||||
|
||||
onRemove: function (map) {
|
||||
map.off('layeradd', this._addAttribution, this);
|
||||
},
|
||||
|
||||
_addAttribution: function (ev) {
|
||||
if (ev.layer.getAttribution) {
|
||||
this.addAttribution(ev.layer.getAttribution());
|
||||
ev.layer.once('remove', function () {
|
||||
this.removeAttribution(ev.layer.getAttribution());
|
||||
}, this);
|
||||
}
|
||||
},
|
||||
|
||||
// @method setPrefix(prefix: String): this
|
||||
// Sets the text before the attributions.
|
||||
setPrefix: function (prefix) {
|
||||
|
@ -113,10 +113,6 @@ export var Layer = Evented.extend({
|
||||
|
||||
this.onAdd(map);
|
||||
|
||||
if (this.getAttribution && map.attributionControl) {
|
||||
map.attributionControl.addAttribution(this.getAttribution());
|
||||
}
|
||||
|
||||
this.fire('add');
|
||||
map.fire('layeradd', {layer: this});
|
||||
}
|
||||
@ -189,10 +185,6 @@ Map.include({
|
||||
layer.onRemove(this);
|
||||
}
|
||||
|
||||
if (layer.getAttribution && this.attributionControl) {
|
||||
this.attributionControl.removeAttribution(layer.getAttribution());
|
||||
}
|
||||
|
||||
delete this._layers[id];
|
||||
|
||||
if (this._loaded) {
|
||||
|
Reference in New Issue
Block a user