Replace MouseWheelZoom Mode enum with typedef
This commit is contained in:
@@ -8,12 +8,8 @@ import {all, always, focusWithTabindex} from '../events/condition.js';
|
|||||||
import {clamp} from '../math.js';
|
import {clamp} from '../math.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @typedef {'trackpad' | 'wheel'} Mode
|
||||||
*/
|
*/
|
||||||
export const Mode = {
|
|
||||||
TRACKPAD: 'trackpad',
|
|
||||||
WHEEL: 'wheel',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
@@ -218,12 +214,12 @@ class MouseWheelZoom extends Interaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) {
|
if (!this.mode_ || now - this.startTime_ > this.trackpadEventGap_) {
|
||||||
this.mode_ = Math.abs(delta) < 4 ? Mode.TRACKPAD : Mode.WHEEL;
|
this.mode_ = Math.abs(delta) < 4 ? 'trackpad' : 'wheel';
|
||||||
}
|
}
|
||||||
|
|
||||||
const view = map.getView();
|
const view = map.getView();
|
||||||
if (
|
if (
|
||||||
this.mode_ === Mode.TRACKPAD &&
|
this.mode_ === 'trackpad' &&
|
||||||
!(view.getConstrainResolution() || this.constrainResolution_)
|
!(view.getConstrainResolution() || this.constrainResolution_)
|
||||||
) {
|
) {
|
||||||
if (this.trackpadTimeoutId_) {
|
if (this.trackpadTimeoutId_) {
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import Event from '../../../../../src/ol/events/Event.js';
|
import Event from '../../../../../src/ol/events/Event.js';
|
||||||
import Map from '../../../../../src/ol/Map.js';
|
import Map from '../../../../../src/ol/Map.js';
|
||||||
import MapBrowserEvent from '../../../../../src/ol/MapBrowserEvent.js';
|
import MapBrowserEvent from '../../../../../src/ol/MapBrowserEvent.js';
|
||||||
import MouseWheelZoom, {
|
import MouseWheelZoom from '../../../../../src/ol/interaction/MouseWheelZoom.js';
|
||||||
Mode,
|
|
||||||
} from '../../../../../src/ol/interaction/MouseWheelZoom.js';
|
|
||||||
import View from '../../../../../src/ol/View.js';
|
import View from '../../../../../src/ol/View.js';
|
||||||
import {DEVICE_PIXEL_RATIO, FIREFOX} from '../../../../../src/ol/has.js';
|
import {DEVICE_PIXEL_RATIO, FIREFOX} from '../../../../../src/ol/has.js';
|
||||||
|
|
||||||
describe('ol.interaction.MouseWheelZoom', function () {
|
describe('ol.interaction.MouseWheelZoom', function () {
|
||||||
let map, interaction;
|
/** @type {Map} */
|
||||||
|
let map;
|
||||||
|
/** @type {MouseWheelZoom} */
|
||||||
|
let interaction;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
interaction = new MouseWheelZoom();
|
interaction = new MouseWheelZoom();
|
||||||
@@ -65,7 +66,7 @@ describe('ol.interaction.MouseWheelZoom', function () {
|
|||||||
if (FIREFOX) {
|
if (FIREFOX) {
|
||||||
it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
|
it('works on Firefox in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
|
||||||
map.once('postrender', function () {
|
map.once('postrender', function () {
|
||||||
expect(interaction.mode_).to.be(Mode.TRACKPAD);
|
expect(interaction.mode_).to.be('trackpad');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
const event = new MapBrowserEvent('wheel', map, {
|
const event = new MapBrowserEvent('wheel', map, {
|
||||||
@@ -83,7 +84,7 @@ describe('ol.interaction.MouseWheelZoom', function () {
|
|||||||
if (!FIREFOX) {
|
if (!FIREFOX) {
|
||||||
it('works in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
|
it('works in DOM_DELTA_PIXEL mode (trackpad)', function (done) {
|
||||||
map.once('postrender', function () {
|
map.once('postrender', function () {
|
||||||
expect(interaction.mode_).to.be(Mode.TRACKPAD);
|
expect(interaction.mode_).to.be('trackpad');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
const event = new MapBrowserEvent('wheel', map, {
|
const event = new MapBrowserEvent('wheel', map, {
|
||||||
|
|||||||
Reference in New Issue
Block a user