add Control & Layer remove method
This commit is contained in:
parent
08b6074941
commit
eec19a441b
@ -16,6 +16,7 @@ All Leaflet layers (including markers, popups, tile and vector layers) have been
|
||||
* Added `Layer` class which all layers added to a map should inherit from.
|
||||
* Added `add` and `remove` events to all layers.
|
||||
* Added `pane` option to all layers that can be changed (e.g. you can set `pane: 'overlayPane'` to a tile layer).
|
||||
* Added `remove` method to layers and controls (`marker.remove()` is now equivalent to `map.removeLayer(marker)`).
|
||||
* Added `shadowPane` option to markers as well.
|
||||
* Added `getEvents` method to all layers that returns an `{event: listener, ...}` hash; layers now manage its listeners automatically without having to do this in `onAdd`/`onRemove`.
|
||||
* Improved performance of adding/removing layers with layers control present (instead of listening to any layer add/remove, the control only listens to layers added in configuration).
|
||||
|
@ -54,15 +54,15 @@ L.Control = L.Class.extend({
|
||||
return this;
|
||||
},
|
||||
|
||||
removeFrom: function (map) {
|
||||
remove: function () {
|
||||
L.DomUtil.remove(this._container);
|
||||
|
||||
this._map = null;
|
||||
|
||||
if (this.onRemove) {
|
||||
this.onRemove(map);
|
||||
this.onRemove(this._map);
|
||||
}
|
||||
|
||||
this._map = null;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
@ -87,7 +87,7 @@ L.Map.include({
|
||||
},
|
||||
|
||||
removeControl: function (control) {
|
||||
control.removeFrom(this);
|
||||
control.remove();
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -40,10 +40,12 @@ L.Layer = L.Class.extend({
|
||||
map.fire('layeradd', {layer: this});
|
||||
},
|
||||
|
||||
removeFrom: function (map) {
|
||||
remove: function () {
|
||||
|
||||
var id = L.stamp(this);
|
||||
if (!map._layers[id]) { return this; }
|
||||
var id = L.stamp(this),
|
||||
map = this._map;
|
||||
|
||||
if (!map || !map._layers[id]) { return this; }
|
||||
|
||||
if (map._loaded) {
|
||||
this.onRemove(map);
|
||||
@ -61,6 +63,8 @@ L.Layer = L.Class.extend({
|
||||
}
|
||||
|
||||
this._map = null;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
getPane: function (name) {
|
||||
@ -84,7 +88,7 @@ L.Map.include({
|
||||
},
|
||||
|
||||
removeLayer: function (layer) {
|
||||
layer.removeFrom(this);
|
||||
layer.remove();
|
||||
return this;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user