2

I'm using OpenSeaDragon for the first time and I'm trying to display to the console zoom level and Viewport center.

Now I found out how to display coordinates on click (Openseadragon image cordinates), but I'm having trouble w/ zoom and center. From looking at the API doc, I'm thinking that I need to use getCenter and getZoom of method Viewport, but syntactically I'm lost. Any help would be much appreciated. Thanks!


So after some help, here's the code I ended up using to get click coordinates as well as zoom and center (in image coordinates):

viewer.addHandler('canvas-click', function(target, info) {
    var viewportPoint = viewer.viewport.pointFromPixel(info.position);
    var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint.x, viewportPoint.y);
    console.log(imagePoint.x, imagePoint.y);
    console.log(viewer.viewport.getZoom());
    var viewportCenter = viewer.viewport.getCenter();
    var imageCenter = viewer.viewport.viewportToImageCoordinates(viewportCenter.x, viewportCenter.y);
    console.log(imageCenter.x, imageCenter.y);
});
Community
  • 1
  • 1
feldog84
  • 21
  • 1
  • 3
  • Be careful, there have been changes in newer versions of OSD. The `info` argument will be undefined now. See this thread, e.g.: http://stackoverflow.com/q/18417287/981694 – some-non-descript-user Dec 15 '15 at 09:36

1 Answers1

3

You're on the right track. If your viewer is called viewer, you would do viewer.viewport.getZoom() for instance.

The viewport has a number of other coordinate conversion methods:

http://openseadragon.github.io/docs/symbols/OpenSeadragon.Viewport.html

...and there's also a plugin that provides even more, if you need:

https://github.com/msalsbery/openseadragonimaginghelper

iangilman
  • 2,144
  • 1
  • 13
  • 16