UNPKG

@cogic/annotorious

Version:

A JavaScript image annotation library

119 lines (102 loc) 3.16 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Annotorious | Editor Plugin Example</title> <link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet"> <link href="/annotorious.min.css" rel="stylesheet"> <script type="text/javascript" src="/annotorious.min.js"></script></head> <style> html, body { padding:20px; margin:0px; font-family:'Lato', sans-serif; } #content { width:100%; } h1 { font-size:21px; font-weight:normal; margin:0; padding:0; } p.instructions { padding:10px 0; } img { max-width:100%; } p.caption { font-family:Arial, Helvetica, sans-serif; color:#8f8f8f; } p.caption a { color:#3f3f3f; } </style> </head> <body> <div id="content"> <p> <button id="current-tool">RECTANGLE</button> <button id="toggle-editor">TOGGLE EDITOR</button> </p> <img id="hallstatt" src="/640px-Hallstatt.jpg"> </div> </div> <script> (function() { var anno = Annotorious.init({ image: 'hallstatt', locale: 'auto', disableEditor: true, disableDeleteKey: true }); anno.on('createSelection', async function(selection) { selection.body = [{ type: 'TextualBody', purpose: 'tagging', value: 'MyOtherTag' }]; await anno.updateSelected(selection); anno.saveSelected(); }); anno.on('selectAnnotation', function(a) { console.log('selectAnnotation', a); }); anno.on('cancelSelected', function(a) { console.log('cancelSelected', a); }); anno.on('createAnnotation', function(a) { console.log('created', a); }); anno.on('updateAnnotation', function(annotation, previous) { console.log('updated', previous, 'with', annotation); }); anno.on('mouseEnterAnnotation', function(a) { console.log('enter'); }); anno.on('mouseLeaveAnnotation', function(a) { console.log('leave'); }); var toolToggle = document.getElementById('current-tool'); toolToggle.addEventListener('click', function() { if (toolToggle.innerHTML == 'RECTANGLE') { toolToggle.innerHTML = 'POLYGON'; anno.setDrawingTool('polygon'); } else { toolToggle.innerHTML = 'RECTANGLE'; anno.setDrawingTool('rect'); } }); var editorToggle = document.getElementById('toggle-editor'); editorToggle.addEventListener('click', function() { const updatedState = !anno.disableEditor; console.log('setting disableEditor', updatedState); anno.disableEditor = updatedState; }); })() </script> </body> </html>