From fe8db5ee7e32b441ea03b8663ab30994ca4afc98 Mon Sep 17 00:00:00 2001 From: esp_maniac <91507465+espmaniac@users.noreply.github.com> Date: Thu, 28 Nov 2024 21:27:46 +0300 Subject: [PATCH] fix dragging when panning with touch --- main.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 9acda2f..5799f35 100644 --- a/main.js +++ b/main.js @@ -779,6 +779,12 @@ canvas.addEventListener("touchmove", function(event) { let pointerX = event.touches[0].clientX - canvas.getBoundingClientRect().left; let pointerY = event.touches[0].clientY - canvas.getBoundingClientRect().top; + if (touches.length !== event.touches.length) { + panOffX = pointerX; + panOffY = pointerY; + + } + if (event.touches.length <= 1) { if (isDragging) { @@ -792,9 +798,6 @@ canvas.addEventListener("touchmove", function(event) { else if (isPanning) { offsetX -= (panOffX - pointerX) / zoom; offsetY -= (panOffY - pointerY) / zoom; - - panOffX = pointerX; - panOffY = pointerY; } } @@ -835,9 +838,15 @@ canvas.addEventListener("touchmove", function(event) { offsetX += current.x - prev.x; offsetY += current.y - prev.y; + + } + + panOffX = pointerX; + panOffY = pointerY; + touches = event.touches;