These are chat archives for openseadragon/openseadragon

22nd
Jun 2015
Grant Echols
@gechols
Jun 22 2015 15:34
So I'm back to working on the code to preserve the image zoom level during container resize and I can't seem to make sense of the bounds that need to be set in viewport.fitBounds and the point conversion methods provided for translation between image, window and viewport coordinates. The width and height of the bounds (which is what I think I'm supposed to adjust) aren't points. Sorry - I'm pretty confused...
Ian Gilman
@iangilman
Jun 22 2015 16:59
viewport.getBounds and viewport.fitBounds are in viewport coordinates. The width and height you get from the DOM for the element size are in window/web coordinates.
pointFromPixel will get a location converted from web to viewport. deltaPointsFromPixels will get a size converted from web to viewport.
@ksclarke When you create the viewer, you should stick it in a variable (i.e. var viewer = OpenSeadragon(options)). Then you can later call viewer.viewport.goHome() on it.
Grant Echols
@gechols
Jun 22 2015 17:13
I understand the various 'points' displayed on the coordinates page, but I'm struggling to make sense of the rectangles I need to work with because the width and height don't make sense. For instance, getBounds() returns: {"x":-0.16700821997509407,"y":0.117106655140852,"width":1.300265176896492,"height":0.522676611470748}. When I've stretched the window vertically I get a new container size that is 2 or 3 pixels taller.
I believe I need to adjust the bounds.height by something, but its not the 2 or 3 I'm getting from the change in pixel heights. That's where things are breaking down for me
Ian Gilman
@iangilman
Jun 22 2015 17:15
Viewport coordinates generally go from 0 to 1, but they can go wider if there is whitespace outside the image. At any rate, that's the scale you need to be thinking in. Viewport coordinates are not pixels.
Grant Echols
@gechols
Jun 22 2015 17:25
So is there a way to convert from pixels to viewport coordinates? Isn't that what I'm looking for?
Ian Gilman
@iangilman
Jun 22 2015 17:28
Do you mean the pixels of the web/window coordinate system? Or the pixels of the image coordinate system? At any rate, yes you want to convert from the pixels of the web/window coordinate system (and ignore the image coordinate system) because that's how you know how big your DOM element is. That's what pointFromPixel and deltaPointsFromPixels do.
Grant Echols
@gechols
Jun 22 2015 17:38
I apologize for being obtuse but I'm feeling more lost now in looking at pointFromPixel and deltaPointsFromPixels because they need a Point for reference and I don't know what point we would be talking about. Let me try this - here's a snippet of code - with a missing portion for where I think I'm getting confused:var bounds = viewer.viewport.getBounds();
    var deltaX = (containerSize.x - prevContainerSize.x);
    var deltaY = (containerSize.y - prevContainerSize.y);

    bounds.width += ????
    bounds.height += ????
    viewer.viewport.fitBounds(bounds, true);
So the deltaX and deltaY are the pixel differences from the web/window coordinate system I believe
Ian Gilman
@iangilman
Jun 22 2015 17:39
Yeah, the terminology may be a bit confusing. The "point" in pointFromPixel means viewport coordinates, but the Point object type just means any set of x and y.
Just a sec...
@gechols Should be something like
var deltaX = (containerSize.x - prevContainerSize.x);
var deltaY = (containerSize.y - prevContainerSize.y);
var viewportDiff = viewer.viewport.deltaPointsFromPixels(new OpenSeadragon.Point(deltaX, deltaY), true);
viewer.viewport.resize(new OpenSeadragon.Point(containerSize.x, containerSize.y), false);
var bounds = viewer.viewport.getBounds(true);
bounds.width += viewportDiff.x;
bounds.height += viewportDiff.y;
viewer.viewport.fitBounds(bounds, true);
viewer.forceRedraw();
Grant Echols
@gechols
Jun 22 2015 17:44
I'll give it a try and let you know. Thanks!
Ian Gilman
@iangilman
Jun 22 2015 17:44
Sure...sorry it's so confusing!
Grant Echols
@gechols
Jun 22 2015 17:45
NP - I just appreciate how ready to help you have been.
Ian Gilman
@iangilman
Jun 22 2015 17:46
:)
Grant Echols
@gechols
Jun 22 2015 18:17
@iangilman - Great news! With a few tweaks the code you helped me with is looking very promising - I'll update you with a PR later if I can get it working all the way.
Ian Gilman
@iangilman
Jun 22 2015 21:11
@gechols Awesome! I should be able to take a look at it tomorrow.