External baselayer changes should fire 'baselayerchange' instead of 'overlayadd'
'baselayerchange' event should fire with layer name(use object in _layers of L.Control.Layers) instead of only layer.
This commit is contained in:
parent
f7e18a109c
commit
02b93b44e4
@ -145,11 +145,17 @@ L.Control.Layers = L.Control.extend({
|
||||
|
||||
_onLayerChange: function (e) {
|
||||
var id = L.stamp(e.layer);
|
||||
|
||||
if (this._layers[id] && !this._handlingClick) {
|
||||
this._update();
|
||||
var overlayEvent = (e.type === 'layeradd' ? 'overlayadd' : 'overlayremove');
|
||||
this._map.fire(overlayEvent, {layer: this._layers[id]});
|
||||
var overlayEvent;
|
||||
if (this._layers[id].overlay) {
|
||||
overlayEvent = (e.type === 'layeradd' ? 'overlayadd' : 'overlayremove');
|
||||
} else {
|
||||
overlayEvent = (e.type === 'layeradd' ? 'baselayerchange' : null);
|
||||
}
|
||||
if (overlayEvent) {
|
||||
this._map.fire(overlayEvent, {layer: this._layers[id]});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -213,13 +219,15 @@ L.Control.Layers = L.Control.extend({
|
||||
if (input.checked && !this._map.hasLayer(obj.layer)) {
|
||||
this._map.addLayer(obj.layer);
|
||||
if (!obj.overlay) {
|
||||
baseLayer = obj.layer;
|
||||
baseLayer = obj;
|
||||
} else {
|
||||
this._map.fire('overlayadd', {layer: obj});
|
||||
}
|
||||
} else if (!input.checked && this._map.hasLayer(obj.layer)) {
|
||||
this._map.removeLayer(obj.layer);
|
||||
this._map.fire('overlayremove', {layer: obj});
|
||||
if (obj.overlay) {
|
||||
this._map.fire('overlayremove', {layer: obj});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user