diff --git a/externs/olx.js b/externs/olx.js index 6317e51f55..ddcb7bea89 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -3110,6 +3110,14 @@ olx.interaction.MouseWheelZoomOptions.prototype.duration; olx.interaction.MouseWheelZoomOptions.prototype.timeout; +/** + * Zoom to the closest integer zoom level after trackpad zoom ends. Default is `false`. + * @type {boolean|undefined} + * @api + */ +olx.interaction.MouseWheelZoomOptions.prototype.constrainResolution; + + /** * 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 diff --git a/src/ol/interaction/mousewheelzoom.js b/src/ol/interaction/mousewheelzoom.js index 1abdae100b..8068075409 100644 --- a/src/ol/interaction/mousewheelzoom.js +++ b/src/ol/interaction/mousewheelzoom.js @@ -50,6 +50,12 @@ ol.interaction.MouseWheelZoom = function(opt_options) { */ this.useAnchor_ = options.useAnchor !== undefined ? options.useAnchor : true; + /** + * @private + * @type {boolean} + */ + this.constrainResolution_ = options.constrainResolution || false; + /** * @private * @type {?ol.Coordinate} @@ -186,6 +192,16 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) { view.setCenter(view.constrainCenter(center)); } view.setResolution(resolution); + + if (rebound === 0 && this.constrainResolution_) { + view.animate({ + resolution: view.constrainResolution(resolution, delta > 0 ? -1 : 1), + easing: ol.easing.easeOut, + anchor: this.lastAnchor_, + duration: this.duration_ + }); + } + if (rebound > 0) { view.animate({ resolution: minResolution,