From f6ad883db65bb78144058c6e20459cc33fd27ff2 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 6 Nov 2016 08:29:05 -0700 Subject: [PATCH] Use view.animate() to auto-pan an overlay --- externs/olx.js | 14 +++++++------- src/ol/overlay.js | 15 +++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 2a70979cf4..12b5767ec4 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -398,9 +398,9 @@ olx.OverlayOptions.prototype.autoPan; /** - * The options used to create a `ol.animation.pan` animation. This animation - * is only used when `autoPan` is enabled. By default the default options for - * `ol.animation.pan` are used. If set to `null` the panning is not animated. + * The animation options used to pan the overlay into view. This animation + * is only used when `autoPan` is enabled. A `duration` and `easing` may be + * provided to customize the animation. * @type {olx.animation.PanOptions|undefined} * @api */ @@ -787,10 +787,10 @@ olx.animation.BounceOptions.prototype.easing; /** - * @typedef {{source: ol.Coordinate, - * start: (number|undefined), - * duration: (number|undefined), - * easing: (function(number):number|undefined)}} + * @typedef {{ + * duration: (number|undefined), + * easing: (function(number):number|undefined) + * }} */ olx.animation.PanOptions; diff --git a/src/ol/overlay.js b/src/ol/overlay.js index 635fae8aa5..1cecab6717 100644 --- a/src/ol/overlay.js +++ b/src/ol/overlay.js @@ -3,7 +3,6 @@ goog.provide('ol.Overlay'); goog.require('ol'); goog.require('ol.MapEvent'); goog.require('ol.Object'); -goog.require('ol.animation'); goog.require('ol.dom'); goog.require('ol.events'); goog.require('ol.extent'); @@ -71,8 +70,8 @@ ol.Overlay = function(options) { * @private * @type {olx.animation.PanOptions} */ - this.autoPanAnimation_ = options.autoPanAnimation !== undefined ? - options.autoPanAnimation : /** @type {olx.animation.PanOptions} */ ({}); + this.autoPanAnimation_ = options.autoPanAnimation || + /** @type {olx.animation.PanOptions} */ ({}); /** * @private @@ -380,11 +379,11 @@ ol.Overlay.prototype.panIntoView_ = function() { centerPx[1] + delta[1] ]; - if (this.autoPanAnimation_) { - this.autoPanAnimation_.source = center; - map.beforeRender(ol.animation.pan(this.autoPanAnimation_)); - } - map.getView().setCenter(map.getCoordinateFromPixel(newCenterPx)); + map.getView().animate({ + center: map.getCoordinateFromPixel(newCenterPx), + duration: this.autoPanAnimation_.duration, + easing: this.autoPanAnimation_.easing + }); } } };