Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 0 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.RESOLUTIONS = gmap.RESOLUTIONS.slice( gmap.MIN_ZOOM_LEVEL, gmap.MAX_ZOOM_LEVEL );

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

map.zoomToExtent( vegasAirport.clone() );

window.olMap = map;
share|improve this answer
add comment

Your Answer

 
discard

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.