-
Notifications
You must be signed in to change notification settings - Fork 0
/
iiif.js
65 lines (58 loc) · 1.92 KB
/
iiif.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* IIIF Protocol Handler
*/
Protocols.IIIF = new Class({
/* Return metadata URL
*/
getMetaDataURL: function(server,image){
return server + "/" + image + "/info.json";
},
/* Return an individual tile request URL
*/
getTileURL: function(server,image,resolution,sds,contrast,k,x,y){
var f = this.getMultiplier(resolution);
var orig_x = x*f;
var orig_y = y*f;
var tile_x = this.tileSize.w * Math.pow(2, this.num_resolutions - resolution - 1) ;
var tile_y = this.tileSize.h * Math.pow(2, this.num_resolutions - resolution - 1) ;
var src = server + "/" + image + "/" + orig_x + "," + orig_y + "," + tile_x + "," + tile_y
if (tile_x != 256) {
src += "/!256,256";
} else {
src += "/full";
}
src += "/0/native.jpg";
return src;
},
/* Parse an IIIF protocol metadata request
*/
parseMetaData: function(response){
var p = eval("(" + response + ")");
var w = parseInt(p.width);
var h = parseInt(p.height);
this.num_resolutions = p.scale_factors.length;
this.tileSize = { w: 256, h: 256 };
var result = {
'max_size': { w: w, h: h },
'tileSize': this.tileSize,
'num_resolutions': this.num_resolutions
};
return result;
},
/* Return URL for a full view
*/
getRegionURL: function(server,image,region,width){
return server + "/" + image + "/" + region.x + "," + region.y
+ "," + region.w + "," + region.h + "/" + width + ",/0/native.jpg";
},
/* Return thumbnail URL
*/
getThumbnailURL: function(server,image,width){
return server + "/" + image + "/full/" + width + ",/0/native.jpg";
},
/* Like Djatoka, IIIF wants the region offests in terms of the highest resolution it has.
* Here, we multiply up the offsets to that resolution.
*/
getMultiplier: function(resolution) {
return this.tileSize.w * Math.pow(2, this.num_resolutions - resolution - 1);
}
});