mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-22 05:06:09 +03:00
Merge branch 'rdlester-imageLoaderPatch'
This commit is contained in:
commit
ffac82ce60
100
src/drawer.js
100
src/drawer.js
@ -730,23 +730,10 @@ function loadTile( drawer, tile, time ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onTileLoad( drawer, tile, time, image ) {
|
function onTileLoad( drawer, tile, time, image ) {
|
||||||
var insertionIndex,
|
|
||||||
cutoff,
|
|
||||||
worstTile,
|
|
||||||
worstTime,
|
|
||||||
worstLevel,
|
|
||||||
worstTileIndex,
|
|
||||||
prevTile,
|
|
||||||
prevTime,
|
|
||||||
prevLevel,
|
|
||||||
i;
|
|
||||||
|
|
||||||
tile.loading = false;
|
tile.loading = false;
|
||||||
|
|
||||||
if ( drawer.midUpdate ) {
|
if ( !image && !drawer.viewport.collectionMode ) {
|
||||||
$.console.warn( "Tile load callback in middle of drawing routine." );
|
|
||||||
return;
|
|
||||||
} else if ( !image && !drawer.viewport.collectionMode ) {
|
|
||||||
$.console.log( "Tile %s failed to load: %s", tile, tile.url );
|
$.console.log( "Tile %s failed to load: %s", tile, tile.url );
|
||||||
if( !drawer.debugMode ){
|
if( !drawer.debugMode ){
|
||||||
tile.exists = false;
|
tile.exists = false;
|
||||||
@ -760,47 +747,64 @@ function onTileLoad( drawer, tile, time, image ) {
|
|||||||
tile.loaded = true;
|
tile.loaded = true;
|
||||||
tile.image = image;
|
tile.image = image;
|
||||||
|
|
||||||
insertionIndex = drawer.tilesLoaded.length;
|
if ( drawer.tilesLoaded.length < drawer.maxImageCacheCount ) {
|
||||||
|
// always safe to append things to cache
|
||||||
if ( drawer.tilesLoaded.length >= drawer.maxImageCacheCount ) {
|
drawer.tilesLoaded[ drawer.tilesLoaded.length ] = tile;
|
||||||
cutoff = Math.ceil( Math.log( drawer.source.getTileSize(tile.level) ) / Math.log( 2 ) );
|
}
|
||||||
|
else {
|
||||||
worstTile = null;
|
// need to remove something from cache,
|
||||||
worstTileIndex = -1;
|
// make sure this doesn't happen mid update
|
||||||
|
if ( !drawer.midUpdate ) {
|
||||||
for ( i = drawer.tilesLoaded.length - 1; i >= 0; i-- ) {
|
updateTileCache( tile, drawer );
|
||||||
prevTile = drawer.tilesLoaded[ i ];
|
|
||||||
|
|
||||||
if ( prevTile.level <= drawer.cutoff || prevTile.beingDrawn ) {
|
|
||||||
continue;
|
|
||||||
} else if ( !worstTile ) {
|
|
||||||
worstTile = prevTile;
|
|
||||||
worstTileIndex = i;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
prevTime = prevTile.lastTouchTime;
|
|
||||||
worstTime = worstTile.lastTouchTime;
|
|
||||||
prevLevel = prevTile.level;
|
|
||||||
worstLevel = worstTile.level;
|
|
||||||
|
|
||||||
if ( prevTime < worstTime ||
|
|
||||||
( prevTime == worstTime && prevLevel > worstLevel ) ) {
|
|
||||||
worstTile = prevTile;
|
|
||||||
worstTileIndex = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if ( worstTile && worstTileIndex >= 0 ) {
|
window.setTimeout( function() {
|
||||||
worstTile.unload();
|
updateTileCache( tile, drawer );
|
||||||
insertionIndex = worstTileIndex;
|
}, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawer.tilesLoaded[ insertionIndex ] = tile;
|
|
||||||
drawer.updateAgain = true;
|
drawer.updateAgain = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateTileCache( newTile, drawer ) {
|
||||||
|
var i, prevTile, prevTime, worstTime, prevLevel, worstLevel,
|
||||||
|
insertionIndex = drawer.tilesLoaded.length,
|
||||||
|
cutoff = Math.ceil( Math.log( drawer.source.getTileSize(newTile.level) ) / Math.log( 2 ) ),
|
||||||
|
worstTile = null,
|
||||||
|
worstTileIndex = -1;
|
||||||
|
|
||||||
|
for ( i = drawer.tilesLoaded.length - 1; i >= 0; i-- ) {
|
||||||
|
prevTile = drawer.tilesLoaded[ i ];
|
||||||
|
|
||||||
|
if ( prevTile.level <= drawer.cutoff || prevTile.beingDrawn ) {
|
||||||
|
continue;
|
||||||
|
} else if ( !worstTile ) {
|
||||||
|
worstTile = prevTile;
|
||||||
|
worstTileIndex = i;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
prevTime = prevTile.lastTouchTime;
|
||||||
|
worstTime = worstTile.lastTouchTime;
|
||||||
|
prevLevel = prevTile.level;
|
||||||
|
worstLevel = worstTile.level;
|
||||||
|
|
||||||
|
if ( prevTime < worstTime ||
|
||||||
|
( prevTime == worstTime && prevLevel > worstLevel ) ) {
|
||||||
|
worstTile = prevTile;
|
||||||
|
worstTileIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( worstTile && worstTileIndex >= 0 ) {
|
||||||
|
worstTile.unload();
|
||||||
|
insertionIndex = worstTileIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawer.tilesLoaded[ insertionIndex ] = newTile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function positionTile( tile, overlap, viewport, viewportCenter, levelVisibility ){
|
function positionTile( tile, overlap, viewport, viewportCenter, levelVisibility ){
|
||||||
var boundsTL = tile.bounds.getTopLeft(),
|
var boundsTL = tile.bounds.getTopLeft(),
|
||||||
|
@ -145,7 +145,14 @@ $.ImageLoader.prototype = {
|
|||||||
else {
|
else {
|
||||||
this.jobQueue.push( newJob );
|
this.jobQueue.push( newJob );
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear any unstarted image loading jobs from the queue.
|
||||||
|
* @method
|
||||||
|
*/
|
||||||
|
clear: function() {
|
||||||
|
this.jobQueue = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user