diff --git a/examples/ve.html b/examples/ve.html
index 52ea2a0d38..4d04215869 100644
--- a/examples/ve.html
+++ b/examples/ve.html
@@ -18,20 +18,23 @@
var lon = 5;
var lat = 40;
- var zoom = 5;
+ var zoom = 15;
var map, velayer, layer;
function init(){
- map = new OpenLayers.Map( $('map') );
+ map = new OpenLayers.Map( $('map') ,
+ {controls:[new OpenLayers.Control.MouseDefaults()]});
- velayer = new OpenLayers.Layer.VirtualEarth( "VE");
+ velayer = new OpenLayers.Layer.VirtualEarth( "VE",
+ { minZoomLevel: 4, maxZoomLevel: 6 });
map.addLayer(velayer);
markers = new OpenLayers.Layer.Markers("markers");
map.addLayer(markers);
- map.setCenter(new OpenLayers.LonLat(lon, lat), 2);
+ map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
map.addControl( new OpenLayers.Control.LayerSwitcher() );
+ map.addControl( new OpenLayers.Control.PanZoomBar() );
}
function add() {
diff --git a/lib/OpenLayers/Layer/VirtualEarth.js b/lib/OpenLayers/Layer/VirtualEarth.js
index a021b36d14..360cdcff82 100644
--- a/lib/OpenLayers/Layer/VirtualEarth.js
+++ b/lib/OpenLayers/Layer/VirtualEarth.js
@@ -15,7 +15,10 @@ OpenLayers.Layer.VirtualEarth.prototype =
vemap: null,
/** @type int */
- numZoomLevels: 17,
+ minZoomLevel: 1,
+
+ /** @type int */
+ maxZoomLevel: 17,
/**
* @constructor
@@ -24,6 +27,8 @@ OpenLayers.Layer.VirtualEarth.prototype =
*/
initialize:function(name) {
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
+
+ this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1;
},
/**
@@ -203,21 +208,26 @@ OpenLayers.Layer.VirtualEarth.prototype =
*/
getZoomForExtent: function (bounds) {
- var maxRes = this.map.getMaxResolution();
- var viewSize = this.map.getSize();
-
- var width = bounds.getWidth();
- var height = bounds.getHeight();
-
- var degPerPixel = (width > height) ? width / viewSize.w
- : height / viewSize.h;
-
- var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
-
- //make sure zoom is within bounds
- zoom = Math.min( Math.max(zoom, 0),
- this.numZoomLevels-1);
-
+ var zoom = null;
+ if (this.vemap != null) {
+ var maxRes = this.map.getMaxResolution();
+ var viewSize = this.map.getSize();
+
+ var width = bounds.getWidth();
+ var height = bounds.getHeight();
+
+ var degPerPixel = (width > height) ? width / viewSize.w
+ : height / viewSize.h;
+
+ var veZoom = Math.floor( (Math.log(maxRes/degPerPixel)) /
+ Math.log(2) );
+
+ //make sure zoom is within bounds
+ var veZoom = Math.min(Math.max(veZoom, this.minZoomLevel),
+ this.maxZoomLevel);
+
+ zoom = this.getOLZoomFromVEZoom(veZoom);
+ }
return zoom;
},
@@ -245,7 +255,7 @@ OpenLayers.Layer.VirtualEarth.prototype =
getOLZoomFromVEZoom: function(veZoom) {
var zoom = null;
if (veZoom != null) {
- zoom = veZoom;
+ zoom = veZoom - this.minZoomLevel;
}
return zoom;
},
@@ -260,7 +270,7 @@ OpenLayers.Layer.VirtualEarth.prototype =
getVEZoomFromOLZoom: function(olZoom) {
var zoom = null;
if (olZoom != null) {
- zoom = olZoom;
+ zoom = olZoom + this.minZoomLevel;
}
return zoom;
},