featuresremoved event is called with zero lenght array if layer.selectedFeature is supplied to layer.removeFeatures, p=igrcic, r,t=me (closes #2379)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9929 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2009-12-27 22:16:56 +00:00
parent be246326ee
commit 442d760fe5
2 changed files with 29 additions and 6 deletions

View File

@@ -581,7 +581,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
if (!(features instanceof Array)) { if (!(features instanceof Array)) {
features = [features]; features = [features];
} }
if (features === this.features) { if (features === this.features || features === this.selectedFeatures) {
features = features.slice(); features = features.slice();
} }

View File

@@ -130,7 +130,7 @@
} }
function test_Layer_Vector_removeFeatures(t) { function test_Layer_Vector_removeFeatures(t) {
t.plan(13); t.plan(17);
var layer = new OpenLayers.Layer.Vector(name); var layer = new OpenLayers.Layer.Vector(name);
var features, log; var features, log;
@@ -164,15 +164,38 @@
}); });
layer.removeFeatures(layer.features); layer.removeFeatures(layer.features);
t.eq(log.length, 1, t.eq(log.length, 1,
"\"featuresremoved\" triggered once"); "\"featuresremoved\" triggered once [0]");
t.eq(log[0].features.length, 2, t.eq(log[0].features.length, 2,
"\"featuresremoved\" listener is passed two features"); "\"featuresremoved\" listener is passed two features [0]");
t.ok(log[0].features[0] == pointFeature1, t.ok(log[0].features[0] == pointFeature1,
"\"featuresremoved\" listener is passed the correct feature at index 0"); "\"featuresremoved\" listener is passed the correct feature at index 0 [0]");
t.ok(log[0].features[1] == pointFeature2, t.ok(log[0].features[1] == pointFeature2,
"\"featuresremoved\" listener is passed the correct feature at index 1"); "\"featuresremoved\" listener is passed the correct feature at index 1 [0]");
layer.events.remove("featuresremoved"); layer.events.remove("featuresremoved");
// 4 tests
log = [];
layer.addFeatures([
pointFeature1, pointFeature2,
pointFeature1.clone(), pointFeature2.clone()
]);
layer.selectedFeatures.push(pointFeature1);
layer.selectedFeatures.push(pointFeature2);
layer.events.register("featuresremoved", null, function(obj) {
log.push(obj);
});
layer.removeFeatures(layer.selectedFeatures);
t.eq(log.length, 1,
"\"featuresremoved\" triggered once [1]");
t.eq(log[0].features.length, 2,
"\"featuresremoved\" listener is passed two features [1]");
t.ok(log[0].features[0] == pointFeature1,
"\"featuresremoved\" listener is passed the correct feature at index 0 [1]");
t.ok(log[0].features[1] == pointFeature2,
"\"featuresremoved\" listener is passed the correct feature at index 1 [1]");
layer.events.remove("featuresremoved");
layer.removeFeatures(layer.features);
// 6 tests // 6 tests
layer.events.register('beforefeatureremoved', null, function(obj) { layer.events.register('beforefeatureremoved', null, function(obj) {
t.ok(pointFeature1 == obj.feature, t.ok(pointFeature1 == obj.feature,