From e2468e9f09b09b811a04b0e8519a52023e9f9457 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 1 May 2007 14:09:02 +0000 Subject: [PATCH] Apply Erik's patch from #680 to fix "removeFeatures() in Layer.Vector does not remove features from the selectedFeatures array when deleting features" git-svn-id: http://svn.openlayers.org/trunk/openlayers@3104 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Vector.js | 6 ++++++ tests/Layer/test_Vector.html | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index dd571cc138..80807f24d1 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -248,6 +248,12 @@ OpenLayers.Layer.Vector.prototype = this.features = OpenLayers.Util.removeItem(this.features, feature); this.renderer.eraseGeometry(feature.geometry); + + //in the case that this feature is one of the selected features, + // remove it from that array as well. + if (OpenLayers.Util.indexOf(this.selectedFeatures, feature) != -1){ + OpenLayers.Util.removeItem(this.selectedFeatures, feature); + } } }, diff --git a/tests/Layer/test_Vector.html b/tests/Layer/test_Vector.html index b7565a5556..0ad3a8ddbc 100644 --- a/tests/Layer/test_Vector.html +++ b/tests/Layer/test_Vector.html @@ -29,7 +29,7 @@ } function test_03_Layer_Vector_removeFeatures(t) { - t.plan(2); + t.plan(3); var layer = new OpenLayers.Layer.Vector(name); @@ -43,6 +43,9 @@ t.ok(layer.features.length == 1, "OpenLayers.Layer.Vector.removeFeatures removes a feature from the features array"); layer.addFeatures([pointFeature1.clone(), pointFeature2.clone()]); + layer.selectedFeatures.push(layer.features[0]); + layer.removeFeatures(layer.features[0]); + t.eq(layer.selectedFeatures, [], "Remove features removes selected features"); var features = layer.removeFeatures(layer.features); t.ok(layer.features.length == 0,