Control.GetFeature should abort requests with protocol.abort() instead of response.priv.abort(), r=ahocevar (closes #1999)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9165 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2009-04-01 16:25:35 +00:00
parent 339f5bf8f6
commit 4254d1efdf
2 changed files with 25 additions and 11 deletions

View File

@@ -135,11 +135,11 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
handlers: null,
/**
* Property: hoverRequest
* {<OpenLayers.Request>} contains the currently running hover request
* (if any).
* Property: hoverResponse
* {<OpenLayers.Protocol.Response>} The response object associated with
* the currently running hover request (if any).
*/
hoverRequest: null,
hoverResponse: null,
/**
* Constant: EVENT_TYPES
@@ -324,9 +324,9 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
* Callback from the handlers.hover set up when <hover> selection is on
*/
cancelHover: function() {
if (this.hoverRequest) {
this.hoverRequest.abort();
this.hoverRequest = null;
if (this.hoverResponse) {
this.protocol.abort(this.hoverResponse);
this.hoverResponse = null;
}
},
@@ -378,7 +378,7 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
scope: this
});
if(options.hover == true) {
this.hoverRequest = response.priv;
this.hoverResponse = response;
}
},

View File

@@ -56,7 +56,8 @@
}
function test_Control_GetFeature_hover(t) {
t.plan(3);
t.plan(6);
var abortedResponse = null;
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.WMS("foo", "wms", {
layers: "foo"
@@ -65,6 +66,7 @@
map.setCenter(new OpenLayers.LonLat(1,2));
var feature1 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,2));
var feature2 = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(2,3));
var response = new OpenLayers.Protocol.Response();
var control = new OpenLayers.Control.GetFeature({
protocol: new OpenLayers.Protocol({
read: function(obj){
@@ -72,7 +74,10 @@
features: [feature1, feature2],
code: 1
});
return {priv: {}};
return response;
},
abort: function(response) {
abortedResponse = response;
}
}),
hover: true
@@ -90,8 +95,17 @@
control.events.register("outfeature", this, outTest);
hoverFeature = feature1;
control.selectHover({xy: new OpenLayers.Pixel(200, 125)});
t.ok(control.hoverResponse == response,
"selectHover stores the protocol response in the hoverResponse property");
hoverFeature = feature2;
control.selectHover({xy: new OpenLayers.Pixel(400, 0)});
control.cancelHover();
t.ok(abortedResponse == response,
"cancelHover calls protocol.abort() with the expected response");
t.eq(control.hoverResponse, null,
"cancelHover sets this.hoverResponse to null");
control.events.unregister("hoverfeature", this, hoverTest);
control.events.unregister("outfeature", this, outTest);
}