Abort XMLHttpRequest on tile.destroy for WFS. The loadURL function now returns a request object. Thanks pgiraud for the fix. r=crschmidt (closes #964)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5539 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+18
-10
@@ -45,10 +45,16 @@ OpenLayers.nullHandler = function(request) {
|
|||||||
* uri - {String} URI of source doc
|
* uri - {String} URI of source doc
|
||||||
* params - {String} Params on get (doesnt seem to work)
|
* params - {String} Params on get (doesnt seem to work)
|
||||||
* caller - {Object} object which gets callbacks
|
* caller - {Object} object which gets callbacks
|
||||||
* onComplete - {Function} callback for success
|
* onComplete - {Function} Optional callback for success. The callback
|
||||||
* onFailure - {Function} callback for failure
|
* will be called with this set to caller and will receive the request
|
||||||
|
* object as an argument.
|
||||||
|
* onFailure - {Function} Optional callback for failure. In the event of
|
||||||
|
* a failure, the callback will be called with this set to caller and will
|
||||||
|
* receive the request object as an argument.
|
||||||
*
|
*
|
||||||
* Both callbacks optional (though silly)
|
* Returns:
|
||||||
|
* {OpenLayers.Ajax.Request} The request object. To abort loading, call
|
||||||
|
* request.transport.abort();
|
||||||
*/
|
*/
|
||||||
OpenLayers.loadURL = function(uri, params, caller,
|
OpenLayers.loadURL = function(uri, params, caller,
|
||||||
onComplete, onFailure) {
|
onComplete, onFailure) {
|
||||||
@@ -64,13 +70,15 @@ OpenLayers.loadURL = function(uri, params, caller,
|
|||||||
: OpenLayers.nullHandler;
|
: OpenLayers.nullHandler;
|
||||||
|
|
||||||
// from prototype.js
|
// from prototype.js
|
||||||
new OpenLayers.Ajax.Request(uri,
|
return new OpenLayers.Ajax.Request(
|
||||||
{ method: 'get',
|
uri,
|
||||||
parameters: params,
|
{
|
||||||
onComplete: success,
|
method: 'get',
|
||||||
onFailure: failure
|
parameters: params,
|
||||||
}
|
onComplete: success,
|
||||||
);
|
onFailure: failure
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
|
|||||||
*/
|
*/
|
||||||
url: null,
|
url: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: request
|
||||||
|
* {OpenLayers.Ajax.Request}
|
||||||
|
*/
|
||||||
|
request: null,
|
||||||
|
|
||||||
/** TBD 3.0 - reorder the parameters to the init function to put URL
|
/** TBD 3.0 - reorder the parameters to the init function to put URL
|
||||||
* as last, so we can continue to call tile.initialize()
|
* as last, so we can continue to call tile.initialize()
|
||||||
* without changing the arguments.
|
* without changing the arguments.
|
||||||
@@ -57,6 +63,9 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
|
|||||||
this.destroyAllFeatures();
|
this.destroyAllFeatures();
|
||||||
this.features = null;
|
this.features = null;
|
||||||
this.url = null;
|
this.url = null;
|
||||||
|
if(this.request) {
|
||||||
|
this.request.transport.abort();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +106,7 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
|
|||||||
* failure - {function}
|
* failure - {function}
|
||||||
*/
|
*/
|
||||||
loadFeaturesForRegion:function(success, failure) {
|
loadFeaturesForRegion:function(success, failure) {
|
||||||
OpenLayers.loadURL(this.url, null, this, success);
|
this.request = OpenLayers.loadURL(this.url, null, this, success);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_99_Tile_WFS_destroy(t) {
|
function test_99_Tile_WFS_destroy(t) {
|
||||||
t.plan( 6 );
|
t.plan(8);
|
||||||
|
|
||||||
var layer = {}; // bogus layer
|
var layer = {}; // bogus layer
|
||||||
var position = new OpenLayers.Pixel(10,20);
|
var position = new OpenLayers.Pixel(10,20);
|
||||||
@@ -56,14 +56,28 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var _gAbort = false;
|
||||||
|
tile.request = {
|
||||||
|
transport: {
|
||||||
|
abort: function() {
|
||||||
|
_gAbort = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tile.destroy();
|
tile.destroy();
|
||||||
|
|
||||||
t.ok(tile.layer == null, "tile.layer set to null");
|
t.ok(tile.layer == null, "tile.layer set to null");
|
||||||
t.ok(tile.bounds == null, "tile.bounds set to null");
|
t.ok(tile.bounds == null, "tile.bounds set to null");
|
||||||
t.ok(tile.size == null, "tile.size set to null");
|
t.ok(tile.size == null, "tile.size set to null");
|
||||||
t.ok(tile.position == null, "tile.position set to null");
|
t.ok(tile.position == null, "tile.position set to null");
|
||||||
|
t.ok(_gAbort, "request transport is aborted");
|
||||||
|
|
||||||
t.ok(tile.events == null, "tile.events set to null");
|
t.ok(tile.events == null, "tile.events set to null");
|
||||||
|
|
||||||
|
tile.requestSuccess({'requestText': '<xml><foo /></xml>'});
|
||||||
|
t.ok(true, "Didn't fail after calling requestSuccess on destroyed tile.");
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user