diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index b6e2e88b9f..27701f56ee 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -156,6 +156,24 @@ OpenLayers.Layer.WFS = OpenLayers.Class( } else { OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); } + if (this.tile) { + this.tile.destroy(); + } + this.tile = null; + + this.ratio = null; + this.featureClass = null; + this.format = null; + + if (this.formatObject && this.formatObject.destroy) { + this.formatObject.destroy(); + } + this.formatObject = null; + + this.formatOptions = null; + this.vectorMode = null; + this.encodeBBOX = null; + this.extractAttributes = null; }, /** diff --git a/tests/Layer/test_WFS.html b/tests/Layer/test_WFS.html index 3d6a96f7a8..e87f2e1eb5 100644 --- a/tests/Layer/test_WFS.html +++ b/tests/Layer/test_WFS.html @@ -14,6 +14,68 @@ t.ok(layer.renderer.CLASS_NAME, "layer has a renderer"); } + + function test_Layer_WFS_destroy(t) { + t.plan(13); + + var tVectorDestroy = OpenLayers.Layer.Vector.prototype.destroy; + OpenLayers.Layer.Vector.prototype.destroy = function() { + g_VectorDestroyed = true; + } + + var tMarkersDestroy = OpenLayers.Layer.Markers.prototype.destroy; + OpenLayers.Layer.Markers.prototype.destroy = function() { + g_MarkersDestroyed = true; + } + + var layer = { + 'vectorMode': true, + 'tile': { + 'destroy': function() { + t.ok(true, "wfs layer's tile is destroyed"); + } + }, + 'ratio': {}, + 'featureClass': {}, + 'format': {}, + 'formatObject': { + 'destroy': function() { + t.ok(true, "wfs layer's format object is destroyed"); + } + }, + 'formatOptions': {}, + 'encodeBBOX': {}, + 'extractAttributes': {} + }; + + //this call should set off two tests (destroys for tile and format object) + g_VectorDestroyed = null; + g_MarkersDestroyed = null; + OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []); + + t.ok(g_VectorDestroyed && !g_MarkersDestroyed, "when vector mode is set to true, the default vector layer's destroy() method is called"); + t.eq(layer.vectorMode, null, "'vectorMode' property nullified"); + t.eq(layer.tile, null, "'tile' property nullified"); + t.eq(layer.ratio, null, "'ratio' property nullified"); + t.eq(layer.featureClass, null, "'featureClass' property nullified"); + t.eq(layer.format, null, "'format' property nullified"); + t.eq(layer.formatObject, null, "'formatObject' property nullified"); + t.eq(layer.formatOptions, null, "'formatOptions' property nullified"); + t.eq(layer.encodeBBOX, null, "'encodeBBOX' property nullified"); + t.eq(layer.extractAttributes, null, "'extractAttributes' property nullified"); + + layer.vectorMode = false; + + //this call will *not* set off two tests (tile and format object are null) + g_VectorDestroyed = null; + g_MarkersDestroyed = null; + OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []); + t.ok(!g_VectorDestroyed && g_MarkersDestroyed, "when vector mode is set to false, the default markers layer's destroy() method is called"); + + OpenLayers.Layer.Vector.prototype.destroy = tVectorDestroy; + OpenLayers.Layer.Markers.prototype.destroy = tMarkersDestroy; + } + function test_Layer_WFS_mapresizevector(t) { t.plan(2);