These are chat archives for openseadragon/openseadragon

17th
Jun 2015
Grant Echols
@gechols
Jun 17 2015 21:25 UTC
I'm working on a slight adjustment to the autoResize feature. I'd like to keep the image zoom more 'fixed' and hide and show more of the image as the viewport gets shrunk and expanded appropriately. I can see how much the viewport size has changed - so what is it I should be altering for the image to hide/show more image. I thought it was the 'bounds' (e.g. viewport.getBounds and viewport.setBounds) but that doesn't look right. Any pointers?
Ian Gilman
@iangilman
Jun 17 2015 21:28 UTC
Cool. I assume you mean fitBounds rather than setBounds? I think that should do it...you just need to keep in mind that the aspect ratio is probably changing, and that fitBounds will center the bounds you give it inside the given aspect ratio if you don't provide an exact match.
Grant Echols
@gechols
Jun 17 2015 21:31 UTC
I'll give fitBounds a check. Thanks!
Ian Gilman
@iangilman
Jun 17 2015 21:32 UTC
Cool. Make sure to pass true for the immediately flag, otherwise it'll bounce around
Grant Echols
@gechols
Jun 17 2015 21:41 UTC
It looks like the values coming back from the getBounds are all floating point values - suggesting these are ratios rather than pixels. Is there an easy way to convert from the ratios to pixel values so I can use the new container height and/or width to adjust the amount of the image shown?
Ian Gilman
@iangilman
Jun 17 2015 21:43 UTC
Indeed...those values are in viewport coordinates. You want to use viewport.pointFromPixel and/or viewport.deltaPointsFromPixels to convert
See http://openseadragon.github.io/examples/viewport-coordinates/ for more info on viewport coordinates
Grant Echols
@gechols
Jun 17 2015 22:10 UTC
I must be missing something. I've turned autoResize=false and am using the following code when the viewport is resized:
    var imageRect = viewer.viewport.viewportToImageRectangle(viewer.viewport.getHomeBounds());
    var deltaX = containerSize.x - prevContainerSize.x;
    var deltaY = containerSize.y - prevContainerSize.y;
    imageRect.width += deltaX;
    imageRect.height += deltaY;
    var newViewRect = viewer.viewport.imageToViewportRectangle(imageRect);
    viewer.viewport.fitBounds(newViewRect, true);
It doesn't seem to do anything different though I THOUGHT I was changing the amount of the image showing
Ian Gilman
@iangilman
Jun 17 2015 22:18 UTC
getHomeBounds is the rectangle that you'll return to if you hit the home button...I assume you want getBounds, which is the rectangle you're currently looking at
You're converting that rectangle into image coordinates, which is a third coordinate system incompatible with the web coordinates the containerSize is going to be in. You want to convert it into web coordinates instead.
Ian Gilman
@iangilman
Jun 17 2015 22:23 UTC
I'm not sure, but since you have autoResize=false, you might also need to call viewer.viewport.resize(newSize, false) and viewer.forceRedraw() as well
Anyway, I understand the three coordinate systems can be tricky to think through...hopefully that page is helpful. It's just kind of the way it goes when you're zooming :)
Grant Echols
@gechols
Jun 17 2015 22:53 UTC
Thanks a bunch - I really appreciate your help
Ian Gilman
@iangilman
Jun 17 2015 22:54 UTC
Happy to :)