diff --git a/src/viewer.js b/src/viewer.js index f0b698b8..af4b1822 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -115,6 +115,7 @@ $.Viewer = function( options ) { THIS[ this.hash ] = { "fsBoundsDelta": new $.Point( 1, 1 ), "prevContainerSize": null, + "updateRequestId": null, "animating": false, "forceRedraw": false, "mouseInside": false, @@ -353,7 +354,11 @@ $.extend( $.Viewer.prototype, $.EventHandler.prototype, $.ControlDock.prototype, * @return {OpenSeadragon.Viewer} Chainable. */ close: function ( ) { - + if ( THIS[ this.hash ].updateRequestId !== null ){ + $.cancelAnimationFrame( THIS[ this.hash ].updateRequestId ); + THIS[ this.hash ].updateRequestId = null; + } + if( this.drawer ){ this.drawer.clearOverlays(); } @@ -1064,7 +1069,7 @@ function openTileSource( viewer, source ) { THIS[ _this.hash ].animating = false; THIS[ _this.hash ].forceRedraw = true; - scheduleUpdate( _this, updateMulti ); + THIS[ _this.hash ].updateRequestId = scheduleUpdate( _this, updateMulti ); //Assuming you had programatically created a bunch of overlays //and added them via configuration @@ -1338,13 +1343,11 @@ function updateMulti( viewer ) { var beginTime; - if ( !viewer.source ) { - return; - } - beginTime = +new Date(); updateOnce( viewer ); - scheduleUpdate( viewer, arguments.callee, beginTime ); + + THIS[ viewer.hash ].updateRequestId = scheduleUpdate( viewer, + arguments.callee, beginTime ); } function updateOnce( viewer ) {