With your help I was able get a shapefile from the CAD file of the previous question.

Now the next step is the display the shapefile in OpenLayers... I wrote the script but the map being displayed in the browser is way too small... I need help setting the default zoom level...

Can someone point me to an "simple" example that explains how to set the default zoom level?

The ones I've found a way to complicated...

5 Answers 5


The second argument to map.setCenter is a zoom.

  var map = new OpenLayers.Map("mapdiv");
  // add layers here
  map.setCenter(new OpenLayers.LonLat(yourlon, yourlat), 5);

If you want something more complex than that, you're probably going to need to share more details about what your map and setup currently look like. (Projection, base layer, etc.)

  • Thanks for the replies!!! But still no luck.... Here's the link to my "map".... Hopefully someone take a look at the source page and let me know what I'm doing wrong... [link] (tobagoborn.com/gis/science/floor13.html) Thanks
    – ChrisJ
    Feb 25, 2011 at 5:58
  • Thanks everyone for taking the time to reply... After reading everything I started from scratch. The key was figuring out the center lat/lon. I did this by running get.center() on the command prompt on firebug... Chris
    – ChrisJ
    Feb 28, 2011 at 13:19

Exemples are complexes because the way it works is not that simple

Since Zoom level and resolution are linked together, it could be a good start for you to read about it on the wiki page : http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels, then choose the best way to process for the project you're working on.


Another way to set extent like you want

-Zoom to the extent you desired

-Get your current bbox

currentBbox = map.getExtent().left + ","+ map.getExtent().bottom + "," + map.getExtent().right + "," + map.getExtent().top;

-Copy result you got from console below


-Reuse the result you got by pasting it in map.zoomToExtent(new OpenLayers.Bounds(stringYouCopy));

So in your case, do in firebug console

map.zoomToExtent(new OpenLayers.Bounds(-1.395751953125, -2.051635742188, 11.787841796875, 10.582641601562));

If it's ok, you can add the code to your Openlayers application

Reusing "Christopher Schmidt" advice with map.setCenter, to get the right informations

-Zoom to the place you want

-To get lon


-To get lat


-To get zoom


It's up to you to complete (easy now)


Another option would be to zoom to the extent of your map using map.zoomToExtent(layer.getExtent())


Pretty easy, bigger the value, bigger the zoom:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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