Make zoom control animation duration configurable
This commit is contained in:
@@ -217,6 +217,7 @@
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.ZoomOptions
|
||||
* @property {number|undefined} duration Animation duration. Default is 250ms.
|
||||
* @property {string|undefined} className CSS class name. Default is `ol-zoom`.
|
||||
* @property {number|undefined} delta The zoom delta applied on each click.
|
||||
* @property {Element|undefined} target Target.
|
||||
|
||||
@@ -12,12 +12,6 @@ goog.require('ol.css');
|
||||
goog.require('ol.easing');
|
||||
|
||||
|
||||
/**
|
||||
* @define {number} Zoom duration.
|
||||
*/
|
||||
ol.control.ZOOM_DURATION = 250;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new control with 2 buttons, one for zoom in and one for zoom out.
|
||||
@@ -62,6 +56,12 @@ ol.control.Zoom = function(opt_options) {
|
||||
target: options.target
|
||||
});
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.duration_ = goog.isDef(options.duration) ? options.duration : 250;
|
||||
|
||||
};
|
||||
goog.inherits(ol.control.Zoom, ol.control.Control);
|
||||
|
||||
@@ -79,11 +79,13 @@ ol.control.Zoom.prototype.zoomByDelta_ = function(delta, browserEvent) {
|
||||
var view = map.getView().getView2D();
|
||||
var currentResolution = view.getResolution();
|
||||
if (goog.isDef(currentResolution)) {
|
||||
map.beforeRender(ol.animation.zoom({
|
||||
resolution: currentResolution,
|
||||
duration: ol.control.ZOOM_DURATION,
|
||||
easing: ol.easing.easeOut
|
||||
}));
|
||||
if (this.duration_ > 0) {
|
||||
map.beforeRender(ol.animation.zoom({
|
||||
resolution: currentResolution,
|
||||
duration: this.duration_,
|
||||
easing: ol.easing.easeOut
|
||||
}));
|
||||
}
|
||||
var newResolution = view.constrainResolution(currentResolution, delta);
|
||||
view.setResolution(newResolution);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user