OpenLayers OpenLayers

Ticket #964: requestAbort.patch

File requestAbort.patch, 1.8 kB (added by euzuro, 11 months ago)

patch to abort our requests on multiple reloads (see my previous comment for explanation). since isLoading is a variable defined at the generic Tile level, it doesn't make sense to replace it with the 'request' property (as I had mentioned in my comment). tests pass in ff/ie6

  • tests/Tile/test_WFS.html

    old new  
    4141         
    4242    } 
    4343     
     44    function test_Tile_WFS_loadFeaturesForRegion(t) { 
     45        t.plan(9); 
     46         
     47        var tile = { 
     48            'url': {} 
     49        }; 
     50 
     51        var g_Success = {};      
     52 
     53        var tLoadURL = OpenLayers.loadURL; 
     54        OpenLayers.loadURL = function(url, params, caller, onComplete) { 
     55            t.ok(url == tile.url, "tile's url correctly passed as 1st param to loadURL"); 
     56            t.ok(params == null, "null passed as 2nd param to loadURL"); 
     57            t.ok(caller == tile, "tile passed as 3rd param to loadURL"); 
     58            t.ok(onComplete == g_Success, "success param from loadFeaturesForRegion() passed as 4th param to loadURL"); 
     59        }; 
     60         
     61      //no running request -- 4 tests 
     62        OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]); 
     63 
     64      //running request (cancelled) -- 4 tests + 1 test (for request abort) 
     65        tile.request = { 
     66            'transport': { 
     67                'abort': function() { 
     68                    t.ok(true, "request aborted"); 
     69                } 
     70            } 
     71        }; 
     72        OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]); 
     73                 
     74        OpenLayers.loadURL = tLoadURL; 
     75    } 
     76     
    4477    function test_Tile_WFS_destroy(t) { 
    4578        t.plan(8); 
    4679 
  • lib/OpenLayers/Tile/WFS.js

    old new  
    108108    * failure - {function} 
    109109    */ 
    110110    loadFeaturesForRegion:function(success, failure) { 
     111        if(this.request) { 
     112            this.request.transport.abort(); 
     113            //this.request.destroy(); 
     114        } 
    111115        this.request = OpenLayers.loadURL(this.url, null, this, success); 
    112116    }, 
    113117