OpenLayers OpenLayers

Changeset 5989

Show
Ignore:
Timestamp:
02/05/08 01:12:29 (1 year ago)
Author:
euzuro
Message:

give the wfs layer a proper destroy method (Closes #1256)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Layer/WFS.js

    r5913 r5989  
    157157            OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments); 
    158158        }     
     159        if (this.tile) { 
     160            this.tile.destroy(); 
     161        } 
     162        this.tile = null; 
     163 
     164        this.ratio = null; 
     165        this.featureClass = null; 
     166        this.format = null; 
     167 
     168        if (this.formatObject && this.formatObject.destroy) { 
     169            this.formatObject.destroy(); 
     170        } 
     171        this.formatObject = null; 
     172         
     173        this.formatOptions = null; 
     174        this.vectorMode = null; 
     175        this.encodeBBOX = null; 
     176        this.extractAttributes = null; 
    159177    }, 
    160178     
  • trunk/openlayers/tests/Layer/test_WFS.html

    r5844 r5989  
    1515 
    1616    } 
     17     
     18    function test_Layer_WFS_destroy(t) { 
     19        t.plan(13); 
     20         
     21        var tVectorDestroy = OpenLayers.Layer.Vector.prototype.destroy; 
     22        OpenLayers.Layer.Vector.prototype.destroy = function() { 
     23            g_VectorDestroyed = true; 
     24        } 
     25 
     26        var tMarkersDestroy = OpenLayers.Layer.Markers.prototype.destroy; 
     27        OpenLayers.Layer.Markers.prototype.destroy = function() { 
     28            g_MarkersDestroyed = true; 
     29        } 
     30 
     31        var layer = { 
     32            'vectorMode': true, 
     33            'tile': { 
     34                'destroy': function() { 
     35                    t.ok(true, "wfs layer's tile is destroyed"); 
     36                } 
     37            }, 
     38            'ratio': {}, 
     39            'featureClass': {}, 
     40            'format': {}, 
     41            'formatObject': { 
     42                'destroy': function() { 
     43                    t.ok(true, "wfs layer's format object is destroyed"); 
     44                } 
     45            }, 
     46            'formatOptions': {}, 
     47            'encodeBBOX': {}, 
     48            'extractAttributes': {} 
     49        }; 
     50         
     51        //this call should set off two tests (destroys for tile and format object) 
     52        g_VectorDestroyed = null; 
     53        g_MarkersDestroyed = null;       
     54        OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);         
     55 
     56        t.ok(g_VectorDestroyed && !g_MarkersDestroyed, "when vector mode is set to true, the default vector layer's destroy() method is called"); 
     57        t.eq(layer.vectorMode, null, "'vectorMode' property nullified"); 
     58        t.eq(layer.tile, null, "'tile' property nullified"); 
     59        t.eq(layer.ratio, null, "'ratio' property nullified"); 
     60        t.eq(layer.featureClass, null, "'featureClass' property nullified"); 
     61        t.eq(layer.format, null, "'format' property nullified"); 
     62        t.eq(layer.formatObject, null, "'formatObject' property nullified"); 
     63        t.eq(layer.formatOptions, null, "'formatOptions' property nullified"); 
     64        t.eq(layer.encodeBBOX, null, "'encodeBBOX' property nullified"); 
     65        t.eq(layer.extractAttributes, null, "'extractAttributes' property nullified"); 
     66 
     67        layer.vectorMode = false; 
     68 
     69        //this call will *not* set off two tests (tile and format object are null) 
     70        g_VectorDestroyed = null; 
     71        g_MarkersDestroyed = null;       
     72        OpenLayers.Layer.WFS.prototype.destroy.apply(layer, []);         
     73        t.ok(!g_VectorDestroyed && g_MarkersDestroyed, "when vector mode is set to false, the default markers layer's destroy() method is called"); 
     74         
     75        OpenLayers.Layer.Vector.prototype.destroy = tVectorDestroy; 
     76        OpenLayers.Layer.Markers.prototype.destroy = tMarkersDestroy; 
     77    } 
     78     
    1779    function test_Layer_WFS_mapresizevector(t) { 
    1880        t.plan(2);