feldog84
feldog84

Reputation: 31

Displaying Zoom and Center on OpenSeadragon

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);
});

Upvotes: 3

Views: 4161

Answers (1)

iangilman
iangilman

Reputation: 2174

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

Upvotes: 3

Related Questions