diff --git a/lib/OpenLayers/Handler/Feature.js b/lib/OpenLayers/Handler/Feature.js index ed6f3d1e22..700dd798cd 100644 --- a/lib/OpenLayers/Handler/Feature.js +++ b/lib/OpenLayers/Handler/Feature.js @@ -351,6 +351,11 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, { if(dpx <= this.clickTolerance) { this.callback(key, args); } + // we're done with this set of events now: clear the cached + // positions so we can't trip over them later (this can occur + // if one of the up/down events gets eaten before it gets to us + // but we still get the click) + this.up = this.down = null; } else { this.callback(key, args); } diff --git a/tests/Handler/Feature.html b/tests/Handler/Feature.html index 7c768e1a69..580d419d70 100644 --- a/tests/Handler/Feature.html +++ b/tests/Handler/Feature.html @@ -564,10 +564,10 @@ handler = new OpenLayers.Handler.Feature( control, layer, callbacks, {clickTolerance: 4}); handler.activate(); - handler.down = {x: 0, y: 0}; // distance between down and up is 1, which is // lower than clickTolerance so "click" should trigger + handler.down = {x: 0, y: 0}; handler.up = {x: 1, y: 0}; clicks = 0; map.events.triggerEvent("click", evtPx); @@ -575,6 +575,7 @@ // distance between down and up is 4, which is // equal to clickTolerance so "click" should trigger + handler.down = {x: 0, y: 0}; // cached handler.down cleared (#857) handler.up = {x: 0, y: 4}; clicks = 0; map.events.triggerEvent("click", evtPx); @@ -582,6 +583,7 @@ // distance between down and up is 5, which is // greater than clickTolerance so "click" should not trigger + handler.down = {x: 0, y: 0}; // cached handler.down cleared (#857) handler.up = {x: 5, y: 0}; clicks = 0; map.events.triggerEvent("click", evtPx); @@ -660,6 +662,36 @@ } + function test_clear_event_position_cache(t) { + t.plan(2); + + var map, control, layer, feature, evtPx; + + map = new OpenLayers.Map('map', {controls: []}); + control = new OpenLayers.Control(); + map.addControl(control); + layer = new OpenLayers.Layer(); + layer.getFeatureFromEvent = function(evt) { return feature; }; + map.addLayer(layer); + feature = new OpenLayers.Feature.Vector(); + feature.layer = layer; + + evtPx = { + xy: new OpenLayers.Pixel(Math.random(), Math.random()), + type: "click" + }; + + handler = new OpenLayers.Handler.Feature( + control, layer, {}, {}); + handler.activate(); + + handler.down = {x: 0, y: 0}; + handler.up = {x: 1, y: 0}; + map.events.triggerEvent("click", evtPx); + t.eq(handler.down, null, "cached mousedown position is cleared after handling click"); + t.eq(handler.up, null, "cached mouseup position is cleared after handling click") + } +