8

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.

11

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)
  • +1 - the displayProjection is only used by some controls that display coordinates – geographika May 22 '11 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.