Zoom around a Point

Hi, I’m trying to zoom an image around the current Mouse point (sort of like google craps…err, maps). So when you have the mouse in the bottom right corner and zoom in (mouse wheel scroll up) it zooms around that point, but then you can move the mouse to the top left corner and continue to zoom in and it will zoom around the new point in the top left corner. I have this working (in the attached code … I guess you have to be logged in to see the code and image) but the problem I have is with zooming back out. Unlike Google maps I don’t want to zoom out past the boundary of the map - I want the map to remain in the view. Right now, if you zoom in the bottom right corner and then move the mouse to the top left corner and start to zoom back out, eventually you will see the corner of the map but in reality I don’t want to be able to zoom out past the map extents (…the code eventually snaps back but that’s not a solution I want).

sorry for the poor code, but I tried a bunch of things like retrieving the rectangle that represents the current zoomed in portion of the map and using that to determine when to force the zoom to scale of 1.0, etc, etc…there must be a more elegant way to do this. I don’t want to use scroll bars and I don’t want to zoom out and see the map edges.

btw, I just found another example of what I’m trying to do…unfortunately this code doesn’t limit the zoom out to remain within the bounds of the display/canvas but it does the same zoom in and out that I have (ie around a point).

It is a very cool example and completely functional: http://today.java.net/pub/a/today/2007/03/27/navigable-image-panel.html

so, no one zooms in on their scenes?

wow…this message board is quite, is there any better java2d boards where I can go ask questions? I mean more active boards?

This is the output from your program when the lower right corner of the map is visible with a white border.

Screen 2D Point: 163 90
Screen width: 824 height: 506
Scale Factor: 0.9
Scaled Point: 146.70000000000002 height: 81.0
Scaled width: 741.6 height: 455.40000000000003
at: 2.6861527427269354 2.6861527427269354
CLICK> X: 163.0 Y: 90.0
1: 567 317 308 189
clickX/getWidth()*rec.width = 60.92718446601942
clickY/getHeight()*rec.height = 33.616600790513836

You output the dimensions of your rec, with the width being 308, and the height being 189.
Both of those are less than your screen width and screen height.
I think that you need to detect the case where your rec.width is less than screen width and then move your map by the difference to force it to an edge, same would apply for rec.height being less than screen height.
You definitely want to move, and not force the scale to change as this condition could happen at a high zoom.

Thanks for the response, Wildern. I believe you are right that I need to detect when my width is less and I initially tried doing that and sort of do now and I then snap the map to the bounds of the screen/panel but I’m doing this poorly. I’ve completely confused myself on this zooming and I’m having a hard time even explaining my problems so I’m glad you were able to see my problem and could contribute. I need to review the link I provided in a previous post and I need to map this out on paper once again and then I can find a solution and post here or provide a better explanation for all of you to shoot holes through.

Initially I thought about doing a google maps kind of zoom, but they don’t try to force the map within the panel bounds because as you zoom out you eventually zoom outside of the map and they also keep wrapping the image along the X axis which I don’t want to do.