Add a few more featuregroup tests and fix regression of removeLayer.
This commit is contained in:
parent
0de87fa6ba
commit
ec3b9e0ff2
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user