Hello Khalid, If you could post a small code sample and a bit more information about what you need to achieve that would help me and others work out what's wrong.
Alternatively, you might find it useful to look at the StatusBar class in the swing module which uses a MapMouseListener to get the world location of the cursor for display. Michael On 16 June 2011 03:27, khalid Amiral <[email protected]> wrote: > I think that the problem is how to associate the event to the appropriate > panel, ie how to associate the Mouse Listener to the panel containing the > map? > >> Date: Wed, 15 Jun 2011 23:24:00 +1000 >> Subject: Re: [Geotools-gt2-users] Get point from click mouse >> From: [email protected] >> To: [email protected] >> CC: [email protected] >> >> OK, that's the problem. JMapFrame is just a JFrame really and it >> doesn't know anything about JMapPane's clever bits. Try this >> instead... >> >> JMapFrame map = ... >> map.getMapPane().addMouseListener( new MapMouseAdapter() { >> ... >> } ); >> >> Michael >> >> On 15 June 2011 23:17, khalid Amiral <[email protected]> wrote: >> > Effectively, I access the map pane via a JMapFrame : >> > --------Code----- >> > JMapFrame map= new JMapFrame(); >> > map.showMap(mapcontext); >> > map.addMouseListener(new MapMouseAdapter() { >> > >> > public void onMouseClicked(MapMouseEvent ev) { >> > // Get the world position of the mouse >> > DirectPosition2D pos = ev.getMapPosition(); >> > System.out.println(pos.x +pos.y); >> > } >> > }); >> > >> > --------------------------------------------------------------- >> > Thank you a lot. >> > >> >> Date: Wed, 15 Jun 2011 22:26:46 +1000 >> >> Subject: Re: [Geotools-gt2-users] Get point from click mouse >> >> From: [email protected] >> >> To: [email protected] >> >> CC: [email protected] >> >> >> >> Hello Khalid, >> >> >> >> That looks like you are calling Component.addMouseListener( >> >> MouseListener ) rather >> >> than JMapPane.addMouseListener( MapMouseListener ). >> >> >> >> Are you perhaps accessing the map pane via a JPanel or similar >> >> reference ? >> >> >> >> Michael >> >> >> >> On 15 June 2011 22:07, khalid Amiral <[email protected]> wrote: >> >> > thank you for the reply, but when i implements it gives me this >> >> > error: >> >> > "The >> >> > method addMouseListener (MouseListener) such Component does not apply >> >> > to >> >> > arguments (new MapMouseAdapter (){})"! >> >> > >> >> >> Date: Wed, 15 Jun 2011 13:44:00 +1000 >> >> >> From: [email protected] >> >> >> To: [email protected] >> >> >> Subject: Re: [Geotools-gt2-users] Get point from click mouse >> >> >> >> >> >> Yes, I was just typing the same thing when Jody's reply came through >> >> >> :) >> >> >> >> >> >> Alexander, your approach works fine but it's less work to let >> >> >> GeoTools >> >> >> do it for you like this... >> >> >> >> >> >> // Listen for mouse clicks in the map pane >> >> >> mapPane.addMouseListener(new MapMouseAdapter() { >> >> >> @Override >> >> >> public void onMouseClicked(MapMouseEvent ev) { >> >> >> // Get the world position of the mouse >> >> >> DirectPosition2D pos = ev.getMapPosition(); >> >> >> ... >> >> >> } >> >> >> }); >> >> >> >> >> >> You can use the MapMouseListener interface directly, rather than the >> >> >> adapter class, if you wish. Here are some useful javadoc pages... >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> http://docs.geotools.org/stable/javadocs/org/geotools/swing/event/MapMouseEvent.html >> >> >> >> >> >> >> >> >> >> >> >> http://docs.geotools.org/stable/javadocs/org/geotools/swing/event/MapMouseListener.html >> >> >> >> >> >> Michael >> >> >> >> >> >> >> >> >> On 15 June 2011 13:26, Jody Garnett <[email protected]> wrote: >> >> >> > I thought there was some kind of MapEvent that did the coordinate >> >> >> > transformation for you ... MapMouseEvent has some of that figured >> >> >> > out >> >> >> > already. >> >> >> > >> >> >> > -- >> >> >> > Jody Garnett >> >> >> > >> >> >> > On Wednesday, 15 June 2011 at 8:54 AM, Alexander Lanin wrote: >> >> >> > >> >> >> > Hi, >> >> >> > >> >> >> > here is what I’m using. I’m new to GeoTools so feel free to >> >> >> > correct >> >> >> > me >> >> >> > everyone! >> >> >> > I have this code in JMapPane: >> >> >> > >> >> >> > public void mouseClicked(MouseEvent e) { >> >> >> > // get the geographic position the mouse is pointing to >> >> >> > DirectPosition2D geoCoords = getScreenToWorldPos(e.getPoint()); >> >> >> > ... >> >> >> > } >> >> >> > >> >> >> > /** >> >> >> > * Convert Screen point to Map/World point >> >> >> > * @param point point on screen >> >> >> > * @return point in map >> >> >> > */ >> >> >> > public DirectPosition2D getScreenToWorldPos(Point point) { >> >> >> > assert ( point != null ); >> >> >> > >> >> >> > DirectPosition2D geoCoords = new DirectPosition2D(point.getX(), >> >> >> > point.getY()); >> >> >> > >> >> >> > AffineTransform t = getScreenToWorldTransform(); >> >> >> > assert ( t != null ); >> >> >> > >> >> >> > t.transform(geoCoords, geoCoords); >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > geoCoords.setCoordinateReferenceSystem(getMapContext().getCoordinateReferenceSys >> >> >> > tem()); >> >> >> > >> >> >> > assert ( geoCoords != null ); >> >> >> > return geoCoords; >> >> >> > } >> >> >> > >> >> >> > Regards, >> >> >> > Alex >> >> >> > >> >> >> > >> >> >> > >> >> >> > Von: khalid Amiral [mailto:[email protected]] >> >> >> > Gesendet: Mittwoch, 15. Juni 2011 00:25 >> >> >> > An: [email protected] >> >> >> > Betreff: [Geotools-gt2-users] Get point from click mouse >> >> >> > >> >> >> > Heloo, >> >> >> > please How can i get coordinates point after click mouse, because >> >> >> > i >> >> >> > want >> >> >> > to >> >> >> > use >> >> >> > it in WMS/GetFeatureInfo request (request.setQueryPoint(X,Y)). >> >> >> > if there is an example or tutorial will be better. >> >> >> > >> >> >> > Thank you in advance >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > ------------------------------------------------------------------------------ >> >> >> > EditLive Enterprise is the world's most technically advanced >> >> >> > content >> >> >> > authoring tool. Experience the power of Track Changes, Inline >> >> >> > Image >> >> >> > Editing and ensure content is compliant with Accessibility >> >> >> > Checking. >> >> >> > http://p.sf.net/sfu/ephox-dev2dev >> >> >> > _______________________________________________ >> >> >> > Geotools-gt2-users mailing list >> >> >> > [email protected] >> >> >> > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > >> >> >> > ------------------------------------------------------------------------------ >> >> >> > EditLive Enterprise is the world's most technically advanced >> >> >> > content >> >> >> > authoring tool. Experience the power of Track Changes, Inline >> >> >> > Image >> >> >> > Editing and ensure content is compliant with Accessibility >> >> >> > Checking. >> >> >> > http://p.sf.net/sfu/ephox-dev2dev >> >> >> > _______________________________________________ >> >> >> > Geotools-gt2-users mailing list >> >> >> > [email protected] >> >> >> > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> >> > >> >> >> > >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> >> >> EditLive Enterprise is the world's most technically advanced content >> >> >> authoring tool. Experience the power of Track Changes, Inline Image >> >> >> Editing and ensure content is compliant with Accessibility Checking. >> >> >> http://p.sf.net/sfu/ephox-dev2dev >> >> >> _______________________________________________ >> >> >> Geotools-gt2-users mailing list >> >> >> [email protected] >> >> >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> > >> > > ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
