From 765f2701b8b640973e6c9bae6b045c5b12bf1c59 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Sun, 8 Jan 2023 10:32:32 +0100 Subject: [PATCH] WIP: Close #778 move with mouse wheel --- packages/core/src/services/EventsHandler.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/core/src/services/EventsHandler.ts b/packages/core/src/services/EventsHandler.ts index 8ad47f6b9..519a318b2 100644 --- a/packages/core/src/services/EventsHandler.ts +++ b/packages/core/src/services/EventsHandler.ts @@ -74,6 +74,8 @@ export class EventsHandler extends AbstractService { longtouchTimeout: null as ReturnType, twofingersTimeout: null as ReturnType, ctrlZoomTimeout: null as ReturnType, + wheelTimeout: null as ReturnType, + lastWheelTime: 0, }; private readonly keyHandler = new PressHandler(); @@ -372,6 +374,22 @@ export class EventsHandler extends AbstractService { const delta = (evt.deltaY / Math.abs(evt.deltaY)) * 5 * this.config.zoomSpeed; if (delta !== 0) { this.viewer.dynamics.zoom.step(-delta, 5); + + if (evt.timeStamp - this.data.lastWheelTime > 200) { + const boundingRect = this.viewer.container.getBoundingClientRect(); + + const viewerX = evt.clientX - boundingRect.left; + const viewerY = evt.clientY - boundingRect.top; + + const position = this.viewer.dataHelper.viewerCoordsToSphericalCoords({ x: viewerX, y: viewerY }); + + this.viewer.dynamics.position.goto(position); + } + + this.data.lastWheelTime = evt.timeStamp; + + clearTimeout(this.data.wheelTimeout); + this.data.wheelTimeout = setTimeout(() => this.viewer.dynamics.position.stop(), 200); } }