Attempt fixing multitouch bugs

This commit is contained in:
Pyro Nicampt committed 2025-03-21 12:52:57 -05:00
1 parent 11c8b427c7
commit ebdbb1e979
1 file changed
+11 -4
+11 -4
View File
@@ -38,7 +38,7 @@ window.addEventListener('resize', () => {MapData.view.dirty = true});
/** Handling for the map scrolling and zooming */ /** Handling for the map scrolling and zooming */
function mapNavigationSetup(){ function mapNavigationSetup(){
const touchCache = []; let touchCache = [];
let touchCount = 0; let touchCount = 0;
let pinchDistance = null; let pinchDistance = null;
let previousScale = null; let previousScale = null;
@@ -59,17 +59,24 @@ function mapNavigationSetup(){
previousScale = MapData.view.scale; previousScale = MapData.view.scale;
} }
mapContainer.style.cursor = 'grabbing'; mapContainer.style.cursor = 'grabbing';
isNavigating = true;
} }
const touchMoveHandler = e => { const touchMoveHandler = e => {
if(!touchCache[e.pointerId]) return; if(!touchCache[e.pointerId]){
touchCache = [];
return;
}
if(touchCount == 1){ if(touchCount == 1){
MapData.view.x += e.clientX - touchCache[e.pointerId].x; MapData.view.x += e.clientX - touchCache[e.pointerId].x;
MapData.view.y -= e.clientY - touchCache[e.pointerId].y; MapData.view.y -= e.clientY - touchCache[e.pointerId].y;
}else if(touchCount == 2){ }else if(touchCount == 2){
getTouchAverage(); getTouchAverage();
zoomAtPosition(touchCenter_x, touchCenter_y, (previousScale * getTouchDistance()/pinchDistance)/MapData.view.scale); zoomAtPosition(touchCenter_x, touchCenter_y, (previousScale * getTouchDistance()/pinchDistance)/MapData.view.scale);
}else{
touchCache = [];
MapData.view.dirty = true;
return;
} }
isNavigating = true;
touchCache[e.pointerId].x = e.clientX; touchCache[e.pointerId].x = e.clientX;
touchCache[e.pointerId].y = e.clientY; touchCache[e.pointerId].y = e.clientY;
MapData.view.dirty = true; MapData.view.dirty = true;
@@ -80,7 +87,6 @@ function mapNavigationSetup(){
touchCount--; touchCount--;
if(touchCount <= 0){ if(touchCount <= 0){
mapContainer.style.cursor = ''; mapContainer.style.cursor = '';
isNavigating = false;
} }
} }
const scrollHandler = e => { const scrollHandler = e => {
@@ -203,6 +209,7 @@ function tooltipSetup(){
tooltip.style.display = 'none'; tooltip.style.display = 'none';
mapCanvas.style.cursor = ''; mapCanvas.style.cursor = '';
} }
isNavigating = false;
tooltipDirty = false; tooltipDirty = false;
} }
cursorCoordDisplay.innerHTML = `X: ${MapData.view.unconvertX(tooltipX).toFixed(2)} / Z: ${MapData.view.unconvertY(tooltipY).toFixed(2)}`; cursorCoordDisplay.innerHTML = `X: ${MapData.view.unconvertX(tooltipX).toFixed(2)} / Z: ${MapData.view.unconvertY(tooltipY).toFixed(2)}`;