Add getCompletionCallback method.

This commit is contained in:
Antoine Vandecreme 2015-06-02 12:59:38 -04:00
parent 4c1d0f9a4c
commit be657c0b3d

View File

@ -976,11 +976,16 @@ function onTileLoad( tiledImage, tile, time, image ) {
} }
function setTileLoaded(tiledImage, tile, image, cutoff) { function setTileLoaded(tiledImage, tile, image, cutoff) {
tiledImage.viewer.raiseEvent("tile-loaded", { var increment = 0;
tile: tile,
tiledImage: tiledImage, function getCompletionCallback() {
image: image increment++;
}); return completionCallback;
}
function completionCallback() {
increment--;
if (increment === 0) {
tile.loading = false; tile.loading = false;
tile.loaded = true; tile.loaded = true;
tiledImage._tileCache.cacheTile({ tiledImage._tileCache.cacheTile({
@ -990,6 +995,33 @@ function setTileLoaded(tiledImage, tile, image, cutoff) {
tiledImage: tiledImage tiledImage: tiledImage
}); });
} }
}
/**
* Triggered when a tile has just been loaded in memory. That means that the
* image has been downloaded and can be modified asynchronously before being
* drawn to the canvas.
*
* @event tile-loaded
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {Image} image - The image of the tile.
* @property {OpenSeadragon.TiledImage} tiledImage - The tiled image of the loaded tile.
* @property {OpenSeadragon.Tile} tile - The tile which has been loaded.
* @property {function} getCompletionCallback - A function giving a callback to call
* when the asynchronous processing of the image is done. The image will be
* marked as entirely loaded once the callback has been called as many times as
* getCompletionCallback
*/
tiledImage.viewer.raiseEvent("tile-loaded", {
tile: tile,
tiledImage: tiledImage,
image: image,
getCompletionCallback: getCompletionCallback
});
// In case the completion callback is never called, we at least force it once.
getCompletionCallback()();
}
function positionTile( tile, overlap, viewport, viewportCenter, levelVisibility, tiledImage ){ function positionTile( tile, overlap, viewport, viewportCenter, levelVisibility, tiledImage ){
var boundsTL = tile.bounds.getTopLeft(); var boundsTL = tile.bounds.getTopLeft();