72 lines
2.0 KiB
JavaScript
72 lines
2.0 KiB
JavaScript
import IIIFResource from './IIIFResource.js';
|
|
/**
|
|
* @implements IIIFResource
|
|
*/
|
|
class Image {
|
|
id = '';
|
|
context = `https://iiif.io/api/presentation/${process.env.IIIF_API_VERSION}/context.json`;
|
|
type = 'oa:Annotation';
|
|
motivation = 'sc:painting';
|
|
__type = 'dctypes:Image';
|
|
__format = 'image/jpeg';
|
|
height = 0;
|
|
width = 0;
|
|
service = {
|
|
"@context" : this.context,
|
|
"@id" : '',
|
|
profile : 'https://iiif.io/api/image/2/level2.json',
|
|
};
|
|
canvasId = '';
|
|
/**
|
|
*
|
|
* @param {string} canvasId The canvas IIIF id
|
|
*/
|
|
constructor(canvasId) {
|
|
this.canvasId = canvasId;
|
|
}
|
|
/**
|
|
* @param {number} height
|
|
* @param {number} width
|
|
*/
|
|
setSize(height, width) {
|
|
this.height = height;
|
|
this.width = width;
|
|
}
|
|
/**
|
|
* Generate IIIF id pointing to image
|
|
* server endpoint for this image
|
|
* @param {string} serviceURL The image server base URL
|
|
* @param {string} filename The image's complete filename
|
|
*/
|
|
generateID(serviceURL, filename) {
|
|
let splitFilename = filename.split('_');
|
|
const baseFolder = splitFilename.slice(0,2).join('_') + '_iiif';
|
|
const subfolder = splitFilename.slice(0,3).join('_') + '_iiif';
|
|
|
|
this.id = `${serviceURL}/2/${baseFolder}%2F${subfolder}%2F${filename}/full/full/0/default.jpg`;
|
|
this.service['@id'] = this.id.replace(/\/full.*$/,'');
|
|
}
|
|
/**
|
|
* Object representation of this image
|
|
*
|
|
* @returns {Object}
|
|
*/
|
|
toObject() {
|
|
return {
|
|
"@context" : this.context,
|
|
"@type" : this.type,
|
|
motivation : this.motivation,
|
|
resource : {
|
|
"@id" : this.id,
|
|
"@type" : this.__type,
|
|
format: this.__format,
|
|
service : this.service,
|
|
height: this.height,
|
|
width: this.width,
|
|
},
|
|
on : this.canvasId
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Image; |