mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-02-16 14:53:14 +03:00
Further optimization: code moved into constructor thereby eliminating need for getLevelSize() function.
This commit is contained in:
parent
5fd125dc92
commit
c5404006b2
@ -141,6 +141,18 @@ $.IIIFTileSource = function( options ){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an array with our exact resolution sizes if these have been supplied
|
||||||
|
if( this.sizes ) {
|
||||||
|
var sizeLength = this.sizes.length;
|
||||||
|
if ( (sizeLength === options.maxLevel) || (sizeLength === options.maxLevel + 1) ) {
|
||||||
|
this.levelSizes = this.sizes;
|
||||||
|
// Need to take into account that the list may or may not include the full resolution size
|
||||||
|
if( sizeLength === options.maxLevel ) {
|
||||||
|
this.levelSizes.push( {width: this.width, height: this.height} );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$.TileSource.apply( this, [ options ] );
|
$.TileSource.apply( this, [ options ] );
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -334,8 +346,8 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use supplied list of scaled resolution sizes if these exist
|
// Use supplied list of scaled resolution sizes if these exist
|
||||||
var levelSize = this.getLevelSize(level);
|
if( this.levelSizes ) {
|
||||||
if( levelSize ) {
|
var levelSize = this.levelSizes[level];
|
||||||
var x = Math.ceil( levelSize.width / this.getTileWidth(level) ),
|
var x = Math.ceil( levelSize.width / this.getTileWidth(level) ),
|
||||||
y = Math.ceil( levelSize.height / this.getTileHeight(level) );
|
y = Math.ceil( levelSize.height / this.getTileHeight(level) );
|
||||||
return new $.Point( x, y );
|
return new $.Point( x, y );
|
||||||
@ -347,37 +359,6 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine image size at a given resolution level using the info.json "sizes" field
|
|
||||||
* Returns null if this information is not present
|
|
||||||
* @function {Number} level
|
|
||||||
*/
|
|
||||||
getLevelSize: function( level ) {
|
|
||||||
|
|
||||||
if (!this.sizes) {
|
|
||||||
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};
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
* @param {Number} level
|
* @param {Number} level
|
||||||
@ -390,14 +371,13 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use supplied list of scaled resolution sizes if these exist
|
// Use supplied list of scaled resolution sizes if these exist
|
||||||
var levelSize = this.getLevelSize(level);
|
if( this.levelSizes ) {
|
||||||
if( levelSize ) {
|
|
||||||
|
|
||||||
var validPoint = point.x >= 0 && point.x <= 1 &&
|
var validPoint = point.x >= 0 && point.x <= 1 &&
|
||||||
point.y >= 0 && point.y <= 1 / this.aspectRatio;
|
point.y >= 0 && point.y <= 1 / this.aspectRatio;
|
||||||
$.console.assert(validPoint, "[TileSource.getTileAtPoint] must be called with a valid point.");
|
$.console.assert(validPoint, "[TileSource.getTileAtPoint] must be called with a valid point.");
|
||||||
|
|
||||||
var widthScaled = levelSize.width;
|
var widthScaled = this.levelSizes[level].width;
|
||||||
var pixelX = point.x * widthScaled;
|
var pixelX = point.x * widthScaled;
|
||||||
var pixelY = point.y * widthScaled;
|
var pixelY = point.y * widthScaled;
|
||||||
|
|
||||||
@ -466,15 +446,14 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
uri;
|
uri;
|
||||||
|
|
||||||
// Use supplied list of scaled resolution sizes if these exist
|
// Use supplied list of scaled resolution sizes if these exist
|
||||||
var levelSize = this.getLevelSize( level );
|
if( this.levelSizes ) {
|
||||||
if( levelSize ) {
|
levelWidth = this.levelSizes[level].width;
|
||||||
levelWidth = levelSize.width;
|
levelHeight = this.levelSizes[level].height;
|
||||||
levelHeight = levelSize.height;
|
|
||||||
}
|
}
|
||||||
// Otherwise calculate the sizes ourselves
|
// Otherwise calculate the sizes ourselves
|
||||||
else {
|
else {
|
||||||
levelWidth = Math.ceil( this.width * scale );
|
levelWidth = Math.ceil( this.width * scale );
|
||||||
levelHeight = Math.ceil( this.height * scale );
|
levelHeight = Math.ceil( this.height * scale );
|
||||||
}
|
}
|
||||||
|
|
||||||
tileWidth = this.getTileWidth(level);
|
tileWidth = this.getTileWidth(level);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user