Merge pull request #857 from faegi/featureClickPatch
Clear cached mousedown/up positions used for distinguishing between (fix #856).
This commit is contained in:
@@ -351,6 +351,11 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
if(dpx <= this.clickTolerance) {
|
if(dpx <= this.clickTolerance) {
|
||||||
this.callback(key, args);
|
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 {
|
} else {
|
||||||
this.callback(key, args);
|
this.callback(key, args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -564,10 +564,10 @@
|
|||||||
handler = new OpenLayers.Handler.Feature(
|
handler = new OpenLayers.Handler.Feature(
|
||||||
control, layer, callbacks, {clickTolerance: 4});
|
control, layer, callbacks, {clickTolerance: 4});
|
||||||
handler.activate();
|
handler.activate();
|
||||||
handler.down = {x: 0, y: 0};
|
|
||||||
|
|
||||||
// distance between down and up is 1, which is
|
// distance between down and up is 1, which is
|
||||||
// lower than clickTolerance so "click" should trigger
|
// lower than clickTolerance so "click" should trigger
|
||||||
|
handler.down = {x: 0, y: 0};
|
||||||
handler.up = {x: 1, y: 0};
|
handler.up = {x: 1, y: 0};
|
||||||
clicks = 0;
|
clicks = 0;
|
||||||
map.events.triggerEvent("click", evtPx);
|
map.events.triggerEvent("click", evtPx);
|
||||||
@@ -575,6 +575,7 @@
|
|||||||
|
|
||||||
// distance between down and up is 4, which is
|
// distance between down and up is 4, which is
|
||||||
// equal to clickTolerance so "click" should trigger
|
// equal to clickTolerance so "click" should trigger
|
||||||
|
handler.down = {x: 0, y: 0}; // cached handler.down cleared (#857)
|
||||||
handler.up = {x: 0, y: 4};
|
handler.up = {x: 0, y: 4};
|
||||||
clicks = 0;
|
clicks = 0;
|
||||||
map.events.triggerEvent("click", evtPx);
|
map.events.triggerEvent("click", evtPx);
|
||||||
@@ -582,6 +583,7 @@
|
|||||||
|
|
||||||
// distance between down and up is 5, which is
|
// distance between down and up is 5, which is
|
||||||
// greater than clickTolerance so "click" should not trigger
|
// 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};
|
handler.up = {x: 5, y: 0};
|
||||||
clicks = 0;
|
clicks = 0;
|
||||||
map.events.triggerEvent("click", evtPx);
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user