Spaces:
Sleeping
Sleeping
Moved JS stuff to JS module
Browse files- js/scripts.js +124 -0
js/scripts.js
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var viewer = OpenSeadragon({
|
2 |
+
id: "wsi-canvas",
|
3 |
+
prefixUrl: "../node_modules/openseadragon/build/openseadragon/images/",
|
4 |
+
zoomPerScroll: 2,
|
5 |
+
zoomPerClick: 1,
|
6 |
+
showNavigator: true,
|
7 |
+
showHomeControl: false,
|
8 |
+
showFullPageControl: false,
|
9 |
+
showZoomControl: false,
|
10 |
+
minZoomLevel: 0.25,
|
11 |
+
maxZoomLevel: 40,
|
12 |
+
tileSources: {
|
13 |
+
Image: {
|
14 |
+
xmlns: "http://schemas.microsoft.com/deepzoom/2008",
|
15 |
+
Url: "../A05_files/",
|
16 |
+
Format: "jpeg",
|
17 |
+
Overlap: "0",
|
18 |
+
TileSize: "256",
|
19 |
+
Size: {
|
20 |
+
Height: 42625,
|
21 |
+
Width: 51553
|
22 |
+
}
|
23 |
+
},
|
24 |
+
overlays: [],
|
25 |
+
},
|
26 |
+
});
|
27 |
+
viewer.innerTracker.keyHandler = null;
|
28 |
+
|
29 |
+
var anno = OpenSeadragon.Annotorious(viewer);
|
30 |
+
Annotorious.SelectorPack(anno);
|
31 |
+
|
32 |
+
const toolbar = new Annotorious.Toolbar(anno, document.getElementById('annotation-toolbar'));
|
33 |
+
viewer.addControl(document.getElementById("annotation-toolbar"), { anchor: OpenSeadragon.ControlAnchor.TOP_LEFT });
|
34 |
+
|
35 |
+
document.getElementById('annotation-toolbar').addEventListener('click', function (event) {
|
36 |
+
event.preventDefault();
|
37 |
+
});
|
38 |
+
|
39 |
+
// Listen for annotation creation event
|
40 |
+
anno.on('createAnnotation', function (annotation) {
|
41 |
+
// Create a new div element for the annotation
|
42 |
+
var annotationItem = document.createElement('div');
|
43 |
+
annotationItem.className = 'annotation-item';
|
44 |
+
annotationItem.dataset.annotationId = annotation.id;
|
45 |
+
|
46 |
+
// Add annotation details to the item
|
47 |
+
annotationItem.innerHTML = `${annotation.body[0].value}`;
|
48 |
+
|
49 |
+
// Add click event to make the annotation active
|
50 |
+
annotationItem.addEventListener('click', function () {
|
51 |
+
anno.selectAnnotation(annotation.id);
|
52 |
+
});
|
53 |
+
|
54 |
+
// Append the annotation item to the annotations list in the sidebar
|
55 |
+
document.getElementById('annotations-list').appendChild(annotationItem);
|
56 |
+
});
|
57 |
+
|
58 |
+
// Listen for annotation deletion event
|
59 |
+
anno.on('deleteAnnotation', function (annotation) {
|
60 |
+
// Find the corresponding annotation item in the sidebar
|
61 |
+
var annotationItems = document.querySelectorAll('.annotation-item');
|
62 |
+
annotationItems.forEach(function (item) {
|
63 |
+
if (item.dataset.annotationId === annotation.id) {
|
64 |
+
item.remove();
|
65 |
+
}
|
66 |
+
});
|
67 |
+
});
|
68 |
+
|
69 |
+
// Disable panning when polygon tool is active
|
70 |
+
anno.on('startSelection', function (event) {
|
71 |
+
if (event.tool === 'polygon') {
|
72 |
+
viewer.setMouseNavEnabled(false);
|
73 |
+
}
|
74 |
+
});
|
75 |
+
|
76 |
+
// Re-enable panning when polygon tool is deactivated
|
77 |
+
anno.on('cancelSelection', function (event) {
|
78 |
+
if (event.tool === 'polygon') {
|
79 |
+
viewer.setMouseNavEnabled(true);
|
80 |
+
}
|
81 |
+
});
|
82 |
+
|
83 |
+
anno.on('createAnnotation', function (event) {
|
84 |
+
if (event.tool === 'polygon') {
|
85 |
+
viewer.setMouseNavEnabled(true);
|
86 |
+
}
|
87 |
+
});
|
88 |
+
|
89 |
+
// Add a listener to the viewer to update the position and zoom info
|
90 |
+
var positionEl = document.querySelectorAll('.sidebar-right .position')[0];
|
91 |
+
var zoomEl = document.querySelectorAll('.sidebar-right .zoom')[0];
|
92 |
+
|
93 |
+
// Default values
|
94 |
+
positionEl.innerHTML = 'Web:<br> (NA) <br><br>Viewport:<br> (NA) <br><br>Image:<br> (NA)';
|
95 |
+
zoomEl.innerHTML = 'Zoom:<br> NA <br><br>Image Zoom:<br> NA';
|
96 |
+
|
97 |
+
var updateZoom = function () {
|
98 |
+
var zoom = viewer.viewport.getZoom(true);
|
99 |
+
var imageZoom = viewer.viewport.viewportToImageZoom(zoom);
|
100 |
+
|
101 |
+
zoomEl.innerHTML = 'Zoom:<br>' + (Math.round(zoom * 100) / 100) +
|
102 |
+
'<br><br>Image Zoom:<br>' + (Math.round(imageZoom * 100) / 100);
|
103 |
+
}
|
104 |
+
|
105 |
+
viewer.addHandler('open', function () {
|
106 |
+
var tracker = new OpenSeadragon.MouseTracker({
|
107 |
+
element: viewer.container,
|
108 |
+
moveHandler: function (event) {
|
109 |
+
var webPoint = event.position;
|
110 |
+
var viewportPoint = viewer.viewport.pointFromPixel(webPoint);
|
111 |
+
var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint);
|
112 |
+
var zoom = viewer.viewport.getZoom(true);
|
113 |
+
var imageZoom = viewer.viewport.viewportToImageZoom(zoom);
|
114 |
+
|
115 |
+
positionEl.innerHTML = 'Web:<br>' + webPoint.toString() +
|
116 |
+
'<br><br>Viewport:<br>' + viewportPoint.toString() +
|
117 |
+
'<br><br>Image:<br>' + imagePoint.toString();
|
118 |
+
|
119 |
+
updateZoom();
|
120 |
+
}
|
121 |
+
});
|
122 |
+
tracker.setTracking(true);
|
123 |
+
viewer.addHandler('animation', updateZoom);
|
124 |
+
});
|