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
This commit is contained in:
Tim Schaub
2009-04-10 19:22:14 +00:00
parent 119f9bc635
commit ddbf4b5222
2 changed files with 7 additions and 2 deletions

View File

@@ -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;

View File

@@ -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) {