Add constraintResolution option to MouseWheelZoom for zoom with trackpad

This commit is contained in:
Kai Culemann
2017-04-04 15:06:08 +02:00
parent 350b42ad91
commit c1adde6a13
2 changed files with 24 additions and 0 deletions

View File

@@ -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

View File

@@ -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,