I'm quite new to using openseadragon.
I have some dynamic overlays on my image. which will give the user some info's about the points on the image..
So what i need is to zoom in on an overlay on pageload, based on the active overlay.
I have the i'ds on the overlays, so was wandering if there is some simple function like: ZoomTo("OverlayId") to do the trick.
Let me know if you need more info.
We don't have a function like that. If you know the rectangle location of the overlay, you can do viewer.viewport.fitBounds(rect) to go there. That rectangle needs to be in viewport coordinates. Depending on how you created the overlay, you should have that information from when you created it.
On the other hand @iangilman, is there any (reasonable) way to get the location back from the overlay? I wanted to help here and I started to look for such solution, but I don't see the data anywhere in DOM tree. I suppose they must be stored somewhere?
In my hack I modified the added elements to store x,y, size and width so I can get them easily.
Well, if you know the id of the overlay, you can select that element in the DOM and find its bounds relative to the window and then use windowToViewportCoordinates to convert the position and deltaPointsFromPixels to convert the size.
Another option would be to loop through the viewer.currentOverlays looking for the one that matches the id (you can test the id of the overlay's element property) and then use its bounds property (a rectangle in viewport coordinates). Looks like none of this is documented though... :(
After 856f009 if you know overlay id you can use something like this:
myoverlay = viewer.getOverlayById('overlay-id');
viewer.viewport.fitBounds(myoverlay.getBounds());
Indeed! I consider this fixed by https://github.com/openseadragon/openseadragon/pull/853
I'd press like here ; )
Most helpful comment
After 856f009 if you know overlay id you can use something like this: