Allow layer.destroy to be called twice without failing for the vector layer. r=elemoine (closes #1697)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7941 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -492,12 +492,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
|||||||
* options - {Object}
|
* options - {Object}
|
||||||
*/
|
*/
|
||||||
removeFeatures: function(features, options) {
|
removeFeatures: function(features, options) {
|
||||||
|
if(!features || features.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!(features instanceof Array)) {
|
if (!(features instanceof Array)) {
|
||||||
features = [features];
|
features = [features];
|
||||||
}
|
}
|
||||||
if (features.length <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var notify = !options || !options.silent;
|
var notify = !options || !options.silent;
|
||||||
|
|
||||||
@@ -567,9 +567,11 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
|||||||
if(all) {
|
if(all) {
|
||||||
features = this.features;
|
features = this.features;
|
||||||
}
|
}
|
||||||
this.removeFeatures(features, options);
|
if(features) {
|
||||||
for (var i = 0; i < features.length; i++) {
|
this.removeFeatures(features, options);
|
||||||
features[i].destroy();
|
for(var i=features.length-1; i>=0; i--) {
|
||||||
|
features[i].destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -238,7 +238,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Layer_Vector_destroy (t) {
|
function test_Layer_Vector_destroy (t) {
|
||||||
t.plan(4);
|
t.plan(5);
|
||||||
|
|
||||||
var options = {protocol: new OpenLayers.Protocol(),
|
var options = {protocol: new OpenLayers.Protocol(),
|
||||||
strategies: [new OpenLayers.Strategy(), new OpenLayers.Strategy()]}
|
strategies: [new OpenLayers.Strategy(), new OpenLayers.Strategy()]}
|
||||||
@@ -252,6 +252,16 @@
|
|||||||
|
|
||||||
t.eq(layer.protocol, null, "layer.protocol is null after destroy");
|
t.eq(layer.protocol, null, "layer.protocol is null after destroy");
|
||||||
t.eq(layer.strategies, null, "layer.strategies is null after destroy");
|
t.eq(layer.strategies, null, "layer.strategies is null after destroy");
|
||||||
|
|
||||||
|
// test that we can call layer.destroy a second time without trouble
|
||||||
|
try {
|
||||||
|
layer.destroy();
|
||||||
|
layer.destroy();
|
||||||
|
t.ok(true, "layer.destroy called twice without any issues");
|
||||||
|
} catch(err) {
|
||||||
|
t.fail("calling layer.destroy twice triggers exception: " + err + " in " + err.fileName + " line " + err.lineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Layer_Vector_externalGraphic(t) {
|
function test_Layer_Vector_externalGraphic(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user