I would like to restrict zoom levels in OpenLayers 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 OpenLayers.

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

  • Got it working but it's an incredible hack: fiddle/1
    – ca0v
    Feb 23, 2012 at 21:42
  • Please post the working code as the answer, so future readers can find the answer Feb 24, 2012 at 18:45

1 Answer 1


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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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