Refactored code to take into account optimization suggestions (https://github.com/openseadragon/openseadragon/pull/2337#discussion_r1170931340)

This commit is contained in:
Ruven 2023-04-24 17:24:18 +02:00
parent 0c358c140d
commit 877c3b68ed
No known key found for this signature in database
GPG Key ID: B54C2EF1C087BEFB

View File

@ -354,24 +354,27 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
*/ */
getLevelSize: function( level ) { getLevelSize: function( level ) {
var numLevels = this.maxLevel - this.minLevel; if (!this.sizes) {
// Need to take into account that the list may or may not include the full resolution size
if( this.sizes && ((this.sizes.length === numLevels) ||
(this.sizes.length === numLevels + 1)) ) {
var levelWidth, levelHeight;
if( this.sizes.length === numLevels ) {
levelWidth = (level === this.sizes.length) ? this.width : this.sizes[level].width;
levelHeight = (level === this.sizes.length) ? this.height : this.sizes[level].height;
}
else {
levelWidth = this.sizes[level].width;
levelHeight = this.sizes[level].height;
}
return { width: levelWidth, height: levelHeight };
}
else {
return null; return null;
} }
var levelWidth, levelHeight;
var numLevels = this.maxLevel - this.minLevel;
var sizeLength = this.sizes.length;
// Need to take into account that the list may or may not include the full resolution size
if (sizeLength === numLevels) {
levelWidth = (level === sizeLength) ? this.width : this.sizes[level].width;
levelHeight = (level === sizeLength) ? this.height : this.sizes[level].height;
} else if ( sizeLength === numLevels + 1 ) {
levelWidth = this.sizes[level].width;
levelHeight = this.sizes[level].height;
} else {
// Sizes field doesn't contain resolution level sizes, so discard
return null;
}
return {width: levelWidth, height: levelHeight};
}, },