I have a custom map which I get from a mbtiles file with the bounds -13,25,49,60 and zoom from 4 to 10.The display div is dynamic, I mean that it depends on window size and the extent restriction works but still tries to load images around the map if the display div is bigger.
How can I limit the zooming out below 4?
Here is my code:
var map;
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var extent= new OpenLayers.Bounds(-13,25,49,60).transform( fromProjection, toProjection);
var mbTiles = new OpenLayers.Layer.TMS("base", "base.php", {
getURL: mbtilesURL,
type:'png',
transitionEffect: "resize",
isBaseLayer: true,
});
function mbtilesURL (bounds) {
var db = "img/map/base.mbtiles";
var res = this.map.getResolution();
var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
var z = this.map.getZoom();
return this.url+"?db="+db+"&z="+z+"&x="+x+"&y="+((1 << z) - y - 1);
}
map = new OpenLayers.Map('map', {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
layers: [mbTiles],
restrictedExtent : extent,
numZoomLevels: 11,
controls: [
new OpenLayers.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
}),
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.Attribution()
]
});
var position = new OpenLayers.LonLat(9.4679,37.6831).transform( fromProjection, toProjection);
var zoom = 4;
map.setCenter(position, zoom );
map.zoomToMaxExtent();
var switcherControl = new OpenLayers.Control.LayerSwitcher();
map.addControl(switcherControl);
switcherControl.maximizeControl();
I made it work! Had to add :
resolutions: [4891.969809,2445.984905,1222.992452,611.4962262,305.7481131,152.8740565]
and to add to z+4 to get to right zoom level. I used this site http://simonmercier.net/blog/?p=88 to get the right resolutions to use.
Best Answer
I made it work! Had to add :
and to add to z+4 to get to right zoom level.
I used this site http://simonmercier.net/blog/?p=88 to get the right resolutions to use.