Add constraintResolution option to MouseWheelZoom for zoom with trackpad
This commit is contained in:
@@ -3109,6 +3109,14 @@ olx.interaction.MouseWheelZoomOptions.prototype.duration;
|
|||||||
olx.interaction.MouseWheelZoomOptions.prototype.timeout;
|
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`.
|
* 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
|
* When set to false, zooming in and out will zoom to the center of the screen
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ ol.interaction.MouseWheelZoom = function(opt_options) {
|
|||||||
*/
|
*/
|
||||||
this.useAnchor_ = options.useAnchor !== undefined ? options.useAnchor : true;
|
this.useAnchor_ = options.useAnchor !== undefined ? options.useAnchor : true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.constrainResolution_ = options.constrainResolution || false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {?ol.Coordinate}
|
* @type {?ol.Coordinate}
|
||||||
@@ -186,6 +192,16 @@ ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
|
|||||||
view.setCenter(view.constrainCenter(center));
|
view.setCenter(view.constrainCenter(center));
|
||||||
}
|
}
|
||||||
view.setResolution(resolution);
|
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) {
|
if (rebound > 0) {
|
||||||
view.animate({
|
view.animate({
|
||||||
resolution: minResolution,
|
resolution: minResolution,
|
||||||
|
|||||||
Reference in New Issue
Block a user