[OpenLayers-Users] Retrieve lat/lon coordinates
Andreas Hocevar
ahocevar at opengeo.org
Fri Dec 16 07:06:34 EST 2011
Hi,
OpenLayers expects all coordinates to be in the projection of the base
layer - EPSG:31258 in your case. If you want lat/lon coordinates, you
need to transform them, and for this you'll need the additional
proj4js library (http://proj4js.org/). The preferred way is to
download it along with the projection definitions you need and install
it on your site, but for testing you can add the following script
resources to your html page:
<script type="text/javascript"
src="http://trac.osgeo.org/proj4js/export/2080/trunk/lib/proj4js-compressed.js"></script>
<script type="text/javascript"
src="http://spatialreference.org/ref/epsg/31258/proj4js/"></script>
Then, to set your map center, do
map.setCenter(new OpenLayers.LonLat(13,48).transform(new
OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
To get mouse coordinates in lat/lon, configure your map with
displayProjection: new OpenLayers.Projection("EPSG:4326");
Andreas.
On Fri, Dec 16, 2011 at 12:32 PM, canduc17 <candini at meeo.it> wrote:
> Hi everyone.
> I have an OSM style map produced with http://mapnik.org/ mapnik , having
> projection http://spatialreference.org/ref/epsg/31258/ EPSG:31258 .
> To perform tile production I have specified to mapnik my projection, so they
> should have been produced correctly.
> My code is the following:
>
> The map is correctly rendered and the tiling system works.
>
> But I have two questions:
> 1 - How can I retrieve lat/lon coordinates passing with the cursor on the
> map? Like in http://openlayers.org/dev/examples/mouse-position.html this
> example , but I would like to obtain lat/lon and not x/y coordinates...
> 2 - The setCenter function doesn't work: map is focused in the Atlantic
> Ocean and not ove Salzburg as expected.
>
> Thanks in advance.
>
> --
> View this message in context: http://osgeo-org.1803224.n2.nabble.com/Retrieve-lat-lon-coordinates-tp7100457p7100457.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list