diff --git a/lib/OpenLayers/Layer/VirtualEarth.js b/lib/OpenLayers/Layer/VirtualEarth.js index ea2fc6ec04..f256d6e04d 100644 --- a/lib/OpenLayers/Layer/VirtualEarth.js +++ b/lib/OpenLayers/Layer/VirtualEarth.js @@ -212,12 +212,25 @@ OpenLayers.Layer.VirtualEarth.prototype = * @type int */ getZoomForExtent: function (bounds) { - var zoom = null; - if (this.vemap != null) { - var gBounds = this.getVELatLongBoundsFromOLBounds(bounds); - var gZoom = this.vemap.getBoundsZoomLevel(gBounds); - zoom = this.getOLZoomFromGZoom(gZoom); - } + + 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) ); + + var maxZoomLevel = this.map.getMaxZoomLevel(); + var minZoomLevel = this.map.getMinZoomLevel(); + + //make sure zoom is within bounds + zoom = Math.min( Math.max(zoom, minZoomLevel), + maxZoomLevel ); + return zoom; },