Thursday, 7 May 2015

Any example for Google like the Bing OpenLayers examples?


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.



Answer



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;

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...