Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to restrict zoom levels in Open Layers for a Google Map. A bing example shows how to limit the extent of the bing tiles:

var road3 = new OpenLayers.Layer.Bing({
    name: "Road tiles with 3 zoom levels",
    type: "Road",
    key: apiKey,
    maxResolution: 76.43702827453613,
    numZoomLevels: 3

But I cannot find a google example which does this same thing in open layers.

Found OpenLayersAndGoogleMapOverlays but didn't work. I used it to build this fiddle which also doesn't work.

share|improve this question
Got it working but it's an incredible hack: fiddle/1 – ca0v Feb 23 '12 at 21:42
Please post the working code as the answer, so future readers can find the answer – pacofvf Feb 24 '12 at 18:45
up vote 1 down vote accepted

pacofvf: I cleaned up the solution and it can be accessed here. Most of the code is also pasted below:

var proj900913 = new OpenLayers.Projection( "EPSG:900913" ); //Spherical mercator used for google maps
var vegasAirport = new OpenLayers.Bounds ( -12821203.157925, 4310035.6046593, -12815126.414177, 4314851.1374406 );

var options = {
    maxExtent: vegasAirport.clone(),
    restrictedExtent : vegasAirport.clone (),
    projection : proj900913,
    displayProjection: proj900913,
    units : "m",
    controls: [new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.Navigation()]

var map = new OpenLayers.Map( 'map', options );
var gmap = new OpenLayers.Layer.Google("gmap",  { MIN_ZOOM_LEVEL: 15, MAX_ZOOM_LEVEL: 18 } );

gmap.maxExtent = vegasAirport.clone();
map.addLayers( [gmap] );
gmap.resolutions = gmap.RESOLUTIONS;

map.zoomToExtent( vegasAirport.clone() );

window.olMap = map;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.