From 1548a6c470bdbd6514abc6829beed30522a0a306 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Thu, 12 Apr 2007 10:51:39 +0000 Subject: [PATCH] Patch to empty selectedFeatures when destroying all features from #665, tschaub. This includes tests (hooray) and fixes issues with zooming a wfs layer while you have a feature selected. git-svn-id: http://svn.openlayers.org/trunk/openlayers@3067 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Vector.js | 4 +++- tests/Layer/test_Vector.html | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index b6eb6d106c..dd571cc138 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -26,7 +26,7 @@ OpenLayers.Layer.Vector.prototype = features: null, /** @type Array(OpenLayers.Feature.Vector) */ - selectedFeatures: [], + selectedFeatures: null, /** @type {Boolean} */ reportError: true, @@ -252,8 +252,10 @@ OpenLayers.Layer.Vector.prototype = }, /** + * Destroy all features on the layer and empty the selected features array. */ destroyFeatures: function () { + this.selectedFeatures = new Array(); for (var i = this.features.length - 1; i >= 0; i--) { this.features[i].destroy(); } diff --git a/tests/Layer/test_Vector.html b/tests/Layer/test_Vector.html index 6816e9a88f..b7565a5556 100644 --- a/tests/Layer/test_Vector.html +++ b/tests/Layer/test_Vector.html @@ -122,7 +122,7 @@ } function test_Layer_Vector_destroyFeatures (t) { - t.plan(2); + t.plan(3); layer = new OpenLayers.Layer.Vector(name); var map = new OpenLayers.Map('map'); map.addLayer(layer); @@ -133,8 +133,10 @@ } layer.addFeatures(features); t.eq(layer.features.length, 5, "addFeatures adds 5 features"); + layer.selectedFeatures.push(features[0]); layer.destroyFeatures(); t.eq(layer.features.length, 0, "destroyFeatures triggers removal"); + t.eq(layer.selectedFeatures, [], "Destroy features removes selected features"); } function test_99_Layer_Vector_destroy (t) {