-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
66 lines (63 loc) · 1.64 KB
/
lib.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
66
// TODO: move to stdlib
export function scaleMap(map, width, height) {
const scale = map.resource.width / width
console.log(' Scaling annotation by', Math.round(scale * 100) / 100)
return {
...map,
resource: {
...map.resource,
width,
height
},
gcps: map.gcps.map(({ resource, geo }) => ({
resource: [resource[0] / scale, resource[1] / scale],
geo
})),
resourceMask: map.resourceMask.map((coordinate) => [
Math.round(coordinate[0] / scale),
Math.round(coordinate[1] / scale)
])
}
}
// TODO: move to stdlib
export function createManifest(id, images) {
return {
'@context': 'http://iiif.io/api/presentation/3/context.json',
id,
type: 'Manifest',
items: images.map(({ imageId, width, height }) => ({
id: `${imageId}/canvas`,
type: 'Canvas',
width,
height,
items: [
{
id: `${imageId}/annotation-page`,
type: 'AnnotationPage',
items: [
{
id: `${imageId}/annotation`,
type: 'Annotation',
motivation: 'painting',
target: `${imageId}/canvas`,
body: {
id: `${imageId}/full/600,/0/default.jpg`,
type: 'Image',
format: 'image/jpg',
width,
height,
service: [
{
'@id': imageId,
'@type': 'ImageService2',
profile: 'http://iiif.io/api/image/2/level0.json'
}
]
}
}
]
}
]
}))
}
}