annotorious / annotorious-openseadragon

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

Issues with asynchronous functions (await not working) #126

Closed hsellik closed 1 year ago

hsellik commented 2 years ago

Hi,

I am trying to set annotations and then immediately zoom to those annotations. However, the await doesn't work for me properly.

Here's an example: https://stackblitz.com/edit/js-f2v3uc?file=index.js

If I use timeout, it works good, but it's not a preferred solution.

Any idea about what could be happening here?

rsimon commented 2 years ago

I think I've come across this before. It looks like there's not much that can be done about out right now (given the way the zoom function currently works). Timeout might currently be your only workaround.

Some background: setAnnotations is not an async function. The effect you're seeing is that setAnnotations completes immediately, but the DOM update itself takes a while to process in the browser. The problem, now, is that fitAnnotations fetches the annotation from the DOM, and then fits the viewport.

The only way to resolve this cleanly inside Annotorious would be to rewrite fitAnnotations, to make it independent from the DOM. This way, zooming would work even before the annotation is actually rendered to the DOM. I'll leave that issue open, for the case that I get the chance to look into this soon-ish.

hsellik commented 2 years ago

Alright, I see. Thanks for the quick response. :)