Add new timeout option to ol.interaction.MouseWheelZoom
And remove the `ol.MOUSEWHEELZOOM_TIMEOUT_DURATION` define.
This commit is contained in:
@@ -2935,6 +2935,7 @@ olx.interaction.ModifyOptions.prototype.wrapX;
|
||||
|
||||
/**
|
||||
* @typedef {{duration: (number|undefined),
|
||||
* timeout: (number|undefined),
|
||||
* useAnchor: (boolean|undefined)}}
|
||||
*/
|
||||
olx.interaction.MouseWheelZoomOptions;
|
||||
@@ -2948,6 +2949,14 @@ olx.interaction.MouseWheelZoomOptions;
|
||||
olx.interaction.MouseWheelZoomOptions.prototype.duration;
|
||||
|
||||
|
||||
/**
|
||||
* Mouse wheel timeout duration in milliseconds. Default is `80`.
|
||||
* @type {number|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.interaction.MouseWheelZoomOptions.prototype.timeout;
|
||||
|
||||
|
||||
/**
|
||||
* Enable zooming using the mouse's location as the anchor. Default is `true`.
|
||||
* When set to false, zooming in and out will zoom to the center of the screen
|
||||
|
||||
@@ -142,12 +142,6 @@ ol.MAX_ATLAS_SIZE = -1;
|
||||
ol.MOUSEWHEELZOOM_MAXDELTA = 1;
|
||||
|
||||
|
||||
/**
|
||||
* @define {number} Mouse wheel timeout duration.
|
||||
*/
|
||||
ol.MOUSEWHEELZOOM_TIMEOUT_DURATION = 80;
|
||||
|
||||
|
||||
/**
|
||||
* @define {number} Maximum width and/or height extent ratio that determines
|
||||
* when the overview map should be zoomed out.
|
||||
|
||||
@@ -36,6 +36,12 @@ ol.interaction.MouseWheelZoom = function(opt_options) {
|
||||
*/
|
||||
this.duration_ = options.duration !== undefined ? options.duration : 250;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.timeout_ = options.timeout !== undefined ? options.timeout : 80;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
@@ -109,8 +115,7 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
|
||||
this.startTime_ = Date.now();
|
||||
}
|
||||
|
||||
var duration = ol.MOUSEWHEELZOOM_TIMEOUT_DURATION;
|
||||
var timeLeft = Math.max(duration - (Date.now() - this.startTime_), 0);
|
||||
var timeLeft = Math.max(this.timeout_ - (Date.now() - this.startTime_), 0);
|
||||
|
||||
clearTimeout(this.timeoutId_);
|
||||
this.timeoutId_ = setTimeout(
|
||||
|
||||
@@ -27,6 +27,36 @@ describe('ol.interaction.MouseWheelZoom', function() {
|
||||
disposeMap(map);
|
||||
});
|
||||
|
||||
describe('timeout duration', function() {
|
||||
var clock;
|
||||
beforeEach(function() {
|
||||
clock = sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
it('works with the defaut value', function(done) {
|
||||
var spy = sinon.spy(ol.interaction.Interaction, 'zoomByDelta');
|
||||
var event = new ol.MapBrowserEvent('mousewheel', map, {
|
||||
type: 'mousewheel',
|
||||
target: map.getViewport(),
|
||||
preventDefault: ol.events.Event.prototype.preventDefault
|
||||
});
|
||||
map.handleMapBrowserEvent(event);
|
||||
clock.tick(50);
|
||||
// default timeout is 80 ms, not called yet
|
||||
expect(spy.called).to.be(false);
|
||||
clock.tick(30);
|
||||
expect(spy.called).to.be(true);
|
||||
|
||||
ol.interaction.Interaction.zoomByDelta.restore();
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('handleEvent()', function() {
|
||||
it('[wheel] works on Firefox in DOM_DELTA_PIXEL mode', function(done) {
|
||||
var origHasFirefox = ol.has.FIREFOX;
|
||||
|
||||
Reference in New Issue
Block a user