[GIS] OpenLayers restrictedExtent 3857 OSM

openlayers-2openstreetmap

I'm trying to restrict Extent to a map in 3857. This seems like it should be very simple, but required me to write a BBOX function for my very vanilla OSM basemap example. I've provided the code here: http://jsfiddle.net/4Jv4m/

Can someone tell me why there is still whitespace on the top/bottom of the map when you drag the map? Just try dragging it up and down and you will see some whitespace.

I realize that transforming -180, -90 goes to -Infinity, but still I've no way to limit the extent to the world without possibly 'hardcoding' the 3857 compliant XY coordinates. This is not an option as most GetCapability documents work in 4326 lat/lon, so I'd like my transformation function to correctly handle this scenario.

Best Answer

I'm not an expert on OpenLayers with OSM, but looking at my own code (a hiking slippymap) for setting map extents, I think you need to transform the coordinates:

map.restrictedExtent = new OpenLayers.Bounds(15.059825, 46.26, 15.852675, 46.7367894127061)
    .transform(proj4326, proj900913);

Also, Mercator projection usually extends to +/-85 (cca.) degree parallels.

I suggest you take a look at the whole HTML code of my sample, there's some additional code for setting the displayProjection and projection for the map (which I'm not 100% sure is necessary, but works in my case).

Related Question