Skip to content

Commit

Permalink
Fix issues with slow scrolling and improper panning on windows
Browse files Browse the repository at this point in the history
(closes #5512)
  • Loading branch information
bhousel committed Dec 1, 2018
1 parent 2e6652f commit 4f8f45e
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions modules/renderer/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
} from '../util';

import { utilBindOnce } from '../util/bind_once';
import { utilDetect } from '../util/detect';
import { utilGetDimensions } from '../util/dimensions';


Expand Down Expand Up @@ -413,6 +414,7 @@ export function rendererMap(context) {
// They might be triggered by the user scrolling the mouse wheel,
// or 2-finger pinch/zoom gestures, the transform may need adjustment.
if (source && source.type === 'wheel') {
var detected = utilDetect();
var dX = source.deltaX;
var dY = source.deltaY;
var x2 = x;
Expand All @@ -429,9 +431,20 @@ export function rendererMap(context) {
if (source.deltaMode === 1 /* LINE */) {
// Convert from lines to pixels, more if the user is scrolling fast.
// (I made up the exp function to roughly match Firefox to what Chrome does)
var lines = clamp(Math.abs(source.deltaY), 0, 12);
var lines = Math.abs(source.deltaY);
var sign = (source.deltaY > 0) ? 1 : -1;
dY = sign * Math.exp((lines - 1) * 0.5) * 4.000244140625;
dY = sign * clamp(
Math.exp((lines - 1) * 0.75) * 4.000244140625,
4.000244140625, // min
350.000244140625 // max
);

// On Firefox/Windows we just always get +/- the scroll line amount (default 3)
// There doesn't seem to be any scroll accelleration.
// This multiplier increases the speed a little bit - #5512
if (detected.os === 'win') {
dY *= 5;
}

// recalculate x2,y2,k2
t0 = _transformed ? _transformLast : _transformStart;
Expand Down Expand Up @@ -478,15 +491,19 @@ export function rendererMap(context) {
x2 = p0[0] - p1[0] * k2;
y2 = p0[1] - p1[1] * k2;

// 2 finger map panning (all browsers) - #5492
// 2 finger map panning (Mac only, all browsers) - #5492, #5512
// Panning via the `wheel` event will always have:
// - `ctrlKey = false`
// - `deltaX`,`deltaY` are round integer pixels
} else if (!source.ctrlKey && isInteger(dX) && isInteger(dY)) {
p1 = projection.translate();
x2 = p1[0] - dX;
y2 = p1[1] - dY;
k2 = projection.scale();
} else if (detected.os === 'mac' && !source.ctrlKey && isInteger(dX) && isInteger(dY)) {
// Firefox will set `mozInputSource = 1` if the event was generated
// by an actual mouse wheel. If we detect this, don't pan..
if (source.mozInputSource === undefined || source.mozInputSource !== 1) {
p1 = projection.translate();
x2 = p1[0] - dX;
y2 = p1[1] - dY;
k2 = projection.scale();
}
}

// something changed - replace the event transform
Expand Down

0 comments on commit 4f8f45e

Please sign in to comment.