From ddbf4b5222b8f72359436f09025d8d381bed9d09 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 10 Apr 2009 19:22:14 +0000 Subject: [PATCH] Taking care to create a copy of the array sent to removeFeatures in the event that the layer.features array is provided. Thanks for the patch bbinet. r=me (closes #2038) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9265 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Vector.js | 3 +++ tests/Layer/Vector.html | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index 30145feac6..8f4c515088 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -559,6 +559,9 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { if (!(features instanceof Array)) { features = [features]; } + if (features === this.features) { + features = features.slice(); + } var notify = !options || !options.silent; diff --git a/tests/Layer/Vector.html b/tests/Layer/Vector.html index 75050d2c5a..31e26f82d6 100644 --- a/tests/Layer/Vector.html +++ b/tests/Layer/Vector.html @@ -130,7 +130,7 @@ } function test_Layer_Vector_removeFeatures(t) { - t.plan(6); + t.plan(9); var layer = new OpenLayers.Layer.Vector(name); @@ -152,7 +152,7 @@ t.ok(layer.features.length == 0, "OpenLayers.Layer.Vector.removeFeatures(layer.features) removes all feature from the features array"); - // 3 tests + // 6 tests layer.events.register('beforefeatureremoved', null, function(obj) { t.ok(pointFeature1 == obj.feature, "OpenLayers.Layer.Vector.removeFeatures triggers beforefeatureremoved with correct feature passed to callback"); @@ -167,6 +167,8 @@ }); layer.addFeatures([pointFeature1]); layer.removeFeatures([pointFeature1]); + layer.addFeatures([pointFeature1]); + layer.removeFeatures(layer.features); // 0 test layer.events.register('beforefeatureremoved', null, function(obj) {