Skip to content

Commit

Permalink
WIP: Close #778 move with mouse wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Jan 8, 2023
1 parent 50e4aeb commit 765f270
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/core/src/services/EventsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class EventsHandler extends AbstractService {
longtouchTimeout: null as ReturnType<typeof setTimeout>,
twofingersTimeout: null as ReturnType<typeof setTimeout>,
ctrlZoomTimeout: null as ReturnType<typeof setTimeout>,
wheelTimeout: null as ReturnType<typeof setTimeout>,
lastWheelTime: 0,
};

private readonly keyHandler = new PressHandler();
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 765f270

Please sign in to comment.