andreped commited on
Commit
cebb7be
2 Parent(s): 3497e33 7ad4738

Merge pull request #3 from andreped/ui-fixes

Browse files

Show annotation objects in left sidebar; add zoom and position info to right sidebar; fix bug for certain annotation types

Files changed (1) hide show
  1. index.html +111 -7
index.html CHANGED
@@ -2,6 +2,8 @@
2
  <head>
3
  <title>Whole Slide Image Annotation</title>
4
 
 
 
5
  <link rel="stylesheet" href="node_modules/@recogito/annotorious/dist/annotorious.min.css">
6
  <link rel="stylesheet" href="node_modules/@recogito/annotorious-selector-pack/dist/annotorious-selector-pack.min.css">
7
 
@@ -12,21 +14,28 @@
12
  <script src="https://cdn.jsdelivr.net/npm/@recogito/[email protected]/dist/annotorious-selector-pack.min.js"></script>
13
  </head>
14
  <body>
15
- <div style="padding: 0 0em; height: 95%; background: #303030">
16
  <div class="sidebar-left" style="float: left; width: 10%;">
17
- <h1 style="color: white; font-size: 16; padding: 0 1.5em;">Whole Slide Image Annotation Demo</h1>
18
 
19
- <hr style="border: 1px solid white;">
20
 
21
- <div class="position"></div>
22
- <div class="zoom" style="margin-top: 3em;"></div>
 
 
 
23
  </div>
24
  <div id="wsi-canvas" style="float: left; width: 80%; height: 100%; background: white;"></div>
25
  <div id="annotation-toolbar"></div>
26
 
27
  <div class="sidebar-right" style="float: right; width: 10%;">
28
- <div class="position"></div>
29
- <div class="zoom" style="margin-top: 3em;"></div>
 
 
 
 
30
  </div>
31
 
32
  <div id="annotation_list" style="display: none;"></div>
