From f56dab0644d65a96a327f071f04e4d2417c14245 Mon Sep 17 00:00:00 2001 From: euzuro Date: Sat, 19 Aug 2006 05:37:07 +0000 Subject: [PATCH] just like r1308, we update virtual earth to use min/max zoomlevel, and update the example git-svn-id: http://svn.openlayers.org/branches/openlayers/2.0@1309 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/ve.html | 11 ++++--- lib/OpenLayers/Layer/VirtualEarth.js | 46 +++++++++++++++++----------- 2 files changed, 35 insertions(+), 22 deletions(-) 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; },