Make zoom control animation duration configurable
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user