Thank you for the code !
But I still have got a problem. The coordinates don't seem to be exact
(there's an error in both lat and long).
This is my code
private void getNewCoord(MouseEvent e)
{
final AffineTransform transform = new AffineTransform (){
/*
screen is of type Rectangle2D and gets frame.getBounds()
envelope is of type Envelope and is initialized in this way
datastore = new ShapefileDataStore(shape);
String name = datastore.getTypeNames()[0];
FeatureSource source = datastore.getFeatureSource(name);
FeatureCollection collection = source.getFeatures();
envelope = collection.getBounds();
map is of type JMapPane
*/
{final double scaleFactor = (Math.min((screen.getWidth ()/
envelope.getWidth ()), (screen.getHeight
()/envelope.getHeight ())) * map.getZoomFactor ());
System.out.println(scaleFactor);
// Translate to the center of the JPanel.
translate (map.getBounds().getCenterX(),
map.getBounds().getCenterY());
// Scale with negative y factor to correct the orientation.
scale (scaleFactor, -scaleFactor);
// Translate to the center of the feature collection.
translate(-(envelope.centre().x), -(envelope.centre().y));}
};
final Point2D pnt = new Point2D.Double(e.getX(), e.getY());
try
{
transform.inverseTransform(pnt,pnt);
} catch (Exception ex) {ex.printStackTrace();}
System.out.println("X : " + pnt.getX() + " , Y : " + pnt.getY());
}
Did I give the right meaning at you "box" and "centre" ?
Thank you (and sorry for the long post)
Andrea
>From: "Mauricio Mantilla" <[EMAIL PROTECTED]>
>To: "pennyw 81" <[EMAIL PROTECTED]>
>CC: [email protected]
>Subject: Re: [Geotools-gt2-users] Coordinates from MouseEvent
>Date: Fri, 1 Sep 2006 15:54:14 -0500
>
>I think geomouseevent and getmapcoordinate don't work anymore. I did
>something like this.
>
>public void mouseClicked(MouseEvent e) {
> if (e.getButton()==MouseEvent.BUTTON1) {
> final Point2D pnt = new Point2D.Double(e.getX(), e.getY());
> if (info.booleanValue()==true){
> try {
> transform.inverseTransform(pnt,pnt);
> } catch (NoninvertibleTransformException ex) {
> ex.printStackTrace();
> }
> .......
>
>transform is an AffineTransform that has to be defined in order to use the
>streaming renderer (I guess), like this:
>
>final AffineTransform transform = new AffineTransform (){
> {final double scaleFactor = (Math.min((getWidth ()/
>box.getWidth ()), (getHeight ()/box.getHeight ())) * getZoomFactor ());
> System.out.println(scaleFactor);
> // Translate to the center of the JPanel.
> translate (getBounds().getWidth()/2,
>getBounds().getHeight()/2);
> // Scale with negative y factor to correct the
>orientation.
> scale (scaleFactor, -scaleFactor);
> // Translate to the center of the feature collection.
> translate(-centro.getX(), -centro.getY());}
> };
>
>I hope that helps,
>
>Mauricio Mantilla
_________________________________________________________________
Vuoi vedere la reazione dei tuoi amici?
http://imagine-msn.com/messenger/launch80/?locale=it-it
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users