annotorious / annotorious-openseadragon

An OpenSeadragon plugin for annotating high-res zoomable images
https://annotorious.github.io
BSD 3-Clause "New" or "Revised" License
121 stars 43 forks source link

Autosave annotations when widget closes #187

Open raulgabor opened 9 months ago

raulgabor commented 9 months ago

Hi,

I was wondering if there is any possibility in saving an annotation when the user clicks outside the widget to close it (basically it autosaves the annotation without hitting the OK button). I've already made this work with the saveSelected() method when the user clicks outside of the OSD viewer, but I can't get it to work when the user does it inside the viewer. Is there a way to do this or even possible?

Thanks!

rsimon commented 9 months ago

I don't think this is actually possible right now, unfortunately. The cancelSelected event doesn't pass the latest state of the annotation, so there's no way to get a handle on it.

The only (tedious/hacky) workaround might be that you create your own 'clicktrap' - a DIV that's overlaid on top of the OpenSeadragon viewer, and which would block mouse events passing through. Then you could listen to events on that DIV, and instead save + close the editor programmatically.

Must admit I haven't thought this through completely. At least, there will be some z-index trickery required.

FWIW: Annotorious v3 (currently a separate branch in the main Annotorious repo) is almost ready to go. And it will work in a much different way. Most importantly, it will have proper state management, which would make scenarios such as yours a lot easier I think.