How to set default view in OpenLayers, WITHOUT restricting bounds?

Posted by Jenny on Stack Overflow See other posts from Stack Overflow or by Jenny
Published on 2010-08-24T13:33:26Z Indexed on 2010/12/31 19:54 UTC
Read the original article Hit count: 196

Filed under:
|
|

Based on samples, I can see that you can set a default view in OpenLayers by saying something along the lines of:

    var bounds = new OpenLayers.Bounds(-125, 25, -65, 50);
var map = new OpenLayers.Map('map', {restrictedExtent: bounds  });

However, this also (as the name implies), restricts me to be able to ONLY navigate within these bounds. I can zoom out and see things outside of these bounds, but I can't then zoom back onto them, or scroll to them.

I've tried not having any restrictedExtent (or making it the entire map), but then I can't get it to focus on the area I want. I tried using:

     map.setCenter(new OpenLayers.LonLat(0,0), 3);
     console.log(map.getCenter());

To set the zoom and the center...but it doesn't seem to do ANYTHING, other than set the variable "center" which I can then read from map.getCenter() (if I don't set it, it's null, if I do set it, I can see it...but the map itself stays fully extended and it's center doesn't seem to change at all...)

The Map layer I am using is:

OpenLayers.Layer.OSM.Mapnik

with displayOutsideMaxExtent set to true... I'm really at a loss here.

My goal is to have a default region of the world zoomed in to and in view (such as the United States), with the option of viewers being able to go outside the default to view things.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about openlayers