View2D zoom may animate pan

This commit is contained in:
Éric Lemoine
2013-02-20 16:51:48 +01:00
parent 57a86353cd
commit 3ba9a4afd4
+13 -2
View File
@@ -4,6 +4,7 @@
goog.provide('ol.View2D'); goog.provide('ol.View2D');
goog.provide('ol.View2DProperty'); goog.provide('ol.View2DProperty');
goog.require('goog.fx.easing');
goog.require('ol.Constraints'); goog.require('ol.Constraints');
goog.require('ol.Coordinate'); goog.require('ol.Coordinate');
goog.require('ol.Extent'); goog.require('ol.Extent');
@@ -312,12 +313,22 @@ ol.View2D.prototype.zoom_ = function(map, resolution, opt_anchor) {
*/ */
ol.View2D.prototype.zoom = function(map, delta, opt_anchor, opt_duration) { ol.View2D.prototype.zoom = function(map, delta, opt_anchor, opt_duration) {
var currentResolution = this.getResolution(); var currentResolution = this.getResolution();
if (goog.isDef(currentResolution) && goog.isDef(opt_duration)) { var currentCenter = this.getCenter();
if (goog.isDef(currentResolution) && goog.isDef(currentCenter) &&
goog.isDef(opt_duration)) {
map.requestRenderFrame(); map.requestRenderFrame();
map.addPreRenderFunction(ol.animation.zoom({ map.addPreRenderFunction(ol.animation.zoom({
resolution: currentResolution, resolution: currentResolution,
duration: opt_duration duration: opt_duration,
easing: goog.fx.easing.easeOut
})); }));
if (goog.isDef(opt_anchor)) {
map.addPreRenderFunction(ol.animation.pan({
source: currentCenter,
duration: opt_duration,
easing: goog.fx.easing.easeOut
}));
}
} }
var resolution = this.constraints_.resolution(currentResolution, delta); var resolution = this.constraints_.resolution(currentResolution, delta);
this.zoom_(map, resolution, opt_anchor); this.zoom_(map, resolution, opt_anchor);