diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 2b83662c8a..b8ae5d015f 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -318,6 +318,12 @@ OpenLayers.Map = OpenLayers.Class({ * Default is to fall through. */ fallThrough: true, + + /** + * Property: panTween + * {OpenLayers.Tween} Animated panning tween object, see panTo() + */ + panTween: null, /** * Constructor: OpenLayers.Map diff --git a/lib/OpenLayers/Tween.js b/lib/OpenLayers/Tween.js index d325f793f6..298976a0e3 100644 --- a/lib/OpenLayers/Tween.js +++ b/lib/OpenLayers/Tween.js @@ -58,6 +58,12 @@ OpenLayers.Tween = OpenLayers.Class({ */ interval: null, + /** + * Property: playing + * {Boolean} Tells if the easing is currently playing + */ + playing: false, + /** * Constructor: OpenLayers.Tween * Creates a Tween. @@ -80,6 +86,7 @@ OpenLayers.Tween = OpenLayers.Class({ * options - {Object} hash of options (for example callbacks (start, eachStep, done)) */ start: function(begin, finish, duration, options) { + this.playing = true; this.begin = begin; this.finish = finish; this.duration = duration; @@ -98,14 +105,20 @@ OpenLayers.Tween = OpenLayers.Class({ /** * APIMethod: stop - * Stops the Tween, and calls the finish callback + * Stops the Tween, and calls the done callback + * Doesn't do anything if animation is already finished */ stop: function() { + if (!this.playing) { + return + } + if (this.callbacks && this.callbacks.done) { this.callbacks.done.call(this, this.finish); } window.clearInterval(this.interval); this.interval = null; + this.playing = false; }, /** diff --git a/tests/test_Tween.html b/tests/test_Tween.html index 87e9b9f360..be159a7048 100644 --- a/tests/test_Tween.html +++ b/tests/test_Tween.html @@ -46,12 +46,18 @@ } function test_Tween_stop(t) { - t.plan(1); + t.plan(2); var tween = new OpenLayers.Tween(); tween.interval = window.setInterval(function() {}, 10); + tween.playing = true; tween.stop(); t.eq(tween.interval, null, "tween correctly stopped"); + + tween.interval = window.setInterval(function() {}, 10); + tween.playing = false; + tween.stop(); + t.ok(tween.interval != null, "stop method doesn't do anything if tween isn't running"); }