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

Trackpad zoom by 1 too when view has a zoom constraint #15425

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/ol/interaction/MouseWheelZoom.js
Expand Up @@ -150,19 +150,19 @@ class MouseWheelZoom extends Interaction {

/**
* @private
* @param {import("../View.js").default} view View.
*/
endInteraction_() {
this.trackpadTimeoutId_ = undefined;
const map = this.getMap();
if (!map) {
return;
}
const view = map.getView();
endInteraction_(view) {
view.endInteraction(
undefined,
this.lastDelta_ ? (this.lastDelta_ > 0 ? 1 : -1) : 0,
this.lastAnchor_
);

this.trackpadTimeoutId_ = undefined;
this.mode_ = undefined;
this.lastAnchor_ = null;
this.startTime_ = undefined;
}

/**
Expand Down Expand Up @@ -221,7 +221,7 @@ class MouseWheelZoom extends Interaction {
const view = map.getView();
if (
this.mode_ === 'trackpad' &&
!(view.getConstrainResolution() || this.constrainResolution_)
(view.getConstrainResolution() || this.constrainResolution_)
) {
if (this.trackpadTimeoutId_) {
clearTimeout(this.trackpadTimeoutId_);
Expand All @@ -232,7 +232,7 @@ class MouseWheelZoom extends Interaction {
view.beginInteraction();
}
this.trackpadTimeoutId_ = setTimeout(
this.endInteraction_.bind(this),
this.endInteraction_.bind(this, view),
this.timeout_
);
view.adjustZoom(-delta / this.deltaPerZoom_, this.lastAnchor_);
Expand All @@ -246,7 +246,7 @@ class MouseWheelZoom extends Interaction {

clearTimeout(this.timeoutId_);
this.timeoutId_ = setTimeout(
this.handleWheelZoom_.bind(this, map),
this.handleWheelZoom_.bind(this, view),
timeLeft
);

Expand All @@ -255,10 +255,9 @@ class MouseWheelZoom extends Interaction {

/**
* @private
* @param {import("../Map.js").default} map Map.
* @param {import("../View.js").default} view View.
*/
handleWheelZoom_(map) {
const view = map.getView();
handleWheelZoom_(view) {
if (view.getAnimating()) {
view.cancelAnimations();
}
Expand All @@ -274,11 +273,11 @@ class MouseWheelZoom extends Interaction {
}
zoomByDelta(view, delta, this.lastAnchor_, this.duration_);

this.timeoutId_ = undefined;
this.mode_ = undefined;
this.totalDelta_ = 0;
this.lastAnchor_ = null;
this.startTime_ = undefined;
this.timeoutId_ = undefined;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/browser/spec/ol/interaction/mousewheelzoom.test.js
Expand Up @@ -65,6 +65,7 @@ describe('ol.interaction.MouseWheelZoom', function () {
describe('handleEvent()', function () {
if (FIREFOX) {
it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
map.getView().setConstrainResolution(true);
map.once('postrender', function () {
expect(interaction.mode_).to.be('trackpad');
done();
Expand All @@ -83,6 +84,7 @@ describe('ol.interaction.MouseWheelZoom', function () {

if (!FIREFOX) {
it('works in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
map.getView().setConstrainResolution(true);
map.once('postrender', function () {
expect(interaction.mode_).to.be('trackpad');
done();
Expand Down