2014-07-26 03:31:13 +04:00
|
|
|
/*
|
2014-07-29 22:15:14 +04:00
|
|
|
* OpenSeadragon - IIIFTileSource
|
2014-07-26 03:31:13 +04:00
|
|
|
*
|
2014-07-29 22:12:05 +04:00
|
|
|
* Copyright (C) 2009 CodePlex Foundation
|
2014-07-26 03:31:13 +04:00
|
|
|
* Copyright (C) 2010-2013 OpenSeadragon contributors
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* - Neither the name of CodePlex Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function( $ ){
|
|
|
|
|
|
|
|
/**
|
2014-07-29 22:16:23 +04:00
|
|
|
* @class IIIFTileSource
|
2015-12-14 00:32:21 +03:00
|
|
|
* @classdesc A client implementation of the International Image Interoperability Framework
|
|
|
|
* Format: Image API 1.0 - 2.1
|
2014-07-26 03:31:13 +04:00
|
|
|
*
|
|
|
|
* @memberof OpenSeadragon
|
|
|
|
* @extends OpenSeadragon.TileSource
|
|
|
|
* @see http://iiif.io/api/image/
|
2019-03-19 20:23:27 +03:00
|
|
|
* @param {String} [options.tileFormat='jpg']
|
|
|
|
* The extension that will be used when requiring tiles.
|
2014-07-26 03:31:13 +04:00
|
|
|
*/
|
2014-07-29 22:12:05 +04:00
|
|
|
$.IIIFTileSource = function( options ){
|
2014-07-26 03:31:13 +04:00
|
|
|
|
2017-01-08 17:52:57 +03:00
|
|
|
/* eslint-disable camelcase */
|
2014-07-26 03:31:13 +04:00
|
|
|
|
|
|
|
$.extend( true, this, options );
|
|
|
|
|
|
|
|
if ( !( this.height && this.width && this['@id'] ) ) {
|
|
|
|
throw new Error( 'IIIF required parameters not provided.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
options.tileSizePerScaleFactor = {};
|
|
|
|
|
2019-03-19 20:22:09 +03:00
|
|
|
this.tileFormat = this.tileFormat || 'jpg';
|
2019-03-14 16:04:12 +03:00
|
|
|
|
2019-12-17 18:22:48 +03:00
|
|
|
this.version = options.version;
|
|
|
|
|
2014-09-04 23:04:31 +04:00
|
|
|
// N.B. 2.0 renamed scale_factors to scaleFactors
|
2015-07-10 21:26:51 +03:00
|
|
|
if ( this.tile_width && this.tile_height ) {
|
|
|
|
options.tileWidth = this.tile_width;
|
|
|
|
options.tileHeight = this.tile_height;
|
|
|
|
} else if ( this.tile_width ) {
|
2014-07-26 03:31:13 +04:00
|
|
|
options.tileSize = this.tile_width;
|
|
|
|
} else if ( this.tile_height ) {
|
|
|
|
options.tileSize = this.tile_height;
|
|
|
|
} else if ( this.tiles ) {
|
|
|
|
// Version 2.0 forwards
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( this.tiles.length === 1 ) {
|
2015-07-10 21:26:51 +03:00
|
|
|
options.tileWidth = this.tiles[0].width;
|
|
|
|
// Use height if provided, otherwise assume square tiles and use width.
|
|
|
|
options.tileHeight = this.tiles[0].height || this.tiles[0].width;
|
2014-09-04 23:04:31 +04:00
|
|
|
this.scale_factors = this.tiles[0].scaleFactors;
|
2014-07-26 03:31:13 +04:00
|
|
|
} else {
|
|
|
|
// Multiple tile sizes at different levels
|
|
|
|
this.scale_factors = [];
|
|
|
|
for (var t = 0; t < this.tiles.length; t++ ) {
|
2014-09-04 23:04:31 +04:00
|
|
|
for (var sf = 0; sf < this.tiles[t].scaleFactors.length; sf++) {
|
|
|
|
var scaleFactor = this.tiles[t].scaleFactors[sf];
|
2014-07-26 03:31:13 +04:00
|
|
|
this.scale_factors.push(scaleFactor);
|
2015-07-10 21:26:51 +03:00
|
|
|
options.tileSizePerScaleFactor[scaleFactor] = {
|
|
|
|
width: this.tiles[t].width,
|
|
|
|
height: this.tiles[t].height || this.tiles[t].width
|
|
|
|
};
|
2014-07-26 03:31:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-17 18:22:48 +03:00
|
|
|
} else if ( canBeTiled(options) ) {
|
2014-07-26 03:31:13 +04:00
|
|
|
// use the largest of tileOptions that is smaller than the short dimension
|
|
|
|
var shortDim = Math.min( this.height, this.width ),
|
2017-01-08 17:52:57 +03:00
|
|
|
tileOptions = [256, 512, 1024],
|
2014-07-26 03:31:13 +04:00
|
|
|
smallerTiles = [];
|
|
|
|
|
|
|
|
for ( var c = 0; c < tileOptions.length; c++ ) {
|
|
|
|
if ( tileOptions[c] <= shortDim ) {
|
|
|
|
smallerTiles.push( tileOptions[c] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( smallerTiles.length > 0 ) {
|
|
|
|
options.tileSize = Math.max.apply( null, smallerTiles );
|
|
|
|
} else {
|
|
|
|
// If we're smaller than 256, just use the short side.
|
|
|
|
options.tileSize = shortDim;
|
|
|
|
}
|
2015-12-14 00:32:21 +03:00
|
|
|
} else if (this.sizes && this.sizes.length > 0) {
|
2017-01-08 17:52:57 +03:00
|
|
|
// This info.json can't be tiled, but we can still construct a legacy pyramid from the sizes array.
|
|
|
|
// In this mode, IIIFTileSource will call functions from the abstract baseTileSource or the
|
|
|
|
// LegacyTileSource instead of performing IIIF tiling.
|
2015-12-14 00:32:21 +03:00
|
|
|
this.emulateLegacyImagePyramid = true;
|
2017-01-08 17:52:57 +03:00
|
|
|
|
2015-12-14 00:32:21 +03:00
|
|
|
options.levels = constructLevels( this );
|
|
|
|
// use the largest available size to define tiles
|
|
|
|
$.extend( true, options, {
|
|
|
|
width: options.levels[ options.levels.length - 1 ].width,
|
|
|
|
height: options.levels[ options.levels.length - 1 ].height,
|
|
|
|
tileSize: Math.max( options.height, options.width ),
|
|
|
|
tileOverlap: 0,
|
|
|
|
minLevel: 0,
|
|
|
|
maxLevel: options.levels.length - 1
|
|
|
|
});
|
|
|
|
this.levels = options.levels;
|
|
|
|
} else {
|
|
|
|
$.console.error("Nothing in the info.json to construct image pyramids from");
|
2014-07-26 03:31:13 +04:00
|
|
|
}
|
|
|
|
|
2015-12-14 00:32:21 +03:00
|
|
|
if (!options.maxLevel && !this.emulateLegacyImagePyramid) {
|
|
|
|
if (!this.scale_factors) {
|
|
|
|
options.maxLevel = Number(Math.ceil(Math.log(Math.max(this.width, this.height), 2)));
|
2014-08-05 18:13:06 +04:00
|
|
|
} else {
|
2018-02-16 23:09:56 +03:00
|
|
|
var maxScaleFactor = Math.max.apply(null, this.scale_factors);
|
|
|
|
options.maxLevel = Math.round(Math.log(maxScaleFactor) * Math.LOG2E);
|
2014-07-26 03:31:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$.TileSource.apply( this, [ options ] );
|
|
|
|
};
|
|
|
|
|
2014-07-29 22:12:05 +04:00
|
|
|
$.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSeadragon.IIIFTileSource.prototype */{
|
2014-07-26 03:31:13 +04:00
|
|
|
/**
|
|
|
|
* Determine if the data and/or url imply the image service is supported by
|
|
|
|
* this tile source.
|
|
|
|
* @function
|
|
|
|
* @param {Object|Array} data
|
|
|
|
* @param {String} optional - url
|
|
|
|
*/
|
2017-01-08 17:52:57 +03:00
|
|
|
|
2014-07-26 03:31:13 +04:00
|
|
|
supports: function( data, url ) {
|
|
|
|
// Version 2.0 and forwards
|
2020-06-26 02:01:14 +03:00
|
|
|
if (data.protocol && data.protocol === 'http://iiif.io/api/image') {
|
2014-07-26 03:31:13 +04:00
|
|
|
return true;
|
|
|
|
// Version 1.1
|
|
|
|
} else if ( data['@context'] && (
|
2020-06-26 02:01:14 +03:00
|
|
|
data['@context'] === "http://library.stanford.edu/iiif/image-api/1.1/context.json" ||
|
|
|
|
data['@context'] === "http://iiif.io/api/image/1/context.json") ) {
|
2014-07-26 03:31:13 +04:00
|
|
|
// N.B. the iiif.io context is wrong, but where the representation lives so likely to be used
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Version 1.0
|
2014-08-05 18:13:06 +04:00
|
|
|
} else if ( data.profile &&
|
2014-07-26 03:31:13 +04:00
|
|
|
data.profile.indexOf("http://library.stanford.edu/iiif/image-api/compliance.html") === 0) {
|
|
|
|
return true;
|
|
|
|
} else if ( data.identifier && data.width && data.height ) {
|
|
|
|
return true;
|
|
|
|
} else if ( data.documentElement &&
|
2020-06-26 02:01:14 +03:00
|
|
|
"info" === data.documentElement.tagName &&
|
|
|
|
"http://library.stanford.edu/iiif/image-api/ns/" ===
|
2014-07-26 03:31:13 +04:00
|
|
|
data.documentElement.namespaceURI) {
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Not IIIF
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
* @param {Object} data - the raw configuration
|
2021-12-08 11:54:14 +03:00
|
|
|
* @param {String} url - the url configuration was retrieved from
|
|
|
|
* @param {String} postData - data for the post request or null
|
2014-07-29 22:12:05 +04:00
|
|
|
* @example <caption>IIIF 1.1 Info Looks like this</caption>
|
2014-07-26 03:31:13 +04:00
|
|
|
* {
|
|
|
|
* "@context" : "http://library.stanford.edu/iiif/image-api/1.1/context.json",
|
|
|
|
* "@id" : "http://iiif.example.com/prefix/1E34750D-38DB-4825-A38A-B60A345E591C",
|
|
|
|
* "width" : 6000,
|
|
|
|
* "height" : 4000,
|
|
|
|
* "scale_factors" : [ 1, 2, 4 ],
|
|
|
|
* "tile_width" : 1024,
|
|
|
|
* "tile_height" : 1024,
|
|
|
|
* "formats" : [ "jpg", "png" ],
|
|
|
|
* "qualities" : [ "native", "grey" ],
|
|
|
|
* "profile" : "http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0"
|
|
|
|
* }
|
|
|
|
*/
|
2021-12-08 11:54:14 +03:00
|
|
|
configure: function( data, url, postData ){
|
2014-07-26 03:31:13 +04:00
|
|
|
// Try to deduce our version and fake it upwards if needed
|
|
|
|
if ( !$.isPlainObject(data) ) {
|
2014-08-05 18:13:06 +04:00
|
|
|
var options = configureFromXml10( data );
|
2014-07-26 03:31:13 +04:00
|
|
|
options['@context'] = "http://iiif.io/api/image/1.0/context.json";
|
|
|
|
options['@id'] = url.replace('/info.xml', '');
|
2019-12-17 18:22:48 +03:00
|
|
|
options.version = 1;
|
2014-07-26 03:31:13 +04:00
|
|
|
return options;
|
|
|
|
} else {
|
2019-05-22 12:44:52 +03:00
|
|
|
if ( !data['@context'] ) {
|
|
|
|
data['@context'] = 'http://iiif.io/api/image/1.0/context.json';
|
|
|
|
data['@id'] = url.replace('/info.json', '');
|
2019-12-17 18:22:48 +03:00
|
|
|
data.version = 1;
|
|
|
|
} else {
|
|
|
|
var context = data['@context'];
|
|
|
|
if (Array.isArray(context)) {
|
|
|
|
for (var i = 0; i < context.length; i++) {
|
|
|
|
if (typeof context[i] === 'string' &&
|
2019-12-18 19:52:39 +03:00
|
|
|
( /^http:\/\/iiif\.io\/api\/image\/[1-3]\/context\.json$/.test(context[i]) ||
|
2019-12-17 18:22:48 +03:00
|
|
|
context[i] === 'http://library.stanford.edu/iiif/image-api/1.1/context.json' ) ) {
|
|
|
|
context = context[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-18 19:52:39 +03:00
|
|
|
switch (context) {
|
2019-12-17 18:22:48 +03:00
|
|
|
case 'http://iiif.io/api/image/1/context.json':
|
|
|
|
case 'http://library.stanford.edu/iiif/image-api/1.1/context.json':
|
|
|
|
data.version = 1;
|
|
|
|
break;
|
|
|
|
case 'http://iiif.io/api/image/2/context.json':
|
|
|
|
data.version = 2;
|
|
|
|
break;
|
|
|
|
case 'http://iiif.io/api/image/3/context.json':
|
|
|
|
data.version = 3;
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-15 11:56:45 +03:00
|
|
|
$.console.error('Data has a @context property which contains no known IIIF context URI.');
|
2019-12-17 18:22:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !data['@id'] && data['id'] ) {
|
|
|
|
data['@id'] = data['id'];
|
2019-05-22 12:44:52 +03:00
|
|
|
}
|
|
|
|
if(data.preferredFormats) {
|
|
|
|
for (var f = 0; f < data.preferredFormats.length; f++ ) {
|
|
|
|
if ( OpenSeadragon.imageFormatSupported(data.preferredFormats[f]) ) {
|
|
|
|
data.tileFormat = data.preferredFormats[f];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-26 03:31:13 +04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-29 22:12:05 +04:00
|
|
|
/**
|
2015-07-01 00:56:06 +03:00
|
|
|
* Return the tileWidth for the given level.
|
2014-07-29 22:12:05 +04:00
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
2015-07-01 00:56:06 +03:00
|
|
|
*/
|
|
|
|
getTileWidth: function( level ) {
|
2015-12-14 00:32:21 +03:00
|
|
|
|
|
|
|
if(this.emulateLegacyImagePyramid) {
|
|
|
|
return $.TileSource.prototype.getTileWidth.call(this, level);
|
|
|
|
}
|
|
|
|
|
2014-07-26 03:31:13 +04:00
|
|
|
var scaleFactor = Math.pow(2, this.maxLevel - level);
|
2015-07-01 00:56:06 +03:00
|
|
|
|
2014-07-26 03:31:13 +04:00
|
|
|
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
|
2015-07-10 21:26:51 +03:00
|
|
|
return this.tileSizePerScaleFactor[scaleFactor].width;
|
2014-07-26 03:31:13 +04:00
|
|
|
}
|
2015-07-01 00:56:06 +03:00
|
|
|
return this._tileWidth;
|
2014-07-26 03:31:13 +04:00
|
|
|
},
|
|
|
|
|
2015-07-01 00:56:06 +03:00
|
|
|
/**
|
|
|
|
* Return the tileHeight for the given level.
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
|
|
|
getTileHeight: function( level ) {
|
2015-12-14 00:32:21 +03:00
|
|
|
|
|
|
|
if(this.emulateLegacyImagePyramid) {
|
|
|
|
return $.TileSource.prototype.getTileHeight.call(this, level);
|
|
|
|
}
|
|
|
|
|
2015-07-01 00:56:06 +03:00
|
|
|
var scaleFactor = Math.pow(2, this.maxLevel - level);
|
|
|
|
|
|
|
|
if (this.tileSizePerScaleFactor && this.tileSizePerScaleFactor[scaleFactor]) {
|
2015-07-10 21:26:51 +03:00
|
|
|
return this.tileSizePerScaleFactor[scaleFactor].height;
|
2015-07-01 00:56:06 +03:00
|
|
|
}
|
|
|
|
return this._tileHeight;
|
|
|
|
},
|
|
|
|
|
2015-12-14 00:32:21 +03:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
|
|
|
getLevelScale: function ( level ) {
|
|
|
|
|
|
|
|
if(this.emulateLegacyImagePyramid) {
|
|
|
|
var levelScale = NaN;
|
|
|
|
if (this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel) {
|
|
|
|
levelScale =
|
|
|
|
this.levels[level].width /
|
|
|
|
this.levels[this.maxLevel].width;
|
|
|
|
}
|
|
|
|
return levelScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $.TileSource.prototype.getLevelScale.call(this, level);
|
|
|
|
},
|
2015-07-01 00:56:06 +03:00
|
|
|
|
2014-07-26 03:31:13 +04:00
|
|
|
/**
|
2015-12-14 00:32:21 +03:00
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
*/
|
|
|
|
getNumTiles: function( level ) {
|
|
|
|
|
|
|
|
if(this.emulateLegacyImagePyramid) {
|
|
|
|
var scale = this.getLevelScale(level);
|
|
|
|
if (scale) {
|
|
|
|
return new $.Point(1, 1);
|
|
|
|
} else {
|
|
|
|
return new $.Point(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $.TileSource.prototype.getNumTiles.call(this, level);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
* @param {Number} level
|
|
|
|
* @param {OpenSeadragon.Point} point
|
|
|
|
*/
|
|
|
|
getTileAtPoint: function( level, point ) {
|
|
|
|
|
|
|
|
if(this.emulateLegacyImagePyramid) {
|
|
|
|
return new $.Point(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $.TileSource.prototype.getTileAtPoint.call(this, level, point);
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responsible for retrieving the url which will return an image for the
|
2014-07-26 03:31:13 +04:00
|
|
|
* region specified by the given x, y, and level components.
|
|
|
|
* @function
|
|
|
|
* @param {Number} level - z index
|
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
|
|
|
getTileUrl: function( level, x, y ){
|
|
|
|
|
2015-12-14 00:32:21 +03:00
|
|
|
if(this.emulateLegacyImagePyramid) {
|
|
|
|
var url = null;
|
|
|
|
if ( this.levels.length > 0 && level >= this.minLevel && level <= this.maxLevel ) {
|
|
|
|
url = this.levels[ level ].url;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2014-07-26 03:31:13 +04:00
|
|
|
//# constants
|
|
|
|
var IIIF_ROTATION = '0',
|
|
|
|
//## get the scale (level as a decimal)
|
|
|
|
scale = Math.pow( 0.5, this.maxLevel - level ),
|
|
|
|
|
|
|
|
//# image dimensions at this level
|
|
|
|
levelWidth = Math.ceil( this.width * scale ),
|
|
|
|
levelHeight = Math.ceil( this.height * scale ),
|
|
|
|
|
|
|
|
//## iiif region
|
2015-07-01 00:56:06 +03:00
|
|
|
tileWidth,
|
|
|
|
tileHeight,
|
2014-07-26 03:31:13 +04:00
|
|
|
iiifTileSizeWidth,
|
|
|
|
iiifTileSizeHeight,
|
|
|
|
iiifRegion,
|
|
|
|
iiifTileX,
|
|
|
|
iiifTileY,
|
|
|
|
iiifTileW,
|
|
|
|
iiifTileH,
|
|
|
|
iiifSize,
|
2019-03-14 16:04:12 +03:00
|
|
|
iiifSizeW,
|
2019-12-17 18:22:48 +03:00
|
|
|
iiifSizeH,
|
2014-07-26 03:31:13 +04:00
|
|
|
iiifQuality,
|
2019-12-17 18:22:48 +03:00
|
|
|
uri;
|
2014-07-26 03:31:13 +04:00
|
|
|
|
2015-07-02 18:24:43 +03:00
|
|
|
tileWidth = this.getTileWidth(level);
|
2015-07-01 00:56:06 +03:00
|
|
|
tileHeight = this.getTileHeight(level);
|
|
|
|
iiifTileSizeWidth = Math.ceil( tileWidth / scale );
|
|
|
|
iiifTileSizeHeight = Math.ceil( tileHeight / scale );
|
2019-12-17 18:22:48 +03:00
|
|
|
if (this.version === 1) {
|
2019-03-19 10:47:40 +03:00
|
|
|
iiifQuality = "native." + this.tileFormat;
|
2014-07-26 03:31:13 +04:00
|
|
|
} else {
|
2019-03-19 10:47:40 +03:00
|
|
|
iiifQuality = "default." + this.tileFormat;
|
2014-07-26 03:31:13 +04:00
|
|
|
}
|
2015-07-01 00:56:06 +03:00
|
|
|
if ( levelWidth < tileWidth && levelHeight < tileHeight ){
|
2019-12-18 19:07:40 +03:00
|
|
|
if ( this.version === 2 && levelWidth === this.width ) {
|
2020-08-13 18:50:49 +03:00
|
|
|
iiifSize = "full";
|
2019-12-18 19:07:40 +03:00
|
|
|
} else if ( this.version === 3 && levelWidth === this.width && levelHeight === this.height ) {
|
2019-03-14 16:04:12 +03:00
|
|
|
iiifSize = "max";
|
2019-12-17 19:58:57 +03:00
|
|
|
} else if ( this.version === 3 ) {
|
|
|
|
iiifSize = levelWidth + "," + levelHeight;
|
|
|
|
} else {
|
|
|
|
iiifSize = levelWidth + ",";
|
2019-03-14 16:04:12 +03:00
|
|
|
}
|
2014-07-26 03:31:13 +04:00
|
|
|
iiifRegion = 'full';
|
|
|
|
} else {
|
|
|
|
iiifTileX = x * iiifTileSizeWidth;
|
|
|
|
iiifTileY = y * iiifTileSizeHeight;
|
|
|
|
iiifTileW = Math.min( iiifTileSizeWidth, this.width - iiifTileX );
|
|
|
|
iiifTileH = Math.min( iiifTileSizeHeight, this.height - iiifTileY );
|
2019-03-14 21:10:40 +03:00
|
|
|
if ( x === 0 && y === 0 && iiifTileW === this.width && iiifTileH === this.height ) {
|
2019-03-14 16:04:12 +03:00
|
|
|
iiifRegion = "full";
|
|
|
|
} else {
|
|
|
|
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
|
|
|
|
}
|
|
|
|
iiifSizeW = Math.ceil( iiifTileW * scale );
|
2019-12-17 18:22:48 +03:00
|
|
|
iiifSizeH = Math.ceil( iiifTileH * scale );
|
2019-12-18 19:07:40 +03:00
|
|
|
if ( this.version === 2 && iiifSizeW === this.width ) {
|
2020-08-13 18:50:49 +03:00
|
|
|
iiifSize = "full";
|
2019-12-18 19:07:40 +03:00
|
|
|
} else if ( this.version === 3 && iiifSizeW === this.width && iiifSizeH === this.height ) {
|
2019-03-14 16:04:12 +03:00
|
|
|
iiifSize = "max";
|
2019-12-17 19:58:57 +03:00
|
|
|
} else if (this.version === 3) {
|
|
|
|
iiifSize = iiifSizeW + "," + iiifSizeH;
|
2019-03-14 16:04:12 +03:00
|
|
|
} else {
|
2019-12-17 19:58:57 +03:00
|
|
|
iiifSize = iiifSizeW + ",";
|
2019-03-14 16:04:12 +03:00
|
|
|
}
|
2014-07-26 03:31:13 +04:00
|
|
|
}
|
|
|
|
uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
|
|
|
|
|
|
|
|
return uri;
|
2020-01-06 18:16:05 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
__testonly__: {
|
|
|
|
canBeTiled: canBeTiled,
|
|
|
|
constructLevels: constructLevels
|
2014-07-26 03:31:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-12-14 00:32:21 +03:00
|
|
|
/**
|
|
|
|
* Determine whether arbitrary tile requests can be made against a service with the given profile
|
|
|
|
* @function
|
2021-12-07 07:19:12 +03:00
|
|
|
* @param {Object} options
|
|
|
|
* @param {Array|String} options.profile
|
2021-11-29 03:46:45 +03:00
|
|
|
* @param {Number} options.version
|
2021-12-07 07:19:12 +03:00
|
|
|
* @param {String} options.extraFeatures
|
2021-11-29 03:46:45 +03:00
|
|
|
* @returns {Boolean}
|
2015-12-14 00:32:21 +03:00
|
|
|
*/
|
2019-12-17 18:22:48 +03:00
|
|
|
function canBeTiled ( options ) {
|
2015-12-14 00:32:21 +03:00
|
|
|
var level0Profiles = [
|
|
|
|
"http://library.stanford.edu/iiif/image-api/compliance.html#level0",
|
|
|
|
"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",
|
2019-12-17 18:22:48 +03:00
|
|
|
"http://iiif.io/api/image/2/level0.json",
|
|
|
|
"level0",
|
|
|
|
"https://iiif.io/api/image/3/level0.json"
|
2015-12-14 00:32:21 +03:00
|
|
|
];
|
2020-01-07 18:10:14 +03:00
|
|
|
var profileLevel = Array.isArray(options.profile) ? options.profile[0] : options.profile;
|
|
|
|
var isLevel0 = (level0Profiles.indexOf(profileLevel) !== -1);
|
2019-12-17 18:22:48 +03:00
|
|
|
var hasCanoncicalSizeFeature = false;
|
|
|
|
if ( options.version === 2 && options.profile.length > 1 && options.profile[1].supports ) {
|
|
|
|
hasCanoncicalSizeFeature = options.profile[1].supports.indexOf( "sizeByW" ) !== -1;
|
|
|
|
}
|
|
|
|
if ( options.version === 3 && options.extraFeatures ) {
|
|
|
|
hasCanoncicalSizeFeature = options.extraFeatures.indexOf( "sizeByWh" ) !== -1;
|
2019-03-14 16:04:12 +03:00
|
|
|
}
|
2019-12-17 18:22:48 +03:00
|
|
|
return !isLevel0 || hasCanoncicalSizeFeature;
|
2015-12-14 00:32:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the legacy pyramid URLs (one tile per level)
|
|
|
|
* @function
|
|
|
|
* @param {object} options - infoJson
|
|
|
|
* @throws {Error}
|
|
|
|
*/
|
|
|
|
function constructLevels(options) {
|
|
|
|
var levels = [];
|
2017-01-08 17:52:57 +03:00
|
|
|
for(var i = 0; i < options.sizes.length; i++) {
|
2015-12-14 00:32:21 +03:00
|
|
|
levels.push({
|
2019-12-17 18:22:48 +03:00
|
|
|
url: options['@id'] + '/full/' + options.sizes[i].width + ',' +
|
|
|
|
(options.version === 3 ? options.sizes[i].height : '') +
|
|
|
|
'/0/default.' + options.tileFormat,
|
2015-12-14 00:32:21 +03:00
|
|
|
width: options.sizes[i].width,
|
|
|
|
height: options.sizes[i].height
|
|
|
|
});
|
|
|
|
}
|
2017-01-08 17:52:57 +03:00
|
|
|
return levels.sort(function(a, b) {
|
|
|
|
return a.width - b.width;
|
|
|
|
});
|
2015-12-14 00:32:21 +03:00
|
|
|
}
|
|
|
|
|
2015-02-03 15:58:33 +03:00
|
|
|
|
2014-07-26 03:31:13 +04:00
|
|
|
function configureFromXml10(xmlDoc) {
|
|
|
|
//parse the xml
|
|
|
|
if ( !xmlDoc || !xmlDoc.documentElement ) {
|
|
|
|
throw new Error( $.getString( "Errors.Xml" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
var root = xmlDoc.documentElement,
|
|
|
|
rootName = root.tagName,
|
|
|
|
configuration = null;
|
|
|
|
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( rootName === "info" ) {
|
2014-07-26 03:31:13 +04:00
|
|
|
try {
|
|
|
|
configuration = {};
|
|
|
|
parseXML10( root, configuration );
|
|
|
|
return configuration;
|
|
|
|
|
|
|
|
} catch ( e ) {
|
|
|
|
throw (e instanceof Error) ?
|
|
|
|
e :
|
|
|
|
new Error( $.getString("Errors.IIIF") );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new Error( $.getString( "Errors.IIIF" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseXML10( node, configuration, property ) {
|
|
|
|
var i,
|
|
|
|
value;
|
2020-06-26 02:01:14 +03:00
|
|
|
if ( node.nodeType === 3 && property ) {//text node
|
2014-07-26 03:31:13 +04:00
|
|
|
value = node.nodeValue.trim();
|
|
|
|
if( value.match(/^\d*$/)){
|
|
|
|
value = Number( value );
|
|
|
|
}
|
|
|
|
if( !configuration[ property ] ){
|
|
|
|
configuration[ property ] = value;
|
|
|
|
}else{
|
|
|
|
if( !$.isArray( configuration[ property ] ) ){
|
|
|
|
configuration[ property ] = [ configuration[ property ] ];
|
|
|
|
}
|
|
|
|
configuration[ property ].push( value );
|
|
|
|
}
|
2020-06-26 02:01:14 +03:00
|
|
|
} else if( node.nodeType === 1 ){
|
2014-07-26 03:31:13 +04:00
|
|
|
for( i = 0; i < node.childNodes.length; i++ ){
|
|
|
|
parseXML10( node.childNodes[ i ], configuration, node.nodeName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 00:32:21 +03:00
|
|
|
|
2014-07-26 03:31:13 +04:00
|
|
|
}( OpenSeadragon ));
|