Skip to content

Commit d530792

Browse files
committed
remove layer references from layergroup when they are removed. Fixes #452 (patch)
1 parent b78e762 commit d530792

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cypress/integration/layergroup.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,17 @@ describe('Edit LayerGroup', () => {
4141
});
4242
cy.hasVertexMarkers(0);
4343
});
44+
45+
it('supports clearLayers', () => {
46+
47+
cy.window().then(({ L, map }) => {
48+
const featureGroup = new L.FeatureGroup();
49+
featureGroup.addTo(map)
50+
featureGroup.addLayer(new L.Marker([19.04469, 72.9258]));
51+
map.fitBounds(featureGroup.getBounds())
52+
featureGroup.clearLayers();
53+
54+
expect(featureGroup.pm._layers).to.have.lengthOf(0);
55+
});
56+
})
4457
});

src/js/Edit/L.PM.Edit.LayerGroup.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ Edit.LayerGroup = L.Class.extend({
3030
this.enable(this.getOptions());
3131
}
3232
});
33+
34+
// if a layer is removed from the group, calc the layers list again
35+
this._layerGroup.on('layerremove', e => {
36+
if (e.target._pmTempLayer) {
37+
return;
38+
}
39+
40+
this._layers = this.findLayers();
41+
})
3342
},
3443
findLayers() {
3544
// get all layers of the layer group

0 commit comments

Comments
 (0)