Maybe my extension of JMapPane helps you (see attachment).
It provides:
- Left mouse click -> zoom in with factor 2
- Right mouse click -> zoom out with factor 2
- Drag with left mouse button -> select a map area and zoom to it
- Drag with right mouse button -> move the map without zoom
- Mouse wheel -> zoom with factor 1.2 and hold the geo position under the mouse 
cursor

Unfortunately my source code comments are in german... sorry.

Kind regards...

Martin Schmitz



> -----Ursprüngliche Nachricht-----
> Von: "Govardhan" <[EMAIL PROTECTED]>
> Gesendet: 29.11.06 16:26:48
> An:  <[email protected]>
> Betreff: Re: [Geotools-gt2-users] NEED TO convert the image coordinate to Map 
> coordinate


> Dear Jody Garnett,
>   Yes this is working !!!! ... Thank you for all your help.
> 
> But I have some other issue, that is when I click on the image, I am able to 
> convert
> the screen to map coordinate and bring it to center of the map in the image 
> along with some zoomin ability.
> But when I now click on the second image, I am not getting the center of the 
> map properly,
> 
> I guess the reason for this is mapExtent is changing and also zoomfactor is 
> changing.
> for this reason I created the following two methods, to keep the latest 
> envelope (Map extent)
> in the session.
> 
> that is., one which runs when zoomin operation and other for zoomout 
> operation:
> 
>  public void setMapEnvelopeZoomin(Point2D worldcenterpoint){
>   Envelope env = this.mapContext.getAreaOfInterest();
>   double x = worldcenterpoint.getX();
>   double y = worldcenterpoint.getY();
>   double minx = 0.0;
>   double miny = 0.0;
>   double maxx = 0.0;
>   double maxy = 0.0;
>   double width = env.getWidth();
>   double height = env.getHeight();
> 
>    minx = (x) - ((width/2) * this.getZoomFactor());
>   maxx = (x) + ((width/2) * this.getZoomFactor());
>   miny = (y) - ((height/2) * this.getZoomFactor());
>   maxy = (y) + ((height/2) * this.getZoomFactor());
> 
>   System.out.println("zoomin minx=" + minx + ", miny=" + miny + ", maxx=" + 
> maxx + ", maxy=" + maxy);
>   if((minx != Double.NaN) || (miny != Double.NaN) || (maxx != Double.NaN) || 
> (maxy != Double.NaN)) {
>    Envelope enew = new Envelope(minx, maxx, miny, maxy);
>    this.mapContext.setAreaOfInterest(enew);
>   }
>  }
> 
>  public void setMapEnvelopeZoomout(Point2D worldcenterpoint){
>  Envelope env = this.mapContext.getAreaOfInterest();
>   double x = worldcenterpoint.getX();
>   double y = worldcenterpoint.getY();
>   double minx = 0.0;
>   double miny = 0.0;
>   double maxx = 0.0;
>   double maxy = 0.0;
>   double width = env.getWidth();
>   double height = env.getHeight();
> 
>    minx = (x) - ((width *2) / this.getZoomFactor());
>   maxx = (x) + ((width *2) / this.getZoomFactor());
>   miny = (y) - ((height * 2) / this.getZoomFactor());
>   maxy = (y) + ((height * 2) / this.getZoomFactor());
> 
>   System.out.println("zoomout minx=" + minx + ", miny=" + miny + ", maxx=" + 
> maxx + ", maxy=" + maxy);
>   if((minx != Double.NaN) || (miny != Double.NaN) || (maxx != Double.NaN) || 
> (maxy != Double.NaN)) {
>    Envelope enew = new Envelope(minx, maxx, miny, maxy);
>    this.mapContext.setAreaOfInterest(enew);
>   }
> 
> But this function, works good for first few zoomins and zoomouts, but 
> sometimes, it gets -values and then fails...
> 
> Do you know, what mistake I am making in these funtions.....
> If this is not the right method, then please let me know how to change the 
> mapextent (Envelope) when the
> center and zoomfactor of the map changes..
> 
> Once again thank you for all
> 
> Regards
>   Govardhan
> 
> 
> 
> ----- Original Message ----- 
> From: "Jody Garnett" <[EMAIL PROTECTED]>
> To: "Govardhan" <[EMAIL PROTECTED]>; 
> <[email protected]>
> Sent: Tuesday, November 28, 2006 11:38 PM
> Subject: Re: [Geotools-gt2-users] NEED TO convert the image coordinate to 
> Map coordinate
> 
> 
> > HI Mr Govardhan:
> >
> > I understand that sample code is *needed* by a library - and you are
> > correct in asking on the user list: in talking to Jesse he told me of a
> > Render Utilities class that helps with transforms ....
> >
> > http://javadoc.geotools.fr/2.2/org/geotools/renderer/lite/RendererUtilities.html
> >
> > I have not looked at this class before either -- their is a
> > worldToScreenTransform( mapExtent, paintArea) method that returns a
> > Transform.
> >
> > AffineTransform world2screen = RendererUtilities.worldToScreenTransform(
> > mapExtent, imageArea );
> >
> > From there you can call transform.createInverse() to get a transform
> > going from screen to world ...
> >
> > AffineTransform screen2world = world2screen.createInverse();
> >
> > And then finally we need to take your points x and y and transform them:
> >
> > Point2D screen = new Point2D( x, y );
> > Point2D world = screen2world.transform( ptSrc, null );
> >
> > This world point should be something useful in your data set. The
> > mapExtent you will need to figure out from the code you used to generate
> > the image, and the imageArea is the size of your image I expect.
> >
> > Give that a go - and get back to me; if it still does not work I will
> > try and spend my coffee break on it.
> > Jody
> >> Dear  Jody Garnett,
> >> Thank you for the info, but I am very new to this kind of operation, I am 
> >> having tough time to
> >> do this, inverse, can I get some sample code which can give me some push 
> >> to do the same.
> >>
> >>
> >> Best Regards
> >>  Govardhan
> >>
> >>
> >> ----- Original Message ----- From: "Jody Garnett" 
> >> <[EMAIL PROTECTED]>
> >> To: "Govardhan" <[EMAIL PROTECTED]>
> >> Cc: <[email protected]>
> >> Sent: Sunday, November 26, 2006 7:10 AM
> >> Subject: Re: [Geotools-gt2-users] NEED TO convert the image coordinate to 
> >> Map coordinate
> >>
> >>
> >>> Trying to think - you got an affine transform.
> >>>
> >>> So you need to get the transform.inverse() and then use that to 
> >>> "back-project" the screen coordinate - what pops out should be in the 
> >>> Map coordinate system.
> >>>
> >>> Cheers,
> >>> Jody
> >>>> Hi All,
> >>>>     I am using streamingRenderer and created a jpg image of the Map, 
> >>>> now I am able to bring this map on the browser.
> >>>> When I click on the Map, I get x,y any where between 0-640 (w) and 
> >>>> 0-480 (h), but now I need to convert this clicked point
> >>>> to Map coordinate point, so that I can bring that clicked point to the 
> >>>> center of the map in my next image generation.
> >>>>  PLEASE Help me in doing this, I am having really very hard time to 
> >>>> achieve this.
> >>>>  I am able to zoomin and zoomout by changing the zoomfactor in 
> >>>> AffineTransform , but Not able to bring the center of the map
> >>>> where user is click on the image.
> >>>>  Best Regards
> >>>>   Govardhan
> >>>>   Congruence Software Solutions Pvt Ltd
> >>>>   KusumPrakash Arcade, site no:9
> >>>>   1st Main, SanjayNagar
> >>>>   Bangalore-94
> >>>>   (O) 001-91-41674163
> >>>>   (V) 678-248-2437
> >>>>   (M) 001-91-9980036996
> >>>>   http://www.congruence.co.in
> >>>> ------------------------------------------------------------------------
> >>>>
_______________________________________________________________________
Viren-Scan für Ihren PC! Jetzt für jeden. Sofort, online und kostenlos.
Gleich testen! http://www.pc-sicherheit.web.de/freescan/?mc=022222

Attachment: JMapPane.java
Description: Binary data

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to