getting lat/lng in degrees from OpenLayers (olwidget)

261 views
Skip to first unread message

omat

unread,
Nov 17, 2009, 4:42:56 AM11/17/09
to geodjango
Hi,

I have an OpenLayers map (olwidget InfoMap) with the default
parameters for projection:

units: 'm'
projection: "EPSG:900913"
displayProjection: "EPSG:4326"

Coordinates I get from the map are all in meters. Setting the units:
'd' only changes the unit of the overlays not the base layers, thus I
still get the coordinates in meters.

I should either get the coordinates from the client in degrees or
convert them into degrees on the server. I tried many combinations of
projection transformations both on the client by OpenLayers api and
with python/geodjango on the server with no luck.

Any help is much appreciated.

Thanks.

-- omat

Charlie DeTar

unread,
Nov 17, 2009, 7:21:04 AM11/17/09
to geod...@googlegroups.com
OpenStreetMaps, Google Maps, and several others use 900913 projection
internally. This is why in OpenLayers one must set "projection" to
900913. The "displayProjection" field (as described in the OpenLayers
docs[1]) is only used for displaying data back to users.

olwidget assumes that incoming vector data will be projected using
"displayProjection", and translates that internally to the projection in
"projection" (probably 900913) for display on the map.

You can translate coordinates gotten from the map back into
displayProjection using the OpenLayers API [2]:

point.transform(fromProj, toProj);

As an example, you might have something like this:

var point = map.getLonLatFromPixel(new OpenLayers.Pixel(10, 10));
point.transform(map.projection, map.displayProjection);

-charlie

[1]
http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.projection
[2]
http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/BaseTypes/LonLat-js.html#OpenLayers.LonLat.transform
> --
>
> You received this message because you are subscribed to the Google Groups "geodjango" group.
> To post to this group, send email to geod...@googlegroups.com.
> To unsubscribe from this group, send email to geodjango+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/geodjango?hl=.
>
>

omat

unread,
Nov 17, 2009, 10:40:49 AM11/17/09
to geodjango
I cannot thank you enough, Charlie. Thank you very much for the
clarification and the example.


--
omat


On Nov 17, 2:21 pm, Charlie DeTar <cha...@gmail.com> wrote:
> OpenStreetMaps, Google Maps, and several others use 900913 projection
> internally.  This is why in OpenLayers one must set "projection" to
> 900913.  The "displayProjection" field (as described in the OpenLayers
> docs[1]) is only used for displaying data back to users.
>
> olwidget assumes that incoming vector data will be projected using
> "displayProjection", and translates that internally to the projection in
> "projection" (probably 900913) for display on the map.
>
> You can translate coordinates gotten from the map back into
> displayProjection using the OpenLayers API [2]:
>
> point.transform(fromProj, toProj);
>
> As an example, you might have something like this:
>
> var point = map.getLonLatFromPixel(new OpenLayers.Pixel(10, 10));
> point.transform(map.projection, map.displayProjection);
>
> -charlie
>
> [1]http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/O...
> [2]http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/O...
Reply all
Reply to author
Forward
0 new messages