Make zoom control animation duration configurable

This commit is contained in:
Tom Payne
2013-10-07 15:35:52 +02:00
parent 37a7ac1f5b
commit 214e578333
2 changed files with 14 additions and 11 deletions

View File

@@ -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);
}