[OpenLayers-Dev] Lat long from point

Abhi abhirama.bhat at gmail.com
Wed May 6 11:19:24 EDT 2009


I am trying to figure out how open layers converts a screen co ordinate into
latitudes and longitudes. To figure it out I downloaded version 1 of open
layers(for ease of reading due to less lines of code) and found the
following function:

 getLatLonFromPoint: function (point) {
        var center = this.getCenter();        //map center lat/lon
        var res  = this.getResolution();
        var size = this.getSize();

        var delta_x = point.x - (size.w / 2);
        var delta_y = point.y - (size.h / 2);

        return new OpenLayers.LatLon(
            center.lat - delta_y * res,
            center.lon + delta_x * res );
    }

In the latest version this has changed a bit but the logic remains the same.


Can someone please let me know how this works. I searched for ways to
convert a screen co ordinate to latitude and longitude and stumbled upon a
couple of them. But, none of them seem to match what open layers is doing.

-- 
Cheers,
Abhi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20090506/9d161a93/attachment.html


More information about the Dev mailing list