mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-26 15:16:10 +03:00
Deprecate TileSource.getTileSize(), add TileSource.getTileWidth() and TileSource.getTileHeight()
This commit is contained in:
parent
85241b1249
commit
827fe4e836
@ -185,15 +185,11 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
* @function
|
* @function
|
||||||
* @param {Number} level
|
* @param {Number} level
|
||||||
*/
|
*/
|
||||||
|
|
||||||
getTileSize: function( level ){
|
getTileSize: function( level ){
|
||||||
var scaleFactor = Math.pow(2, this.maxLevel - level);
|
var scaleFactor = Math.pow(2, this.maxLevel - level);
|
||||||
// cache it in case any external code is going to read it directly
|
// cache it in case any external code is going to read it directly
|
||||||
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
|
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
|
||||||
this.tileSize = new $.Point(
|
this.tileSize = this.tileSizePerScaleFactor[scaleFactor];
|
||||||
this.tileSizePerScaleFactor[scaleFactor],
|
|
||||||
this.tileSizePerScaleFactor[scaleFactor]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return this.tileSize;
|
return this.tileSize;
|
||||||
},
|
},
|
||||||
@ -233,8 +229,8 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
|
|
||||||
tileSize = this.getTileSize(level);
|
tileSize = this.getTileSize(level);
|
||||||
|
|
||||||
iiifTileSizeWidth = Math.ceil( tileSize.x / scale );
|
iiifTileSizeWidth = Math.ceil( tileSize / scale );
|
||||||
iiifTileSizeHeight = Math.ceil( tileSize.y / scale );
|
iiifTileSizeHeight = Math.ceil( tileSize / scale );
|
||||||
|
|
||||||
if ( this['@context'].indexOf('/1.0/context.json') > -1 ||
|
if ( this['@context'].indexOf('/1.0/context.json') > -1 ||
|
||||||
this['@context'].indexOf('/1.1/context.json') > -1 ||
|
this['@context'].indexOf('/1.1/context.json') > -1 ||
|
||||||
@ -244,7 +240,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
iiifQuality = "default.jpg";
|
iiifQuality = "default.jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( levelWidth < tileSize.x && levelHeight < tileSize.y ){
|
if ( levelWidth < tileSize && levelHeight < tileSize ){
|
||||||
iiifSize = levelWidth + ",";
|
iiifSize = levelWidth + ",";
|
||||||
iiifRegion = 'full';
|
iiifRegion = 'full';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1036,7 +1036,7 @@ function onTileLoad( tiledImage, tile, time, image ) {
|
|||||||
|
|
||||||
var finish = function() {
|
var finish = function() {
|
||||||
var cutoff = Math.ceil( Math.log(
|
var cutoff = Math.ceil( Math.log(
|
||||||
tiledImage.source.getTileSize(tile.level).x ) / Math.log( 2 ) );
|
tiledImage.source.getTileWidth(tile.level) ) / Math.log( 2 ) );
|
||||||
setTileLoaded(tiledImage, tile, image, cutoff);
|
setTileLoaded(tiledImage, tile, image, cutoff);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
|
|||||||
* The size of the image tiles used to compose the image.
|
* The size of the image tiles used to compose the image.
|
||||||
* Please note that tileSize may be deprecated in a future release.
|
* Please note that tileSize may be deprecated in a future release.
|
||||||
* Instead the getTileSize(level) function should be used.
|
* Instead the getTileSize(level) function should be used.
|
||||||
* @member {OpenSeadragon.Point} tileSize
|
* @member {Number} tileSize
|
||||||
* @memberof OpenSeadragon.TileSource#
|
* @memberof OpenSeadragon.TileSource#
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
@ -179,7 +179,7 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
|
|||||||
//async mechanism set some safe defaults first
|
//async mechanism set some safe defaults first
|
||||||
this.aspectRatio = 1;
|
this.aspectRatio = 1;
|
||||||
this.dimensions = new $.Point( 10, 10 );
|
this.dimensions = new $.Point( 10, 10 );
|
||||||
this.tileSize = new $.Point( 0, 0 );
|
this.tileSize = 0;
|
||||||
this.tileOverlap = 0;
|
this.tileOverlap = 0;
|
||||||
this.minLevel = 0;
|
this.minLevel = 0;
|
||||||
this.maxLevel = 0;
|
this.maxLevel = 0;
|
||||||
@ -197,14 +197,9 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
|
|||||||
( options.width / options.height ) : 1;
|
( options.width / options.height ) : 1;
|
||||||
this.dimensions = new $.Point( options.width, options.height );
|
this.dimensions = new $.Point( options.width, options.height );
|
||||||
|
|
||||||
if( options.tileSize ){
|
this.tileSize = options.tileSize ? options.tileSize : 0;
|
||||||
this.tileSize = new $.Point(options.tileSize, options.tileSize);
|
this.tileWidth = options.tileWidth;
|
||||||
} else {
|
this.tileHeight = options.tileHeight;
|
||||||
this.tileSize = new $.Point(
|
|
||||||
(options.tileWidth ? options.tileWidth : 0),
|
|
||||||
(options.tileHeight ? options.tileHeight : 0)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tileOverlap = options.tileOverlap ? options.tileOverlap : 0;
|
this.tileOverlap = options.tileOverlap ? options.tileOverlap : 0;
|
||||||
this.minLevel = options.minLevel ? options.minLevel : 0;
|
this.minLevel = options.minLevel ? options.minLevel : 0;
|
||||||
@ -231,14 +226,50 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
|
|||||||
* Subclasses should override this if tileSizes can be different at different levels
|
* Subclasses should override this if tileSizes can be different at different levels
|
||||||
* such as in IIIFTileSource. Code should use this function rather than reading
|
* such as in IIIFTileSource. Code should use this function rather than reading
|
||||||
* from .tileSize directly. tileSize may be deprecated in a future release.
|
* from .tileSize directly. tileSize may be deprecated in a future release.
|
||||||
|
* @deprecated
|
||||||
* @function
|
* @function
|
||||||
* @param {Number} level
|
* @param {Number} level
|
||||||
* @returns {OpenSeadragon.Point} The dimensions of tiles in level
|
|
||||||
*/
|
*/
|
||||||
getTileSize: function( level ) {
|
getTileSize: function( level ) {
|
||||||
|
$.console.error(
|
||||||
|
"[TileSource.getTileSize] is deprecated." +
|
||||||
|
"Use TileSource.getTileWidth() and TileSource.getTileHeight() instead"
|
||||||
|
);
|
||||||
return this.tileSize;
|
return this.tileSize;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the tileWidth for a given level.
|
||||||
|
* Subclasses should override this if tileWidth can be different at different levels
|
||||||
|
* such as in IIIFTileSource. Code should use this function rather than reading
|
||||||
|
* from .tileWidth directly.
|
||||||
|
* @function
|
||||||
|
* @param {Number} level
|
||||||
|
*/
|
||||||
|
getTileWidth: function( level ) {
|
||||||
|
// If tileWidth was not set, fallback by setting it to tileSize
|
||||||
|
if( this.tileWidth === undefined){
|
||||||
|
this.tileWidth = this.tileSize;
|
||||||
|
}
|
||||||
|
return this.tileWidth;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the tileHeight for a given level.
|
||||||
|
* Subclasses should override this if tileHeight can be different at different levels
|
||||||
|
* such as in IIIFTileSource. Code should use this function rather than reading
|
||||||
|
* from .tileHeight directly.
|
||||||
|
* @function
|
||||||
|
* @param {Number} level
|
||||||
|
*/
|
||||||
|
getTileHeight: function( level ) {
|
||||||
|
// If tileHeight was not set, fallback by setting it to tileSize
|
||||||
|
if( this.tileHeight === undefined ){
|
||||||
|
this.tileHeight = this.tileSize;
|
||||||
|
}
|
||||||
|
return this.tileHeight;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
* @param {Number} level
|
* @param {Number} level
|
||||||
@ -265,8 +296,8 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
|
|||||||
*/
|
*/
|
||||||
getNumTiles: function( level ) {
|
getNumTiles: function( level ) {
|
||||||
var scale = this.getLevelScale( level ),
|
var scale = this.getLevelScale( level ),
|
||||||
x = Math.ceil( scale * this.dimensions.x / this.getTileSize(level).x ),
|
x = Math.ceil( scale * this.dimensions.x / this.getTileWidth(level) ),
|
||||||
y = Math.ceil( scale * this.dimensions.y / this.getTileSize(level).y );
|
y = Math.ceil( scale * this.dimensions.y / this.getTileHeight(level) );
|
||||||
|
|
||||||
return new $.Point( x, y );
|
return new $.Point( x, y );
|
||||||
},
|
},
|
||||||
@ -291,19 +322,16 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
|
|||||||
getClosestLevel: function( rect ) {
|
getClosestLevel: function( rect ) {
|
||||||
var i,
|
var i,
|
||||||
tilesPerSide,
|
tilesPerSide,
|
||||||
tiles,
|
tiles;
|
||||||
tileSize;
|
|
||||||
|
|
||||||
for( i = this.minLevel; i < this.maxLevel; i++ ){
|
for( i = this.minLevel; i < this.maxLevel; i++ ){
|
||||||
tiles = this.getNumTiles( i );
|
tiles = this.getNumTiles( i );
|
||||||
tileSize = this.getTileSize(i);
|
|
||||||
|
|
||||||
tilesPerSide = new $.Point(
|
tilesPerSide = new $.Point(
|
||||||
Math.floor( rect.x / tileSize.x ),
|
Math.floor( rect.x / this.getTileWidth(i) ),
|
||||||
Math.floor( rect.y / tileSize.y )
|
Math.floor( rect.y / this.getTileHeight(i) )
|
||||||
);
|
);
|
||||||
|
|
||||||
if( tiles.x + 1 >= tilesPerSide.x && tiles.y + 1 >= tilesPerSide.y ){
|
if( tiles.x + 1 >= tilesPerSide.x || tiles.y + 1 >= tilesPerSide.y ){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -317,8 +345,8 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
|
|||||||
*/
|
*/
|
||||||
getTileAtPoint: function( level, point ) {
|
getTileAtPoint: function( level, point ) {
|
||||||
var pixel = point.times( this.dimensions.x ).times( this.getLevelScale(level) ),
|
var pixel = point.times( this.dimensions.x ).times( this.getLevelScale(level) ),
|
||||||
tx = Math.floor( pixel.x / this.getTileSize(level).x ),
|
tx = Math.floor( pixel.x / this.getTileWidth(level) ),
|
||||||
ty = Math.floor( pixel.y / this.getTileSize(level).y );
|
ty = Math.floor( pixel.y / this.getTileHeight(level) );
|
||||||
|
|
||||||
return new $.Point( tx, ty );
|
return new $.Point( tx, ty );
|
||||||
},
|
},
|
||||||
@ -331,11 +359,12 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
|
|||||||
*/
|
*/
|
||||||
getTileBounds: function( level, x, y ) {
|
getTileBounds: function( level, x, y ) {
|
||||||
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
var dimensionsScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
||||||
tileSize = this.getTileSize(level),
|
tileWidth = this.getTileWidth(level),
|
||||||
px = ( x === 0 ) ? 0 : tileSize.x * x - this.tileOverlap,
|
tileHeight = this.getTileHeight(level),
|
||||||
py = ( y === 0 ) ? 0 : tileSize.y * y - this.tileOverlap,
|
px = ( x === 0 ) ? 0 : tileWidth * x - this.tileOverlap,
|
||||||
sx = tileSize.x + ( x === 0 ? 1 : 2 ) * this.tileOverlap,
|
py = ( y === 0 ) ? 0 : tileHeight * y - this.tileOverlap,
|
||||||
sy = tileSize.y + ( y === 0 ? 1 : 2 ) * this.tileOverlap,
|
sx = tileWidth + ( x === 0 ? 1 : 2 ) * this.tileOverlap,
|
||||||
|
sy = tileHeight + ( y === 0 ? 1 : 2 ) * this.tileOverlap,
|
||||||
scale = 1.0 / dimensionsScaled.x;
|
scale = 1.0 / dimensionsScaled.x;
|
||||||
|
|
||||||
sx = Math.min( sx, dimensionsScaled.x - px );
|
sx = Math.min( sx, dimensionsScaled.x - px );
|
||||||
|
Loading…
Reference in New Issue
Block a user