views:

8

answers:

1

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.

A: 

I think I've figured it out. For whatever reason, the zoom was never changing, but the center apparently WAS moving (it was just so zoomed out I couldn't tell). Add to the fact that I needed to transform the center to use the google projection, and it seems to work just fine.

What I ended up doing was:

var lonlat = new OpenLayers.LonLat(20,37).transform(new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913"));
map.setCenter(lonlat);
map.zoomTo(4);
Jenny