Take the 2-minute tour ×

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.

share|improve this question

2 Answers 2

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

share|improve this answer
Where did you find the syntax for OSM? It's not documented (at all) on their site. The resolutions part is quite intriguing. –  Drew Mar 22 '11 at 18:13
Mostly searching through OSM Wiki, Google and some experimenting on my part. –  Igor Brejc Mar 24 '11 at 4:13
var fromProjection = new OpenLayers.Projection("EPSG:3857"); // transform from 3857?  
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
 //  (left, bottom, right, top)
map.restrictedExtent = new OpenLayers.Bounds(112.8, -43.7, 153.7, -9.4) .

some thing like that? untested! sorry I'm not familiar with 3857

share|improve this answer

Your Answer