@@ -70,6 +79,101 @@
70
  document.getElementById('annotation-toolbar').addEventListener('click', function(event) {
71
  event.preventDefault();
72
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  </script>
74
  </body>
75
  </html>
 
2
  <head>
3
  <title>Whole Slide Image Annotation</title>
4
 
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6
+
7
  <link rel="stylesheet" href="node_modules/@recogito/annotorious/dist/annotorious.min.css">
8
  <link rel="stylesheet" href="node_modules/@recogito/annotorious-selector-pack/dist/annotorious-selector-pack.min.css">
9
 
 
14
  <script src="https://cdn.jsdelivr.net/npm/@recogito/[email protected]/dist/annotorious-selector-pack.min.js"></script>
15
  </head>
16
  <body>
17
+ <div style="padding: 0 0em; height: 100%; background: #303030">
18
  <div class="sidebar-left" style="float: left; width: 10%;">
19
+ <h1 style="color: white; font-size: 16px; padding: 0 1.5em;">Whole Slide Image Annotation Demo</h1>
20
 
21
+ <hr style="border: 2px solid white;">
22
 
23
+ <div id="annotations-container">
24
+ <h2 style="color: white; padding: 0 0.5em; font-size: 14px;">Annotations</h2>
25
+ <hr style="border: 0.25px solid white;">
26
+ <div id="annotations-list"></div>
27
+ </div>
28
  </div>
29
  <div id="wsi-canvas" style="float: left; width: 80%; height: 100%; background: white;"></div>
30
  <div id="annotation-toolbar"></div>
31
 
32
  <div class="sidebar-right" style="float: right; width: 10%;">
33
+ <h2 style="color: white; padding: 0 0.5em; font-size: 14px;">Info</h2>
34
+ <hr style="border: 0.25px solid white;">
35
+
36
+ <div class="position" style="color: white; padding: 0 0.5em; font-size: 14px;"></div>
37
+ <hr style="border: 0.25px solid white;">
38
+ <div class="zoom" style="color: white; padding: 0 0.5em; font-size: 14px;"></div>
39
  </div>
40
 
41
  <div id="annotation_list" style="display: none;"></div>
 
79
  document.getElementById('annotation-toolbar').addEventListener('click', function(event) {
80
  event.preventDefault();
81
  });
82
+
83
+ // Listen for annotation creation event
84
+ anno.on('createAnnotation', function(annotation) {
85
+ // Create a new div element for the annotation
86
+ var annotationItem = document.createElement('div');
87
+ annotationItem.className = 'annotation-item';
88
+ annotationItem.style.color = 'white';
89
+ annotationItem.style.padding = '10px';
90
+ annotationItem.style.border = '1px solid white';
91
+ annotationItem.style.marginTop = '10px';
92
+ annotationItem.style.cursor = 'pointer';
93
+ annotationItem.style.fontSize = '12px'; // Set font size in pixels
94
+ annotationItem.dataset.annotationId = annotation.id;
95
+
96
+ // Add annotation details to the item
97
+ annotationItem.innerHTML = `
98
+ ${annotation.body[0].value}
99
+ `;
100
+
101
+ // Add click event to make the annotation active
102
+ annotationItem.addEventListener('click', function() {
103
+ anno.selectAnnotation(annotation.id);
104
+ });
105
+
106
+ // Append the annotation item to the annotations list in the sidebar
107
+ document.getElementById('annotations-list').appendChild(annotationItem);
108
+ });
109
+
110
+ // Listen for annotation deletion event
111
+ anno.on('deleteAnnotation', function(annotation) {
112
+ // Find the corresponding annotation item in the sidebar
113
+ var annotationItems = document.querySelectorAll('.annotation-item');
114
+ annotationItems.forEach(function(item) {
115
+ if (item.dataset.annotationId === annotation.id) {
116
+ item.remove();
117
+ }
118
+ });
119
+ });
120
+
121
+ // Disable panning when polygon tool is active
122
+ anno.on('startSelection', function(event) {
123
+ if (event.tool === 'polygon') {
124
+ viewer.setMouseNavEnabled(false);
125
+ }
126
+ });
127
+
128
+ // Re-enable panning when polygon tool is deactivated
129
+ anno.on('cancelSelection', function(event) {
130
+ if (event.tool === 'polygon') {
131
+ viewer.setMouseNavEnabled(true);
132
+ }
133
+ });
134
+
135
+ anno.on('createAnnotation', function(event) {
136
+ if (event.tool === 'polygon') {
137
+ viewer.setMouseNavEnabled(true);
138
+ }
139
+ });
140
+
141
+ // Add a listener to the viewer to update the position and zoom info
142
+ var positionEl = document.querySelectorAll('.sidebar-right .position')[0];
143
+ var zoomEl = document.querySelectorAll('.sidebar-right .zoom')[0];
144
+
145
+ // Default values
146
+ positionEl.innerHTML = 'Web:<br> (NA) <br><br>Viewport:<br> (NA) <br><br>Image:<br> (NA)';
147
+ zoomEl.innerHTML = 'Zoom:<br> NA <br><br>Image Zoom:<br> NA';
148
+
149
+ var updateZoom = function() {
150
+ var zoom = viewer.viewport.getZoom(true);
151
+ var imageZoom = viewer.viewport.viewportToImageZoom(zoom);
152
+
153
+ zoomEl.innerHTML = 'Zoom:<br>' + (Math.round(zoom * 100) / 100) +
154
+ '<br><br>Image Zoom:<br>' + (Math.round(imageZoom * 100) / 100);
155
+ }
156
+
157
+ viewer.addHandler('open', function() {
158
+ var tracker = new OpenSeadragon.MouseTracker({
159
+ element: viewer.container,
160
+ moveHandler: function(event) {
161
+ var webPoint = event.position;
162
+ var viewportPoint = viewer.viewport.pointFromPixel(webPoint);
163
+ var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint);
164
+ var zoom = viewer.viewport.getZoom(true);
165
+ var imageZoom = viewer.viewport.viewportToImageZoom(zoom);
166
+
167
+ positionEl.innerHTML = 'Web:<br>' + webPoint.toString() +
168
+ '<br><br>Viewport:<br>' + viewportPoint.toString() +
169
+ '<br><br>Image:<br>' + imagePoint.toString();
170
+
171
+ updateZoom();
172
+ }
173
+ });
174
+ tracker.setTracking(true);
175
+ viewer.addHandler('animation', updateZoom);
176
+ });
177
  </script>
178
  </body>
179
  </html>