On 10/25/07, theunsgis <[EMAIL PROTECTED]> 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)
bounds.height)
                + mapArea.getMinY();

where mapArea is the envelope that represents the bounds of the viewing area.

See JMapPane.mouseClicked(MouseEvent e) for full code examples.

Ian

-- 

Ian Turton
http://www.geotools.org
http://pennspace.blogspot.com/

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to