Could somebody please help me or direct me in the right direction for
converting screenXY pixels to world Lat longs.
I added a shp file to a mapcontext with a DefaultGeographicCRS.WGS84
coordinate reference system.
I have a mouse listener that listen for mouse movement and i can get the x y
on the panel.
Now to convert it to the correct lat long?
View this message in context: http://www.nabble.com/Convert-ScreenXY-to-World-Lat-Long-tf4691127.html#a13407611
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
From: Ian Turton <ijturton@gm...> - 2007-10-25 15:13:42
On 10/25/07, theunsgis <Theuns@...> wrote:
> HI all
> Could somebody please help me or direct me in the right direction for
> converting screenXY pixels to world Lat longs.
> I added a shp file to a mapcontext with a DefaultGeographicCRS.WGS84
> coordinate reference system.
> I have a mouse listener that listen for mouse movement and i can get the x y
> on the panel.
> Now to convert it to the correct lat long?
The way that JMapPane does it is this:
Rectangle bounds = this.getBounds();
double x = (double) (e.getX());
double y = (double) (e.getY());
double width = mapArea.getWidth();
double height = mapArea.getHeight();
double width2 = mapArea.getWidth() / 2.0;
double height2 = mapArea.getHeight() / 2.0;
double mapX = ((x * width) / (double) bounds.width) + mapArea.getMinX();
double mapY = (((bounds.getHeight() - y) * height) / (double)
where mapArea is the envelope that represents the bounds of the viewing area.
See JMapPane.mouseClicked(MouseEvent e) for full code examples.