diff --git a/examples/google.html b/examples/google.html index 611cc0b51b..5b8495b9ab 100644 --- a/examples/google.html +++ b/examples/google.html @@ -23,20 +23,23 @@ var map, layer; function init(){ - map = new OpenLayers.Map( $('map') ); + map = new OpenLayers.Map( $('map') , + { controls: [new OpenLayers.Control.MouseDefaults()] }); - var normal = new OpenLayers.Layer.Google( "Google" ); + var normal = new OpenLayers.Layer.Google( "Google", // ); + { minZoomLevel: 3, maxZoomLevel: 8 }); var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: G_SATELLITE_MAP }); var hybrid = new OpenLayers.Layer.Google( "Google Hybrid" , {type: G_HYBRID_MAP }); - map.addLayers([normal, satellite, hybrid]); + map.addLayers([satellite, normal, hybrid]); markers = new OpenLayers.Layer.Markers("markers"); map.addLayer(markers); map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); map.addControl( new OpenLayers.Control.LayerSwitcher() ); + map.addControl( new OpenLayers.Control.PanZoomBar() ); } diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index 16f02ab176..27ac91a69b 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -49,7 +49,10 @@ OpenLayers.Layer.Google.prototype = // OPTIONS /** @type int */ - numZoomLevels: 16, + minZoomLevel: 0, + + /** @type int */ + maxZoomLevel: 16, /** @@ -62,6 +65,8 @@ OpenLayers.Layer.Google.prototype = if (this.maxExtent == null) { this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90); } + + this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1; }, /** @@ -263,6 +268,12 @@ OpenLayers.Layer.Google.prototype = if ((this.gmap != null) && (this.gmap.getCenter() != null)) { var gBounds = this.getGLatLngBoundsFromOLBounds(bounds); var gZoom = this.gmap.getBoundsZoomLevel(gBounds); + + //make sure zoom is within bounds + var gZoom = Math.min(Math.max(gZoom, this.minZoomLevel), + this.maxZoomLevel); + + zoom = this.getOLZoomFromGZoom(gZoom); } return zoom; @@ -291,7 +302,7 @@ OpenLayers.Layer.Google.prototype = getOLZoomFromGZoom: function(gZoom) { var zoom = null; if (gZoom != null) { - zoom = gZoom; + zoom = gZoom - this.minZoomLevel; } return zoom; }, @@ -306,7 +317,7 @@ OpenLayers.Layer.Google.prototype = getGZoomFromOLZoom: function(olZoom) { var zoom = null; if (olZoom != null) { - zoom = olZoom; + zoom = olZoom + this.minZoomLevel; } return zoom; },