Remove TileSource.tileSize. Convert IIIFTileSource to override TileSource.getTileWidth and TileSource.getTileHeight.

This commit is contained in:
Conner Wingard 2015-06-30 17:56:06 -04:00
parent 201ca8a422
commit d11c4fe107
2 changed files with 43 additions and 40 deletions

View File

@ -182,19 +182,34 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
}, },
/** /**
* Return the tileSize for the given level. * Return the tileWidth for the given level.
* @function * @function
* @param {Number} level * @param {Number} level
*/ */
getTileSize: function( level ){ getTileWidth: 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
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) { if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
this.tileSize = this.tileSizePerScaleFactor[scaleFactor]; return this.tileSizePerScaleFactor[scaleFactor];
} }
return this.tileSize; return this._tileWidth;
}, },
/**
* Return the tileHeight for the given level.
* @function
* @param {Number} level
*/
getTileHeight: function( level ) {
var scaleFactor = Math.pow(2, this.maxLevel - level);
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
return this.tileSizePerScaleFactor[scaleFactor];
}
return this._tileHeight;
},
/** /**
* Responsible for retreiving the url which will return an image for the * Responsible for retreiving the url which will return an image for the
* region specified by the given x, y, and level components. * region specified by the given x, y, and level components.
@ -216,7 +231,8 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
levelHeight = Math.ceil( this.height * scale ), levelHeight = Math.ceil( this.height * scale ),
//## iiif region //## iiif region
tileSize, tileWidth,
tileHeight,
iiifTileSizeWidth, iiifTileSizeWidth,
iiifTileSizeHeight, iiifTileSizeHeight,
iiifRegion, iiifRegion,
@ -228,9 +244,10 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
iiifQuality, iiifQuality,
uri; uri;
tileSize = this.getTileSize(level); tileWidth = this.getTileSize(level);
iiifTileSizeWidth = Math.ceil( tileSize / scale ); tileHeight = this.getTileHeight(level);
iiifTileSizeHeight = iiifTileSizeWidth; iiifTileSizeWidth = Math.ceil( tileWidth / scale );
iiifTileSizeHeight = Math.ceil( tileHeight / 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 ||
@ -240,7 +257,7 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
iiifQuality = "default.jpg"; iiifQuality = "default.jpg";
} }
if ( levelWidth < tileSize && levelHeight < tileSize ){ if ( levelWidth < tileWidth && levelHeight < tileHeight ){
iiifSize = levelWidth + ","; iiifSize = levelWidth + ",";
iiifRegion = 'full'; iiifRegion = 'full';
} else { } else {

View File

@ -142,13 +142,6 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
* @member {OpenSeadragon.Point} dimensions * @member {OpenSeadragon.Point} dimensions
* @memberof OpenSeadragon.TileSource# * @memberof OpenSeadragon.TileSource#
*/ */
/**
* The size of the image tiles used to compose the image.
* Please note that tileSize may be deprecated in a future release.
* Instead the getTileSize(level) function should be used.
* @member {Number} tileSize
* @memberof OpenSeadragon.TileSource#
*/
/** /**
* The overlap in pixels each tile shares with its adjacent neighbors. * The overlap in pixels each tile shares with its adjacent neighbors.
* @member {Number} tileOverlap * @member {Number} tileOverlap
@ -179,7 +172,8 @@ $.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 = 0; this._tileWidth = 0;
this._tileHeight = 0;
this.tileOverlap = 0; this.tileOverlap = 0;
this.minLevel = 0; this.minLevel = 0;
this.maxLevel = 0; this.maxLevel = 0;
@ -197,9 +191,12 @@ $.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 );
this.tileSize = options.tileSize ? options.tileSize : 0; if ( options.tileSize ){
this.tileWidth = options.tileWidth; this._tileWidth = this._tileHeight = options.tileSize;
this.tileHeight = options.tileHeight; } else {
this._tileWidth = options.tileWidth ? options.tileWidth : 0;
this._tileHeight = 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;
@ -221,21 +218,12 @@ $.TileSource = function( width, height, tileSize, tileOverlap, minLevel, maxLeve
$.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
/**
* Return the tileSize for a given level.
* Subclasses should override this if tileSizes can be different at different levels
* such as in IIIFTileSource. Code should use this function rather than reading
* from .tileSize directly. tileSize may be deprecated in a future release.
* @deprecated
* @function
* @param {Number} level
*/
getTileSize: function( level ) { getTileSize: function( level ) {
$.console.error( $.console.error(
"[TileSource.getTileSize] is deprecated." + "[TileSource.getTileSize] is deprecated." +
"Use TileSource.getTileWidth() and TileSource.getTileHeight() instead" "Use TileSource.getTileWidth() and TileSource.getTileHeight() instead"
); );
return this.tileSize; return this._tileWidth;
}, },
/** /**
@ -247,11 +235,10 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
* @param {Number} level * @param {Number} level
*/ */
getTileWidth: function( level ) { getTileWidth: function( level ) {
// If tileWidth was not set, fallback by setting it to tileSize if (!this._tileWidth) {
if( this.tileWidth === undefined){ return this.getTileSize(level);
this.tileWidth = this.tileSize;
} }
return this.tileWidth; return this._tileWidth;
}, },
/** /**
@ -263,11 +250,10 @@ $.TileSource.prototype = /** @lends OpenSeadragon.TileSource.prototype */{
* @param {Number} level * @param {Number} level
*/ */
getTileHeight: function( level ) { getTileHeight: function( level ) {
// If tileHeight was not set, fallback by setting it to tileSize if (!this._tileHeight) {
if( this.tileHeight === undefined ){ return this.getTileSize(level);
this.tileHeight = this.tileSize;
} }
return this.tileHeight; return this._tileHeight;
}, },
/** /**