allow google layer to be configured with min/max zoomLevels. update example.

git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1308 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-08-19 05:23:45 +00:00
parent 1e8c8e8404
commit 2ec05163ed
2 changed files with 20 additions and 6 deletions

View File

@@ -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() );
}

View File

@@ -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;
},