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

Mouse coordinates issue #172

Closed dianamarginean closed 1 year ago

dianamarginean commented 1 year ago

Hi.

I'm using Annotorius with OSD and faced the following problem I currently want to get the {X,Y} coordinates of a mouse and compare it with a point from a SVG polygon. I added an different events on: canvas, svg, document, but the coordinates are very little comparing with the ones from the points from the svg points.

As an example my mouse point coordinates when clicking inside a polygon is image

The points from the svg polygon are

image

The difference between the 2 coordinates is a range between [10.000 - 20.000]. why is the cause of this?

Any Ideas? I also tried to modify the mouse coordinates by multiplying it with 100 or followed these links, but with no success https://stackoverflow.com/questions/10298658/mouse-position-inside-autoscaled-svg

rsimon commented 1 year ago

The mouse coordinates are relative to your viewport, or the DOM element you are attaching the listener to (depending on which properties of the event you are using - offsetX, clientX etc.). The coordinates used by Annotorious (and on the SVG layer) are relative to the image's original size.

To compare, you need to convert the mouse coordinates to image coordinates (or vice versa), using OpenSeadragon's built-in functions, and compare then. See e.g.: https://openseadragon.github.io/docs/OpenSeadragon.Viewport.html#viewerElementToImageCoordinates

P.S.: Depending on what it is you want to do, there might be more efficient ways to achieve your goal. If you are comparing against a lot of annotations, things might get slow. AnnotoriousOSD already uses a 2D-index internally, and could do fast intersection checking for example. All a bit undocumented though...

dianamarginean commented 1 year ago

@rsimon thank you it worked