fix: Scrolling to zoom in embedded map causes containing page to scroll (#376)

This commit is contained in:
Owen Diffey 2022-12-31 08:44:00 +00:00 committed by GitHub
parent 4bef77d54b
commit 18b4b0b220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -78,7 +78,7 @@ export class FreeFlightControls {
this.target.addEventListener("contextmenu", this.onContextMenu); this.target.addEventListener("contextmenu", this.onContextMenu);
this.target.addEventListener("mousedown", this.onMouseDown); this.target.addEventListener("mousedown", this.onMouseDown);
this.target.addEventListener("mouseup", this.onMouseUp); this.target.addEventListener("mouseup", this.onMouseUp);
window.addEventListener("wheel", this.onWheel, {passive: true}); window.addEventListener("wheel", this.onWheel, {passive: false});
} }
stop() { stop() {
@ -134,6 +134,8 @@ export class FreeFlightControls {
} }
onWheel = evt => { onWheel = evt => {
evt.preventDefault();
let delta = evt.deltaY; let delta = evt.deltaY;
if (evt.deltaMode === WheelEvent.DOM_DELTA_PIXEL) delta *= 0.01; if (evt.deltaMode === WheelEvent.DOM_DELTA_PIXEL) delta *= 0.01;
if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE) delta *= 0.33; if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE) delta *= 0.33;

View File

@ -48,7 +48,7 @@ export class MouseZoomControls {
start(manager) { start(manager) {
this.manager = manager; this.manager = manager;
this.target.addEventListener("wheel", this.onMouseWheel, {passive: true}); this.target.addEventListener("wheel", this.onMouseWheel, {passive: false});
} }
stop() { stop() {
@ -82,6 +82,8 @@ export class MouseZoomControls {
* @param evt {WheelEvent} * @param evt {WheelEvent}
*/ */
onMouseWheel = evt => { onMouseWheel = evt => {
evt.preventDefault();
let delta = evt.deltaY; let delta = evt.deltaY;
if (evt.deltaMode === WheelEvent.DOM_DELTA_PIXEL) delta *= 0.01; if (evt.deltaMode === WheelEvent.DOM_DELTA_PIXEL) delta *= 0.01;
if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE) delta *= 0.33; if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE) delta *= 0.33;