Search code examples
seadragonopenseadragon

Openseadragon image cordinates


iam doing a project using openseadragon check out the below example. a samle openseadragon image

In the Onclick method want to find the cordinates(px,py) of the image.Is there any method?? please help this is ma first openseadragon project.

thanks


Solution

  • When you get a click, it'll be in window pixel coordinates. You can then translate it into viewport coordinates (which go from 0.0 on the left to 1.0 on the right). You can then translate those into image coordinates. Here's how it would look all together:

    viewer.addHandler('canvas-click', function(event) {
      var viewportPoint = viewer.viewport.pointFromPixel(event.position);
      var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint.x, viewportPoint.y);
      console.log(imagePoint.x, imagePoint.y);
    });
    

    For more info on the coordinate systems, see: http://openseadragon.github.io/examples/viewport-coordinates/