How do I move around in the image to pre-determined areas?
Need some clarification on panning or zooming to different areas of the image. I know in terms of the original images the x,y coordinate that I want to appear in the top left position of the viewport. I want to add links to move to these positions(at the current zoom level whatever it is). I have been reading the documentation, but am getting confused as the pixel to point conversion seems to be more for converting the pixel location of the viewport not the pixel of the image itself. Is there a different function I can use?
3
people have this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
The company marked this question as answered.
The best answer from the company
-
Dustmoo, thanks for being a great help! We really appreciate it when our users help each other out. It's a great sign of the community this site is fostering.
Steve, the problem is simple: panTo() -- and all other viewport methods -- work with normalized coordinates rather than image pixels. Learn about what that means here: Seadragon Ajax coordinate system
So instead of passing in (0, 1900), you would pass in (0, 0.825). I got that by dividing 1900 by 2304, the width of the image.
The reason we work in normalized coordinates is because Seadragon is all about resolution-independence (the image can be arbitrarily big -- it'll still "just work" and still load instantly). By that logic, I'd recommend that you store the points of interest in normalized coordinates as well.
On that note, a best practice we recommend is to not rely on the top-left of the viewport, but instead on the center. That's why panTo() goes to the center. This is because another goal of Seadragon is to work on any screen of any size, and the aspect ratios of those screens vary greatly (e.g. laptop vs mobile phone).
Because of that, we provide a fitBounds() method that takes a rect, and just makes sure the user can see that full rect. So consider saving your "points of interest" instead as "regions of interest".
Just some suggestions. Good luck w/ your app, and feel free to share it when it's ready!
I’m happy that users are helping each other
The company and 1 other person say
this answers the question
-
Inappropriate?Well, I am not exactly sure why you are trying to move the point x,y to the top left of the viewport.
The basic usage to moving the image to a pre determined area is to use the panTo function.
Here is a quick example:
function toSpecificPoint(x,y){
var point = new Seadragon.Point(x,y);
viewer.viewport.panTo(point);
}
Then using a link like so to launch the function:
Go To Hotspot
This will put the x, y coordinates you pass to the function in the CENTER of the viewport. To put it in the upper left you would have to do some math based on the size of the viewport to determine the point. I will play with it and see if I can figure out the conversion.
In the mean time, if someone else has the math, post. :D
Edit: For some reason, even though I am using the code tag it is still rendering my link.. Hmmm..
I’m enjoying seadragon
-
Inappropriate?Alright, so with a little more digging, I came up with the solution.
I will try to explain the concept, but perhaps the code will explain better.
Since panTo sets the x and y coordinates that you pass to it to the center of the view port, we need to calculate what the center coordinates would be to put the overlay(or part of the image) we want in the upper left.
Lets start with the ifs:
If we pass the coordinates we know to the panTo function, it will put our overlay dead-center in the viewport.
If we drew a line from the top-left corner of the viewport to the bottom-right, the distances between the now centered overlay and each edge would be equal.
So, it stands to reason, that to move the overlay to the upper-left of the viewport, we need to move the lower-right point to the center.
We do this as follows:
function moveUpperLeft(x,y){
var viewSize = viewer.viewport.getBounds().getSize();
var viewX = (viewSize.x / 2);
var viewY = (viewSize.y / 2);
var point = new Seadragon.Point(x + viewX, y + viewY);
viewer.viewport.panTo(point);
}
The getBounds function gives you access to all of the Seadragon.Rect methods. Allowing you to get the viewport size in points relative to your current zoom.
The bottom-right point, relative to your overlay will always be 1/2 of your current viewport x and y points plus the x and y your current overlay position.
Okay, I am not sure if that makes any sense typed out like this. But the code above does work for what you were trying to do. x and y being the original overlay's point position.
Call with a similar link:
Move to Upper Left
Good luck.
I’m happy
-
Inappropriate?Thank you for the reply, I am not sure what I am doing wrong but when I try this method the x,y do not correlate with the x,y of the image itself. That is where I have struggled to get the correct point.
For example, I have a 2304x27147 pixel image. The first move I want to make is point 0,0. This one works great. Then I want to move to point 0,1900 this is where I get confused. Through trial and error I found that I need to move to Point(0,.9). This works great, but how do I calculate the .9? Is there a function?
Also, the code to move it to the top left is working great, thanks.
I’m Grateful for the help
-
Inappropriate?I see, your trying to find the correct x, y, for the point that you want to move.
The way the coordinate system works is a bit different from what you are used too. To move the viewfinder you need to feed it point data, and what you have is pixel data.
In pixels, your top-left pixel would be 0,0 and your top-right pixel would be 0,2304.
The points are complicated, (at least from what I can tell) the width of the image is always 1, and the height is based on the aspect ratio of the image, so if your image is half as tall as it is wide, it's height would be 0.5.
So all the points in the image are decimal values in between.
Example:
If my image is 400px x 200px.. The aspect ratio would be 1 to .5.
Therefor, to navigate the viewport to the center point of the image the x would need to be 0.5(half the width) and the y would be 0.25(half the height)
In the case of your image if the width is 2304 and the height is 27147 the ratio would be approximately 1 to 11.78(Your height is 11.78 times your width)
So your center point would be x=0.5(width is always ) and your y would be (approx) 5.89 (Again half of the height ratio)
So, hopefully this explains the math a little bit better, at least the way I understand it from what is explained here:
http://livelabs.com/seadragon-ajax/li...
and some tests of my own.
Now, an easier way to find the exact point you want to navigate too is to use the example on that page to user your mouse to find the exact point you want, then plug that into the above functions.
I used their example to give me the point where the mouse was, and then code that into the system, but the math above should help you calculate it dynamically if you have the pixel data.
There are some pixel to point conversion methods in the viewer, but I haven't tested them to see if they apply to the visible area or the loaded image.
Anyway, I hope this all makes sense, its a lot. :)
Dustin
I’m happy to help.
1 person says
this answers the question
-
Yep!
Btw, the conversion methods in the viewport take the current pan and zoom to account. So they let you answer "what point -- in normalized coordinates -- is at the center of the viewport currently?" and "where -- in screen pixels relative to the viewer -- can I find the center of the image currently?" -
Inappropriate?Dustmoo, thanks for being a great help! We really appreciate it when our users help each other out. It's a great sign of the community this site is fostering.
Steve, the problem is simple: panTo() -- and all other viewport methods -- work with normalized coordinates rather than image pixels. Learn about what that means here: Seadragon Ajax coordinate system
So instead of passing in (0, 1900), you would pass in (0, 0.825). I got that by dividing 1900 by 2304, the width of the image.
The reason we work in normalized coordinates is because Seadragon is all about resolution-independence (the image can be arbitrarily big -- it'll still "just work" and still load instantly). By that logic, I'd recommend that you store the points of interest in normalized coordinates as well.
On that note, a best practice we recommend is to not rely on the top-left of the viewport, but instead on the center. That's why panTo() goes to the center. This is because another goal of Seadragon is to work on any screen of any size, and the aspect ratios of those screens vary greatly (e.g. laptop vs mobile phone).
Because of that, we provide a fitBounds() method that takes a rect, and just makes sure the user can see that full rect. So consider saving your "points of interest" instead as "regions of interest".
Just some suggestions. Good luck w/ your app, and feel free to share it when it's ready!
I’m happy that users are helping each other
The company and 1 other person say
this answers the question
-
Inappropriate?Haha, there I go over-complicating it. :) (I think we were replying at the same time) Well Steve, this should give you some good info to go on.
Thanks for the reply Asseem, I am sure I am going to be picking your brain soon. Also, you might want to check the logic in my last reply, it might not be 100% sound. :D
I’m happy
-
Ha, didn't realize you replied at the same time. Good stuff! Makes sense to me. =) -
Inappropriate?Thank you all very much for the help. I read the page on the ajax coordinate system numerous times but didn't quite get it until this post. The different explanations here really cleared things up for me.
Thank you also for the suggestions about fitBounds, and while I will use this for the initial load, if they change the zoom level when they move around I want to keep their zoom level even if they can no longer see the whole rectangle that I would like. In this case, the top left of the image is the most important for them to see(there is a lot of text, and the top left is where the text starts).
I will be sure to share the app with you when I get it done. Mostly I am just working to see if it will do what I need it to. Also I am waiting on the license being finalized to know if I could use it anyway.
Thanks again for the help. Greatly appreciated.
I’m thankful
-
Glad to help. It's good feedback that the coordinate system page didn't make it clear. Anything specific that confused you, or that you think could be improved? Thanks! -
Glad to help too Steve, it helps to solve these problems because who knows when I am going to face the problem in my own app. -
Inappropriate?Yeah, ok. But let me ask you guys this, see if you guys can help. Does anybody know what the cutting voltage on a fi440 cc is on the wire?....No. ok ..thats my point ,see the original question is ok, and also the problem i have, but ! the solucion is all Greek to me, see you guys know all this, but we are completly blind to all this, , Please dont get me wrong, but the use of Photosyth is great for us that don't know much of PC. But is their anyway, you guys can put this so us morons can understand it in plain Inglishiiiii???..lol..lol..lol if not, Its all goooooood
I’m happy
-
Did you mean to reply on a different thread? This thread isn't about Photosynth. =)
Loading Profile...



EMPLOYEE