diff --git a/externs/olx.js b/externs/olx.js index 5d9bd288f5..178ffc19f2 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -3104,6 +3104,13 @@ olx.interaction.PinchZoomOptions; */ olx.interaction.PinchZoomOptions.prototype.duration; +/** + * Zoom to the closest integer zoom level after the pinch gesture ends. Default is `false`. + * @type {boolean|undefined} + * @api + */ +olx.interaction.PinchZoomOptions.prototype.constrainResolution; + /** * @typedef {{handleDownEvent: (function(ol.MapBrowserPointerEvent):boolean|undefined), @@ -7613,7 +7620,7 @@ olx.view.FitOptions.prototype.maxZoom; /** - * The duration of the animation in milliseconds. By default, there is no + * The duration of the animation in milliseconds. By default, there is no * animations. * @type {number|undefined} * @api diff --git a/src/ol/interaction/pinchzoom.js b/src/ol/interaction/pinchzoom.js index ac0bc45f3a..412cc7ce12 100644 --- a/src/ol/interaction/pinchzoom.js +++ b/src/ol/interaction/pinchzoom.js @@ -27,6 +27,12 @@ ol.interaction.PinchZoom = function(opt_options) { var options = opt_options ? opt_options : {}; + /** + * @private + * @type {boolean} + */ + this.constrainResolution_ = options.constrainResolution || false; + /** * @private * @type {ol.Coordinate} @@ -111,13 +117,15 @@ ol.interaction.PinchZoom.handleUpEvent_ = function(mapBrowserEvent) { var map = mapBrowserEvent.map; var view = map.getView(); view.setHint(ol.View.Hint.INTERACTING, -1); - var resolution = view.getResolution(); - // Zoom to final resolution, with an animation, and provide a - // direction not to zoom out/in if user was pinching in/out. - // Direction is > 0 if pinching out, and < 0 if pinching in. - var direction = this.lastScaleDelta_ - 1; - ol.interaction.Interaction.zoom(map, view, resolution, - this.anchor_, this.duration_, direction); + if (this.constrainResolution_) { + var resolution = view.getResolution(); + // Zoom to final resolution, with an animation, and provide a + // direction not to zoom out/in if user was pinching in/out. + // Direction is > 0 if pinching out, and < 0 if pinching in. + var direction = this.lastScaleDelta_ - 1; + ol.interaction.Interaction.zoom(map, view, resolution, + this.anchor_, this.duration_, direction); + } return false; } else { return true;