Sunday 16 October 2016

coordinate system - getExtent() in OpenLayers returns strange values


I'm trying to get the bounding box of the map area displayed by OpenLayers.



I tried to use map.getExtent() because it should be exactly what I need, but the returned values are "strange":


For example, if I center the map around Grenoble (France, 45.19 5.71) with zoom level 14, the getExtent returns : 634409.225396,5647894.800465,643008.391077,5652672.114732 I guess I'm doing something wrong, but I can't figure out what. The getExtent() is supposed to return a bound object with Lat/Lon values...


The map is created with :


var map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
});

I'm using OSM as my base layer.



Answer




Looks like the coordinates are coming back in the map's projection (epsg 900913 AKA web mercator). You should be able to call transform on your bounds object to convert it to lat/long. Try something like this (untested):


map.getExtent().transform(map.projection, map.displayProjection)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...