Merge branch 'rdlester-imageLoaderPatch'

This commit is contained in:
Ian Gilman 2014-11-07 15:33:27 -08:00
commit ffac82ce60
2 changed files with 60 additions and 49 deletions

View File

@ -730,23 +730,10 @@ function loadTile( drawer, tile, time ) {
}
function onTileLoad( drawer, tile, time, image ) {
var insertionIndex,
cutoff,
worstTile,
worstTime,
worstLevel,
worstTileIndex,
prevTile,
prevTime,
prevLevel,
i;
tile.loading = false;
if ( drawer.midUpdate ) {
$.console.warn( "Tile load callback in middle of drawing routine." );
return;
} else if ( !image && !drawer.viewport.collectionMode ) {
if ( !image && !drawer.viewport.collectionMode ) {
$.console.log( "Tile %s failed to load: %s", tile, tile.url );
if( !drawer.debugMode ){
tile.exists = false;
@ -760,12 +747,31 @@ function onTileLoad( drawer, tile, time, image ) {
tile.loaded = true;
tile.image = image;
insertionIndex = drawer.tilesLoaded.length;
if ( drawer.tilesLoaded.length < drawer.maxImageCacheCount ) {
// always safe to append things to cache
drawer.tilesLoaded[ drawer.tilesLoaded.length ] = tile;
}
else {
// need to remove something from cache,
// make sure this doesn't happen mid update
if ( !drawer.midUpdate ) {
updateTileCache( tile, drawer );
}
else {
window.setTimeout( function() {
updateTileCache( tile, drawer );
}, 1);
}
}
if ( drawer.tilesLoaded.length >= drawer.maxImageCacheCount ) {
cutoff = Math.ceil( Math.log( drawer.source.getTileSize(tile.level) ) / Math.log( 2 ) );
drawer.updateAgain = true;
}
worstTile = null;
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-- ) {
@ -795,10 +801,8 @@ function onTileLoad( drawer, tile, time, image ) {
worstTile.unload();
insertionIndex = worstTileIndex;
}
}
drawer.tilesLoaded[ insertionIndex ] = tile;
drawer.updateAgain = true;
drawer.tilesLoaded[ insertionIndex ] = newTile;
}

View File

@ -145,7 +145,14 @@ $.ImageLoader.prototype = {
else {
this.jobQueue.push( newJob );
}
},
/**
* Clear any unstarted image loading jobs from the queue.
* @method
*/
clear: function() {
this.jobQueue = [];
}
};