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

.getSelectedImageSnippet() error #184

Closed AnanthParimi closed 10 months ago

AnanthParimi commented 10 months ago

So I am trying to get a snippet of a selected annotation using the .getSelectedImageSnippet() function. I declared a function which gets the snippet, and added this to a button.

const handleCaptureScreenshot = () => { if(anno && viewer){ const{snippet , transform } = anno.getSelectedImageSnippet(); setCapturedImageSnippet(snippet.todataURL()); } }

I am getting a runtime error that "OpenSeadragon is not defined" in the ImageSnippet.js code in line 31. image

Upon reading the code I realized that the code didnot import OpenSeadragon, image

will adding this line import OpenSeadragon from 'openseadragon'; do it, or am I missing something.

Thanks in advance.

rsimon commented 10 months ago

Yes, I believe import OpenSeadragon from 'openseadragon'; should fix this.

It's weird that no-one has had problems with this earlier. The only setup where this can work is in applications that import OpenSeadragon via <script> tag. (Because then OpenSeadragon will be a global.) I believe that's what I did in all my demos. (I never used the feature in a 'real' app so far myself I think...) You might simply be the first person to actually use that with a bundler ;-)

rsimon commented 10 months ago

P.S.: in case you want to send a PR, please submit it against the 2.x branch, not the main branch. The main branch is now frozen, as it will switch to the v.3 branch soon. Critical updates, minor fixes and general maintenance of 2.7.x will happen on the v2.x branch from now on.

AnanthParimi commented 10 months ago

Thanks man. I just made a pull request on 2.6.x branch if that's okay cause that was the only v2.x I could find in annotorious-openseadragon. The link you provided in the earlier response was for annotorious.

Also I just wanted to appreciate how much this repo has helped me. If I made the PR in a wrong place please tell me where I should make the PR.

AnanthParimi commented 10 months ago

Is there any way I can use the updated code in my application before you merge the pull request. I tried npm install of my forked version, but to vain.

rsimon commented 10 months ago

Thanks for the PR! Ah, about the branch: sorry my fault, I got confused :-D The 3.x branch exists in the annotorious repository, but not this one. (From version 3.x onwards, there will only be one monorepo for both versions. This repo will remain open for critical fixes and such, but otherwise will be de-fact deprecated.) I redirected your PR to the main branch & merged.

And thanks for the nice feedback - I really appreciate it!

About using the update code yourself: I'll try to push a new release with the fix later today or tomorrow. Meanwhile, you could run npm install and ./build.sh in your fork. (If you're on Mac or Linux. The build script might need tweaking on Windows.) Then you'd have to change the package.json in your own project to point to your own local fork rather than the last published version on the npm registry.

Looks something like this:

"dependencies": {
  "@recogito/annotorious-openseadragon": "file:../relative/or/absolute-path/to/your/fork"
}
rsimon commented 10 months ago

The new release with your PR included is published! Version 2.7.13.

AnanthParimi commented 10 months ago

Just installed the newer version. It works perfectly.

Appreciate it! Thanks for quick replies and action.

Also from version 3.x, having only annotorious will work?

rsimon commented 10 months ago

Annotorious 3 will be organized a bit differently. There will still be separate packages for the vanilla JS versions of Annotorious standard (@annotorious/annotorious) and OpenSeadragon (@annotorious/openseadragon).

Then there will be packages for framework bindings specifically (@annotorious/react and @annotorious/svelte - although I hope the community will contribute additional ones). The framework packages will include bindings for both versions.

All those modules will be maintained in a single repo (this one), however, not in separate repos.