mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(awareness): keep a long drag or touch counting as camera input
Only canvas events refreshed the 1.5 s input window, and a touch only on touchstart. Cesium follows a drag that leaves the canvas at document level (in Firefox, and wherever there are no pointer events), so a long gesture kept moving the camera after the window closed, and the pulses rested mid-gesture. From a pointer or touch start on the canvas until its end or cancel, moves at document level now count too; the listeners go when the gesture ends or the layer detaches.
This commit is contained in:
1 parent
56a7cacbec
commit
de634952ec
3 files changed
+71
-1
No files matched your search
@@ -23,6 +23,36 @@ export function createLifecycle({
|
||||
if (event?.type === 'pointermove' && !event.buttons) return;
|
||||
if (!cameraInputsEnabled()) return;
|
||||
layerState.lastCameraInputMs = Date.now();
|
||||
if (event?.type === 'pointerdown' || event?.type === 'touchstart')
|
||||
followGesture(true);
|
||||
}
|
||||
|
||||
// A drag can leave the canvas, and Cesium follows it at document level
|
||||
// (in Firefox, and wherever there are no pointer events). So does this,
|
||||
// from a gesture's start on the canvas to its end, so a long gesture keeps
|
||||
// the input window open the whole way.
|
||||
const GESTURE_MOVE_EVENTS = ['pointermove', 'touchmove'];
|
||||
const GESTURE_END_EVENTS = [
|
||||
'pointerup',
|
||||
'pointercancel',
|
||||
'touchend',
|
||||
'touchcancel',
|
||||
];
|
||||
let followingGesture = false;
|
||||
|
||||
function followGesture(on) {
|
||||
if (followingGesture === on) return;
|
||||
followingGesture = on;
|
||||
const listen = on ? 'addEventListener' : 'removeEventListener';
|
||||
for (const type of GESTURE_MOVE_EVENTS)
|
||||
globalThis.document?.[listen]?.(type, noteCameraInput, { passive: true });
|
||||
for (const type of GESTURE_END_EVENTS)
|
||||
globalThis.document?.[listen]?.(type, endGesture, { passive: true });
|
||||
}
|
||||
|
||||
function endGesture(event) {
|
||||
noteCameraInput(event);
|
||||
followGesture(false);
|
||||
}
|
||||
|
||||
function cameraInputsEnabled() {
|
||||
@@ -160,6 +190,7 @@ export function createLifecycle({
|
||||
noteCameraInput,
|
||||
);
|
||||
layerState.cameraInputTarget = null;
|
||||
followGesture(false);
|
||||
}
|
||||
layerState.preRenderRemover?.();
|
||||
layerState.preRenderRemover = null;
|
||||
|
||||
Reference in new issue
Block a user