OpenLayers OpenLayers

Ticket #1697: destroy2x.2.patch

File destroy2x.2.patch, 2.1 kB (added by tschaub, 4 months ago)

allow layer.destroy to be called twice

  • tests/Layer/Vector.html

    old new  
    238238    } 
    239239 
    240240    function test_Layer_Vector_destroy (t) { 
    241         t.plan(4);     
     241        t.plan(5);     
    242242 
    243243        var options = {protocol: new OpenLayers.Protocol(),  
    244244                       strategies: [new OpenLayers.Strategy(), new OpenLayers.Strategy()]} 
     
    252252 
    253253        t.eq(layer.protocol, null, "layer.protocol is null after destroy"); 
    254254        t.eq(layer.strategies, null, "layer.strategies is null after destroy"); 
     255         
     256        // test that we can call layer.destroy a second time without trouble 
     257        try { 
     258            layer.destroy(); 
     259            layer.destroy(); 
     260            t.ok(true, "layer.destroy called twice without any issues"); 
     261        } catch(err) { 
     262            t.fail("calling layer.destroy twice triggers exception: " + err + " in " + err.fileName + " line " + err.lineNumber); 
     263        } 
     264         
    255265    } 
    256266 
    257267    function test_Layer_Vector_externalGraphic(t) { 
  • lib/OpenLayers/Layer/Vector.js

    old new  
    492492     * options - {Object} 
    493493     */ 
    494494    removeFeatures: function(features, options) { 
     495        if(!features || features.length === 0) { 
     496            return; 
     497        } 
    495498        if (!(features instanceof Array)) { 
    496499            features = [features]; 
    497500        } 
    498         if (features.length <= 0) { 
    499             return; 
    500         } 
    501501 
    502502        var notify = !options || !options.silent; 
    503503 
     
    567567        if(all) { 
    568568            features = this.features; 
    569569        } 
    570         this.removeFeatures(features, options); 
    571         for (var i = 0; i < features.length; i++) { 
    572             features[i].destroy(); 
     570        if(features) { 
     571            this.removeFeatures(features, options); 
     572            for (var i = 0; i < features.length; i++) { 
     573                features[i].destroy(); 
     574            } 
    573575        } 
    574576    }, 
    575577