mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 22:56:11 +03:00
Add support for IIIF Image API 3.0 beta
This commit is contained in:
parent
ae4f586714
commit
8ae1edfd48
@ -59,6 +59,8 @@ $.IIIFTileSource = function( options ){
|
|||||||
|
|
||||||
this.tileFormat = this.tileFormat || 'jpg';
|
this.tileFormat = this.tileFormat || 'jpg';
|
||||||
|
|
||||||
|
this.version = options.version;
|
||||||
|
|
||||||
// N.B. 2.0 renamed scale_factors to scaleFactors
|
// N.B. 2.0 renamed scale_factors to scaleFactors
|
||||||
if ( this.tile_width && this.tile_height ) {
|
if ( this.tile_width && this.tile_height ) {
|
||||||
options.tileWidth = this.tile_width;
|
options.tileWidth = this.tile_width;
|
||||||
@ -88,7 +90,7 @@ $.IIIFTileSource = function( options ){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( canBeTiled(options.profile) ) {
|
} else if ( canBeTiled(options) ) {
|
||||||
// use the largest of tileOptions that is smaller than the short dimension
|
// use the largest of tileOptions that is smaller than the short dimension
|
||||||
var shortDim = Math.min( this.height, this.width ),
|
var shortDim = Math.min( this.height, this.width ),
|
||||||
tileOptions = [256, 512, 1024],
|
tileOptions = [256, 512, 1024],
|
||||||
@ -201,11 +203,42 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
var options = configureFromXml10( data );
|
var options = configureFromXml10( data );
|
||||||
options['@context'] = "http://iiif.io/api/image/1.0/context.json";
|
options['@context'] = "http://iiif.io/api/image/1.0/context.json";
|
||||||
options['@id'] = url.replace('/info.xml', '');
|
options['@id'] = url.replace('/info.xml', '');
|
||||||
|
options.version = 1;
|
||||||
return options;
|
return options;
|
||||||
} else {
|
} else {
|
||||||
if ( !data['@context'] ) {
|
if ( !data['@context'] ) {
|
||||||
data['@context'] = 'http://iiif.io/api/image/1.0/context.json';
|
data['@context'] = 'http://iiif.io/api/image/1.0/context.json';
|
||||||
data['@id'] = url.replace('/info.json', '');
|
data['@id'] = url.replace('/info.json', '');
|
||||||
|
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' &&
|
||||||
|
( /^http:\/\/iiif\.io\/api\/image\/[0-2]\/context\.json$/.test(context[i]) ||
|
||||||
|
context[i] === 'http://library.stanford.edu/iiif/image-api/1.1/context.json' ) ) {
|
||||||
|
context = context[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (data['@context']) {
|
||||||
|
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:
|
||||||
|
// unexpected context
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !data['@id'] && data['id'] ) {
|
||||||
|
data['@id'] = data['id'];
|
||||||
}
|
}
|
||||||
if(data.preferredFormats) {
|
if(data.preferredFormats) {
|
||||||
for (var f = 0; f < data.preferredFormats.length; f++ ) {
|
for (var f = 0; f < data.preferredFormats.length; f++ ) {
|
||||||
@ -350,25 +383,22 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
iiifTileH,
|
iiifTileH,
|
||||||
iiifSize,
|
iiifSize,
|
||||||
iiifSizeW,
|
iiifSizeW,
|
||||||
|
iiifSizeH,
|
||||||
iiifQuality,
|
iiifQuality,
|
||||||
uri,
|
uri;
|
||||||
isv1;
|
|
||||||
|
|
||||||
tileWidth = this.getTileWidth(level);
|
tileWidth = this.getTileWidth(level);
|
||||||
tileHeight = this.getTileHeight(level);
|
tileHeight = this.getTileHeight(level);
|
||||||
iiifTileSizeWidth = Math.ceil( tileWidth / scale );
|
iiifTileSizeWidth = Math.ceil( tileWidth / scale );
|
||||||
iiifTileSizeHeight = Math.ceil( tileHeight / scale );
|
iiifTileSizeHeight = Math.ceil( tileHeight / scale );
|
||||||
isv1 = ( this['@context'].indexOf('/1.0/context.json') > -1 ||
|
if (this.version === 1) {
|
||||||
this['@context'].indexOf('/1.1/context.json') > -1 ||
|
|
||||||
this['@context'].indexOf('/1/context.json') > -1 );
|
|
||||||
if (isv1) {
|
|
||||||
iiifQuality = "native." + this.tileFormat;
|
iiifQuality = "native." + this.tileFormat;
|
||||||
} else {
|
} else {
|
||||||
iiifQuality = "default." + this.tileFormat;
|
iiifQuality = "default." + this.tileFormat;
|
||||||
}
|
}
|
||||||
if ( levelWidth < tileWidth && levelHeight < tileHeight ){
|
if ( levelWidth < tileWidth && levelHeight < tileHeight ){
|
||||||
if ( isv1 || levelWidth !== this.width ) {
|
if ( this.version === 1 || levelWidth !== this.width ) {
|
||||||
iiifSize = levelWidth + ",";
|
iiifSize = levelWidth + "," + ( this.version === 3 ? levelHeight : "" );
|
||||||
} else {
|
} else {
|
||||||
iiifSize = "max";
|
iiifSize = "max";
|
||||||
}
|
}
|
||||||
@ -384,10 +414,11 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
|
iiifRegion = [ iiifTileX, iiifTileY, iiifTileW, iiifTileH ].join( ',' );
|
||||||
}
|
}
|
||||||
iiifSizeW = Math.ceil( iiifTileW * scale );
|
iiifSizeW = Math.ceil( iiifTileW * scale );
|
||||||
if ( (!isv1) && iiifSizeW === this.width ) {
|
iiifSizeH = Math.ceil( iiifTileH * scale );
|
||||||
|
if ( this.version !== 1 && iiifSizeW === this.width && ( this.version !== 3 || iiifSizeH === this.height ) ) {
|
||||||
iiifSize = "max";
|
iiifSize = "max";
|
||||||
} else {
|
} else {
|
||||||
iiifSize = iiifSizeW + ",";
|
iiifSize = iiifSizeW + "," + ( this.version === 3 ? iiifSizeH : "" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
|
uri = [ this['@id'], iiifRegion, iiifSize, IIIF_ROTATION, iiifQuality ].join( '/' );
|
||||||
@ -403,18 +434,23 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
* @param {array} profile - IIIF profile array
|
* @param {array} profile - IIIF profile array
|
||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
function canBeTiled ( profile ) {
|
function canBeTiled ( options ) {
|
||||||
var level0Profiles = [
|
var level0Profiles = [
|
||||||
"http://library.stanford.edu/iiif/image-api/compliance.html#level0",
|
"http://library.stanford.edu/iiif/image-api/compliance.html#level0",
|
||||||
"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",
|
"http://library.stanford.edu/iiif/image-api/1.1/compliance.html#level0",
|
||||||
"http://iiif.io/api/image/2/level0.json"
|
"http://iiif.io/api/image/2/level0.json",
|
||||||
|
"level0",
|
||||||
|
"https://iiif.io/api/image/3/level0.json"
|
||||||
];
|
];
|
||||||
var isLevel0 = (level0Profiles.indexOf(profile[0]) !== -1);
|
var isLevel0 = (level0Profiles.indexOf(options.profile[0]) !== -1);
|
||||||
var hasSizeByW = false;
|
var hasCanoncicalSizeFeature = false;
|
||||||
if ( profile.length > 1 && profile[1].supports ) {
|
if ( options.version === 2 && options.profile.length > 1 && options.profile[1].supports ) {
|
||||||
hasSizeByW = profile[1].supports.indexOf( "sizeByW" ) !== -1;
|
hasCanoncicalSizeFeature = options.profile[1].supports.indexOf( "sizeByW" ) !== -1;
|
||||||
}
|
}
|
||||||
return !isLevel0 || hasSizeByW;
|
if ( options.version === 3 && options.extraFeatures ) {
|
||||||
|
hasCanoncicalSizeFeature = options.extraFeatures.indexOf( "sizeByWh" ) !== -1;
|
||||||
|
}
|
||||||
|
return !isLevel0 || hasCanoncicalSizeFeature;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -427,7 +463,9 @@ $.extend( $.IIIFTileSource.prototype, $.TileSource.prototype, /** @lends OpenSea
|
|||||||
var levels = [];
|
var levels = [];
|
||||||
for(var i = 0; i < options.sizes.length; i++) {
|
for(var i = 0; i < options.sizes.length; i++) {
|
||||||
levels.push({
|
levels.push({
|
||||||
url: options['@id'] + '/full/' + options.sizes[i].width + ',/0/default.' + options.tileFormat,
|
url: options['@id'] + '/full/' + options.sizes[i].width + ',' +
|
||||||
|
(options.version === 3 ? options.sizes[i].height : '') +
|
||||||
|
'/0/default.' + options.tileFormat,
|
||||||
width: options.sizes[i].width,
|
width: options.sizes[i].width,
|
||||||
height: options.sizes[i].height
|
height: options.sizes[i].height
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user