Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

Now the next step is the display the shape file 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....

Thanks
Chris

share|improve this question

4 Answers 4

up vote 9 down vote accepted

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.)

share|improve this answer
    
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 '11 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 '11 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.

share|improve this answer

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

console.log(currentBbox)

-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

map.center.lon

-To get lat

map.center.lat

-To get zoom

map.zoom

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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