Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds touchpad gestures support #210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/features/interactions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {MODE_PANNING, MODE_ZOOMING, TOOL_AUTO, TOOL_NONE, TOOL_PAN, TOOL_ZOOM_IN, TOOL_ZOOM_OUT,} from '../constants';
import {getSVGPoint, setFocus} from './common';
import {autoPanIfNeeded, startPanning, stopPanning, updatePanning} from './pan';
import {autoPanIfNeeded, startPanning, stopPanning, updatePanning, pan} from './pan';
import {startZooming, stopZooming, updateZooming, zoom} from './zoom';
import mapRange from '../utils/mapRange';

Expand Down Expand Up @@ -115,16 +115,31 @@ export function onDoubleClick(event, ViewerDOM, tool, value, props, coords = nul

export function onWheel(event, ViewerDOM, tool, value, props, coords = null) {
const {x, y} = coords || getMousePosition(event, ViewerDOM)
const {deltaX, deltaY} = event;

// prohibit touchpad gesture trigger back and forward
event.stopPropagation();
event.preventDefault();


if (!props.detectWheel) return value;

let delta = Math.max(-1, Math.min(1, event.deltaY));
let scaleFactor = mapRange(delta, -1, 1, props.scaleFactorOnWheel, 1 / props.scaleFactorOnWheel);

let SVGPoint = getSVGPoint(value, x, y);
let nextValue = zoom(value, SVGPoint.x, SVGPoint.y, scaleFactor, props);
let nextValue
// event.ctrlKey is necessary to handle pinch zooming
if (event.metaKey || event.ctrlKey) {
nextValue = zoom(value, SVGPoint.x, SVGPoint.y, scaleFactor, props)
} else if (event.shiftKey) {
// scroll horizontally when shift pressed
nextValue = pan(value, -(deltaY || deltaX), 0)
}
else {
nextValue = pan(value, -deltaX, -deltaY)
}

event.preventDefault();
return nextValue;
}

Expand Down