fix(ui): handle all changedTouches

Signed-off-by: Xuefer <xuefer@gmail.com>
Co-authored-by: Xuefer <xuefer@gmail.com>
This commit is contained in:
Sören Beye 2025-03-20 18:50:51 +01:00 committed by GitHub
parent b7de2f32db
commit 92b2e6f092
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 51 deletions

View File

@ -63,7 +63,9 @@ export class TouchHandler extends EventTarget {
rawEvt.preventDefault();
if (this.currentGesture instanceof NoGesture) {
if (mapCanvasEvents.length >= 2) {
this.currentGesture = new OngoingPinchGesture(mapCanvasEvents[0], mapCanvasEvents[1]);
} else if (this.currentGesture instanceof NoGesture) {
this.currentGesture = new PossibleTapGesture(mapCanvasEvents[0]);
} else if (this.currentGesture instanceof PossibleTapGesture || this.currentGesture instanceof OngoingPanGesture) { //upgrade to pinch
this.currentGesture = new OngoingPinchGesture(this.currentGesture.getLastEvent(), mapCanvasEvents[0]);

View File

@ -36,33 +36,35 @@ export class OngoingPanGesture extends Gesture {
handleOngoingEvent(rawEvt : UserEvent, evts: Array<MapCanvasEvent>): GestureEventHandlingResult {
const event = evts[0];
for (const event of evts) {
if (event.pointerId === this.pointerId) {
this.lastEvent = event;
this.lastPosition.x = event.x;
this.lastPosition.y = event.y;
this.lastEvent = event;
this.lastPosition.x = event.x;
this.lastPosition.y = event.y;
return new PanMoveTouchHandlerEvent(
this.initialPosition.x,
this.initialPosition.y,
this.lastPosition.x,
this.lastPosition.y
);
return new PanMoveTouchHandlerEvent(
this.initialPosition.x,
this.initialPosition.y,
this.lastPosition.x,
this.lastPosition.y
);
}
}
}
handleEndEvent(rawEvt : UserEvent, evts : Array<MapCanvasEvent>) : GestureEventHandlingResult {
const event = evts[0];
for (const event of evts) {
if (event.pointerId === this.pointerId) {
this.lastPosition.x = event.x;
this.lastPosition.y = event.y;
if (event.pointerId === this.pointerId) {
this.lastPosition.x = event.x;
this.lastPosition.y = event.y;
return new PanEndTouchHandlerEvent(
this.initialPosition.x,
this.initialPosition.y,
this.lastPosition.x,
this.lastPosition.y
);
return new PanEndTouchHandlerEvent(
this.initialPosition.x,
this.initialPosition.y,
this.lastPosition.x,
this.lastPosition.y
);
}
}
}

View File

@ -84,23 +84,28 @@ export class OngoingPinchGesture extends Gesture {
}
handleEndEvent(rawEvt : UserEvent, evts : Array<MapCanvasEvent>) : GestureEventHandlingResult {
let pointer1End;
let pointer2End;
for (const evt of evts) {
if (evt.pointerId === this.pointerId) {
return new PinchEndTouchHandlerEvent(
pointer1End = new PinchEndTouchHandlerEvent(
this.last2Position.x,
this.last2Position.y,
this.pointer2Id
);
} else if (evt.pointerId === this.pointer2Id) {
return new PinchEndTouchHandlerEvent(
pointer2End = new PinchEndTouchHandlerEvent(
this.lastPosition.x,
this.lastPosition.y,
this.pointerId
);
}
}
return false;
if (pointer1End && pointer2End) {
return false;
} else {
return pointer1End || pointer2End || false;
}
}
}

View File

@ -36,36 +36,36 @@ export class PossibleTapGesture extends Gesture {
handleOngoingEvent(rawEvt : UserEvent, evts: Array<MapCanvasEvent>): GestureEventHandlingResult {
const event = evts[0];
for (const event of evts) {
if (event.pointerId === this.pointerId) {
this.lastEvent = event;
this.lastPosition.x = event.x;
this.lastPosition.y = event.y;
this.lastEvent = event;
this.lastPosition.x = event.x;
this.lastPosition.y = event.y;
const distance = distance2d(
this.initialPosition.x,
this.initialPosition.y,
this.lastPosition.x,
this.lastPosition.y
);
const distance = distance2d(
this.initialPosition.x,
this.initialPosition.y,
this.lastPosition.x,
this.lastPosition.y
);
//If the pointer moved too much, it's not a tap anymore
if (distance > 5) {
return false;
//If the pointer moved too much, it's not a tap anymore
if (distance > 5) {
return false;
}
}
}
}
handleEndEvent(rawEvt : UserEvent, evts : Array<MapCanvasEvent>) : GestureEventHandlingResult {
const event = evts[0];
if (event.pointerId === this.pointerId) {
return new TapTouchHandlerEvent(
this.initialPosition.x,
this.initialPosition.y,
event.timestamp - this.initialEvent.timestamp
);
} else {
return;
for (const event of evts) {
if (event.pointerId === this.pointerId) {
return new TapTouchHandlerEvent(
this.initialPosition.x,
this.initialPosition.y,
event.timestamp - this.initialEvent.timestamp
);
}
}
}