diff --git a/spec/suites/layer/FeatureGroupSpec.js b/spec/suites/layer/FeatureGroupSpec.js index 75cb2f75..fd875e8d 100644 --- a/spec/suites/layer/FeatureGroupSpec.js +++ b/spec/suites/layer/FeatureGroupSpec.js @@ -1,9 +1,12 @@ -describe('CircleMarker', function () { +describe('FeatureGroup', function () { + var map; + beforeEach(function () { + map = L.map(document.createElement('div')); + map.setView([0, 0], 1); + }); describe("#_propagateEvent", function () { - var map, marker; + var marker; beforeEach(function () { - map = L.map(document.createElement('div')); - map.setView([0, 0], 1); marker = L.marker([0, 0]); }); describe("when a Marker is added to multiple FeatureGroups ", function () { @@ -33,4 +36,38 @@ }); }); }); + describe('addLayer', function () { + it('adds the layer', function () { + var fg = L.featureGroup(), + marker = L.marker([0, 0]); + + expect(fg.hasLayer(marker)).to.be(false); + + fg.addLayer(marker); + + expect(fg.hasLayer(marker)).to.be(true); + }); + }); + describe('removeLayer', function () { + it('removes the layer passed to it', function () { + var fg = L.featureGroup(), + marker = L.marker([0, 0]); + + fg.addLayer(marker); + expect(fg.hasLayer(marker)).to.be(true); + + fg.removeLayer(marker); + expect(fg.hasLayer(marker)).to.be(false); + }); + it('removes the layer passed to it by id', function () { + var fg = L.featureGroup(), + marker = L.marker([0, 0]); + + fg.addLayer(marker); + expect(fg.hasLayer(marker)).to.be(true); + + fg.removeLayer(marker._leaflet_id); + expect(fg.hasLayer(marker)).to.be(false); + }); + }); }); diff --git a/src/layer/FeatureGroup.js b/src/layer/FeatureGroup.js index 33dbd900..83bc1179 100644 --- a/src/layer/FeatureGroup.js +++ b/src/layer/FeatureGroup.js @@ -27,9 +27,12 @@ L.FeatureGroup = L.LayerGroup.extend({ }, removeLayer: function (layer) { - var id = layer in this._layers ? layer : this.getLayerId(layer); - - if (!this._layers[id]) { return this; } + if (!this.hasLayer(layer)) { + return this; + } + if (layer in this._layers) { + layer = this._layers[layer]; + } layer.off(L.FeatureGroup.EVENTS, this._propagateEvent, this);