OpenLayers OpenLayers

Changeset 4063

Show
Ignore:
Timestamp:
08/27/07 17:03:28 (1 year ago)
Author:
tschaub
Message:

Properly destroy features in the point, path, and polygon handlers. Patch with tests from fredj - thank you for the catch and the great patch. (Closes #931)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Handler/Path.js

    r4036 r4063  
    7979     */ 
    8080    destroyFeature: function() { 
     81        OpenLayers.Handler.Point.prototype.destroyFeature.apply(this); 
    8182        this.line.destroy(); 
    82         this.point.destroy()
     83        this.line = null
    8384    }, 
    8485     
  • trunk/openlayers/lib/OpenLayers/Handler/Point.js

    r4036 r4063  
    117117        this.map.removeLayer(this.layer, false); 
    118118        this.layer.destroy(); 
     119        this.layer = null; 
    119120        return true; 
    120121    }, 
     
    126127    destroyFeature: function() { 
    127128        this.point.destroy(); 
     129        this.point = null; 
    128130    }, 
    129131 
  • trunk/openlayers/tests/Handler/test_Path.html

    r4059 r4063  
    6767    }      
    6868         
     69    function test_Handler_Path_destroy(t) { 
     70        t.plan(6); 
     71        var map = new OpenLayers.Map('map'); 
     72        map.addLayer(new OpenLayers.Layer.WMS("", "", {})); 
     73        map.zoomToMaxExtent(); 
     74        var control = new OpenLayers.Control(); 
     75        map.addControl(control); 
     76        var handler = new OpenLayers.Handler.Path(control, {foo: 'bar'}); 
     77 
     78        handler.activate(); 
     79        var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1}; 
     80        handler.mousedown(evt); 
     81 
     82        t.ok(handler.layer, 
     83             "handler has a layer prior to destroy"); 
     84        t.ok(handler.point, 
     85             "handler has a point prior to destroy"); 
     86        t.ok(handler.line, 
     87             "handler has a line prior to destroy"); 
     88        handler.destroy(); 
     89        t.eq(handler.layer, null, 
     90             "handler.layer is null after destroy"); 
     91        t.eq(handler.point, null, 
     92             "handler.point is null after destroy"); 
     93        t.eq(handler.line, null, 
     94             "handler.line is null after destroy"); 
     95    } 
    6996     
    7097 
  • trunk/openlayers/tests/Handler/test_Point.html

    r4059 r4063  
    6363    }      
    6464         
     65    function test_Handler_Point_destroy(t) { 
     66        t.plan(4); 
     67        var map = new OpenLayers.Map('map'); 
     68        map.addLayer(new OpenLayers.Layer.WMS("", "", {})); 
     69        map.zoomToMaxExtent(); 
     70        var control = new OpenLayers.Control(); 
     71        map.addControl(control); 
     72        var handler = new OpenLayers.Handler.Point(control, {foo: 'bar'}); 
     73 
     74        handler.activate(); 
     75        var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1}; 
     76        handler.mousedown(evt); 
     77 
     78        t.ok(handler.layer, 
     79             "handler has a layer prior to destroy"); 
     80        t.ok(handler.point, 
     81             "handler has a point prior to destroy"); 
     82        handler.destroy(); 
     83        t.eq(handler.layer, null, 
     84             "handler.layer is null after destroy"); 
     85        t.eq(handler.point, null, 
     86             "handler.point is null after destroy"); 
     87    } 
    6588     
    6689