I want to display the bounds of my current extent on the page. I am not too great with javascript. I know it must be related to this: map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom))

Can't seem to get it. Any help would be great! Thanks.


I think you are looking for map.getExtent(): http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.getExtent

This will give you a bounds object in the coordinate-system of your map. The Bounds object (http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/BaseTypes/Bounds-js.html) has several methods for getting the bound-coordinates, the simplest beeing toString.

Hope this helps!

  • You will likely want to transform those bounds to the epsg:4326 projection to get the "normal" lat/lon coordinates we're all used to. Especially if you're just starting out I'm assuming you're using a mercator (google/bing/OSM) base map. Just FYI. These are all assumptions. – Vadim Apr 12 '12 at 16:45
  • Good point, forgot to mention that. I am so used to working with WMSes in various UTM zones that I forgot this. – atlefren Apr 12 '12 at 18:28

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.