Need to clone the x/y of the touch as the actual object gets updated. This fixes contextMenu occurring while touch panning the map.

This commit is contained in:
danzel 2012-09-03 11:31:01 +12:00
parent d133c86b51
commit d3d85198e2

View File

@ -1,7 +1,7 @@
L.Util.extend(L.DomEvent, { L.Util.extend(L.DomEvent, {
// inspired by Zepto touch code by Thomas Fuchs // inspired by Zepto touch code by Thomas Fuchs
addLongPressListener: function (obj, handler, id) { addLongPressListener: function (obj, handler, id) {
var touch, var touch, touchStartX, touchStartY,
start, start,
timeoutId = null, timeoutId = null,
delay = 1000, delay = 1000,
@ -20,17 +20,21 @@ L.Util.extend(L.DomEvent, {
} }
touch = e.touches[0]; touch = e.touches[0];
touchStartX = touch.pageX;
touchStartY = touch.pageY;
start = Date.now(); start = Date.now();
timeoutId = setTimeout(function () { timeoutId = setTimeout(function () {
touch.pageX = touchStartX;
touch.pageY = touchStartY;
touch.type = 'contextmenu'; touch.type = 'contextmenu';
handler(touch); handler(touch);
}, delay); }, delay);
} }
function onTouchMove(e) { function onTouchMove(e) {
diffX = e.touches[0].pageX - touch.pageX; diffX = e.touches[0].pageX - touchStartX;
diffY = e.touches[0].pageY - touch.pageY; diffY = e.touches[0].pageY - touchStartY;
if (diffX * diffX + diffY * diffY > maxMovement * maxMovement) { if (diffX * diffX + diffY * diffY > maxMovement * maxMovement) {
clearTimeout(timeoutId); clearTimeout(timeoutId);