From d3d85198e2920def6ba2e380b74b541bd418ceba Mon Sep 17 00:00:00 2001 From: danzel Date: Mon, 3 Sep 2012 11:31:01 +1200 Subject: [PATCH] Need to clone the x/y of the touch as the actual object gets updated. This fixes contextMenu occurring while touch panning the map. --- src/dom/DomEvent.LongPress.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/dom/DomEvent.LongPress.js b/src/dom/DomEvent.LongPress.js index 4384c1b0..12416b6d 100644 --- a/src/dom/DomEvent.LongPress.js +++ b/src/dom/DomEvent.LongPress.js @@ -1,7 +1,7 @@ L.Util.extend(L.DomEvent, { // inspired by Zepto touch code by Thomas Fuchs addLongPressListener: function (obj, handler, id) { - var touch, + var touch, touchStartX, touchStartY, start, timeoutId = null, delay = 1000, @@ -20,17 +20,21 @@ L.Util.extend(L.DomEvent, { } touch = e.touches[0]; + touchStartX = touch.pageX; + touchStartY = touch.pageY; start = Date.now(); timeoutId = setTimeout(function () { + touch.pageX = touchStartX; + touch.pageY = touchStartY; touch.type = 'contextmenu'; handler(touch); }, delay); } function onTouchMove(e) { - diffX = e.touches[0].pageX - touch.pageX; - diffY = e.touches[0].pageY - touch.pageY; + diffX = e.touches[0].pageX - touchStartX; + diffY = e.touches[0].pageY - touchStartY; if (diffX * diffX + diffY * diffY > maxMovement * maxMovement) { clearTimeout(timeoutId);