mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 13:16:10 +03:00
Merge pull request #2282 from RationAI/master
Ensure tile-loaded event completionCallback is called only once.
This commit is contained in:
commit
3cf3fb50b2
@ -1656,9 +1656,14 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
*/
|
*/
|
||||||
_setTileLoaded: function(tile, data, cutoff, tileRequest) {
|
_setTileLoaded: function(tile, data, cutoff, tileRequest) {
|
||||||
var increment = 0,
|
var increment = 0,
|
||||||
|
eventFinished = false,
|
||||||
_this = this;
|
_this = this;
|
||||||
|
|
||||||
function getCompletionCallback() {
|
function getCompletionCallback() {
|
||||||
|
if (eventFinished) {
|
||||||
|
$.console.error("Event 'tile-loaded' argument getCompletionCallback must be called synchronously. " +
|
||||||
|
"Its return value should be called asynchronously.");
|
||||||
|
}
|
||||||
increment++;
|
increment++;
|
||||||
return completionCallback;
|
return completionCallback;
|
||||||
}
|
}
|
||||||
@ -1700,6 +1705,8 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
* marked as entirely loaded when the callback has been called once for each
|
* marked as entirely loaded when the callback has been called once for each
|
||||||
* call to getCompletionCallback.
|
* call to getCompletionCallback.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var fallbackCompletion = getCompletionCallback();
|
||||||
this.viewer.raiseEvent("tile-loaded", {
|
this.viewer.raiseEvent("tile-loaded", {
|
||||||
tile: tile,
|
tile: tile,
|
||||||
tiledImage: this,
|
tiledImage: this,
|
||||||
@ -1711,8 +1718,9 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
|
|||||||
data: data,
|
data: data,
|
||||||
getCompletionCallback: getCompletionCallback
|
getCompletionCallback: getCompletionCallback
|
||||||
});
|
});
|
||||||
|
eventFinished = true;
|
||||||
// In case the completion callback is never called, we at least force it once.
|
// In case the completion callback is never called, we at least force it once.
|
||||||
getCompletionCallback()();
|
fallbackCompletion();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user