Skip to content

Commit e0a9910

Browse files
committed
Add new timeout option to ol.interaction.MouseWheelZoom
And remove the `ol.MOUSEWHEELZOOM_TIMEOUT_DURATION` define.
1 parent 7834a95 commit e0a9910

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

externs/olx.js

+9
Original file line numberDiff line numberDiff line change
@@ -2935,6 +2935,7 @@ olx.interaction.ModifyOptions.prototype.wrapX;
29352935

29362936
/**
29372937
* @typedef {{duration: (number|undefined),
2938+
* timeout: (number|undefined),
29382939
* useAnchor: (boolean|undefined)}}
29392940
*/
29402941
olx.interaction.MouseWheelZoomOptions;
@@ -2948,6 +2949,14 @@ olx.interaction.MouseWheelZoomOptions;
29482949
olx.interaction.MouseWheelZoomOptions.prototype.duration;
29492950

29502951

2952+
/**
2953+
* Mouse wheel timeout duration in milliseconds. Default is `80`.
2954+
* @type {number|undefined}
2955+
* @api
2956+
*/
2957+
olx.interaction.MouseWheelZoomOptions.prototype.timeout;
2958+
2959+
29512960
/**
29522961
* Enable zooming using the mouse's location as the anchor. Default is `true`.
29532962
* When set to false, zooming in and out will zoom to the center of the screen

src/ol/index.js

-6
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ ol.MAX_ATLAS_SIZE = -1;
142142
ol.MOUSEWHEELZOOM_MAXDELTA = 1;
143143

144144

145-
/**
146-
* @define {number} Mouse wheel timeout duration.
147-
*/
148-
ol.MOUSEWHEELZOOM_TIMEOUT_DURATION = 80;
149-
150-
151145
/**
152146
* @define {number} Maximum width and/or height extent ratio that determines
153147
* when the overview map should be zoomed out.

src/ol/interaction/mousewheelzoom.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ ol.interaction.MouseWheelZoom = function(opt_options) {
3636
*/
3737
this.duration_ = options.duration !== undefined ? options.duration : 250;
3838

39+
/**
40+
* @private
41+
* @type {number}
42+
*/
43+
this.timeout_ = options.timeout !== undefined ? options.timeout : 80;
44+
3945
/**
4046
* @private
4147
* @type {boolean}
@@ -109,8 +115,7 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
109115
this.startTime_ = Date.now();
110116
}
111117

112-
var duration = ol.MOUSEWHEELZOOM_TIMEOUT_DURATION;
113-
var timeLeft = Math.max(duration - (Date.now() - this.startTime_), 0);
118+
var timeLeft = Math.max(this.timeout_ - (Date.now() - this.startTime_), 0);
114119

115120
clearTimeout(this.timeoutId_);
116121
this.timeoutId_ = setTimeout(

test/spec/ol/interaction/mousewheelzoom.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,36 @@ describe('ol.interaction.MouseWheelZoom', function() {
2727
disposeMap(map);
2828
});
2929

30+
describe('timeout duration', function() {
31+
var clock;
32+
beforeEach(function() {
33+
clock = sinon.useFakeTimers();
34+
});
35+
36+
afterEach(function() {
37+
clock.restore();
38+
});
39+
40+
it('works with the defaut value', function(done) {
41+
var spy = sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
42+
var event = new ol.MapBrowserEvent('mousewheel', map, {
43+
type: 'mousewheel',
44+
target: map.getViewport(),
45+
preventDefault: ol.events.Event.prototype.preventDefault
46+
});
47+
map.handleMapBrowserEvent(event);
48+
clock.tick(50);
49+
// default timeout is 80 ms, not called yet
50+
expect(spy.called).to.be(false);
51+
clock.tick(30);
52+
expect(spy.called).to.be(true);
53+
54+
ol.interaction.Interaction.zoomByDelta.restore();
55+
done();
56+
});
57+
58+
});
59+
3060
describe('handleEvent()', function() {
3161
it('[wheel] works on Firefox in DOM_DELTA_PIXEL mode', function(done) {
3262
var origHasFirefox = ol.has.FIREFOX;

0 commit comments

Comments
 (0)