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
+1
View File
@@ -217,6 +217,7 @@
/** /**
* @typedef {Object} ol.control.ZoomOptions * @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 {string|undefined} className CSS class name. Default is `ol-zoom`.
* @property {number|undefined} delta The zoom delta applied on each click. * @property {number|undefined} delta The zoom delta applied on each click.
* @property {Element|undefined} target Target. * @property {Element|undefined} target Target.
+13 -11
View File
@@ -12,12 +12,6 @@ goog.require('ol.css');
goog.require('ol.easing'); 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. * 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 target: options.target
}); });
/**
* @type {number}
* @private
*/
this.duration_ = goog.isDef(options.duration) ? options.duration : 250;
}; };
goog.inherits(ol.control.Zoom, ol.control.Control); 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 view = map.getView().getView2D();
var currentResolution = view.getResolution(); var currentResolution = view.getResolution();
if (goog.isDef(currentResolution)) { if (goog.isDef(currentResolution)) {
map.beforeRender(ol.animation.zoom({ if (this.duration_ > 0) {
resolution: currentResolution, map.beforeRender(ol.animation.zoom({
duration: ol.control.ZOOM_DURATION, resolution: currentResolution,
easing: ol.easing.easeOut duration: this.duration_,
})); easing: ol.easing.easeOut
}));
}
var newResolution = view.constrainResolution(currentResolution, delta); var newResolution = view.constrainResolution(currentResolution, delta);
view.setResolution(newResolution); view.setResolution(newResolution);
} }