add Control & Layer remove method

This commit is contained in:
Vladimir Agafonkin 2013-12-06 16:49:50 +02:00
parent 08b6074941
commit eec19a441b
3 changed files with 14 additions and 9 deletions

View File

@ -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).

View File

@ -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;
},

View File

@ -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;
},