add an option to make the pinchZoom constrain zoom levels to integers
Changes the default behavior of ol.interaction.PinchZoom to keep the fractional zoom level after the gesture. The old behavior of zooming to the next whole-number level can be enforced with the new parameter `constrainResolution`.
This commit is contained in:
@@ -3104,6 +3104,13 @@ olx.interaction.PinchZoomOptions;
|
|||||||
*/
|
*/
|
||||||
olx.interaction.PinchZoomOptions.prototype.duration;
|
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),
|
* @typedef {{handleDownEvent: (function(ol.MapBrowserPointerEvent):boolean|undefined),
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ ol.interaction.PinchZoom = function(opt_options) {
|
|||||||
|
|
||||||
var options = opt_options ? opt_options : {};
|
var options = opt_options ? opt_options : {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.constrainResolution_ = options.constrainResolution || false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Coordinate}
|
* @type {ol.Coordinate}
|
||||||
@@ -111,6 +117,7 @@ ol.interaction.PinchZoom.handleUpEvent_ = function(mapBrowserEvent) {
|
|||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
var view = map.getView();
|
var view = map.getView();
|
||||||
view.setHint(ol.View.Hint.INTERACTING, -1);
|
view.setHint(ol.View.Hint.INTERACTING, -1);
|
||||||
|
if (this.constrainResolution_) {
|
||||||
var resolution = view.getResolution();
|
var resolution = view.getResolution();
|
||||||
// Zoom to final resolution, with an animation, and provide a
|
// Zoom to final resolution, with an animation, and provide a
|
||||||
// direction not to zoom out/in if user was pinching in/out.
|
// direction not to zoom out/in if user was pinching in/out.
|
||||||
@@ -118,6 +125,7 @@ ol.interaction.PinchZoom.handleUpEvent_ = function(mapBrowserEvent) {
|
|||||||
var direction = this.lastScaleDelta_ - 1;
|
var direction = this.lastScaleDelta_ - 1;
|
||||||
ol.interaction.Interaction.zoom(map, view, resolution,
|
ol.interaction.Interaction.zoom(map, view, resolution,
|
||||||
this.anchor_, this.duration_, direction);
|
this.anchor_, this.duration_, direction);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user