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
This commit is contained in:
+7
-4
@@ -18,20 +18,23 @@
|
|||||||
|
|
||||||
var lon = 5;
|
var lon = 5;
|
||||||
var lat = 40;
|
var lat = 40;
|
||||||
var zoom = 5;
|
var zoom = 15;
|
||||||
var map, velayer, layer;
|
var map, velayer, layer;
|
||||||
|
|
||||||
function init(){
|
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);
|
map.addLayer(velayer);
|
||||||
|
|
||||||
markers = new OpenLayers.Layer.Markers("markers");
|
markers = new OpenLayers.Layer.Markers("markers");
|
||||||
map.addLayer(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.LayerSwitcher() );
|
||||||
|
map.addControl( new OpenLayers.Control.PanZoomBar() );
|
||||||
}
|
}
|
||||||
|
|
||||||
function add() {
|
function add() {
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
|||||||
vemap: null,
|
vemap: null,
|
||||||
|
|
||||||
/** @type int */
|
/** @type int */
|
||||||
numZoomLevels: 17,
|
minZoomLevel: 1,
|
||||||
|
|
||||||
|
/** @type int */
|
||||||
|
maxZoomLevel: 17,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -24,6 +27,8 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
|||||||
*/
|
*/
|
||||||
initialize:function(name) {
|
initialize:function(name) {
|
||||||
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
|
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) {
|
getZoomForExtent: function (bounds) {
|
||||||
|
|
||||||
var maxRes = this.map.getMaxResolution();
|
var zoom = null;
|
||||||
var viewSize = this.map.getSize();
|
if (this.vemap != null) {
|
||||||
|
var maxRes = this.map.getMaxResolution();
|
||||||
|
var viewSize = this.map.getSize();
|
||||||
|
|
||||||
var width = bounds.getWidth();
|
var width = bounds.getWidth();
|
||||||
var height = bounds.getHeight();
|
var height = bounds.getHeight();
|
||||||
|
|
||||||
var degPerPixel = (width > height) ? width / viewSize.w
|
var degPerPixel = (width > height) ? width / viewSize.w
|
||||||
: height / viewSize.h;
|
: height / viewSize.h;
|
||||||
|
|
||||||
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
var veZoom = Math.floor( (Math.log(maxRes/degPerPixel)) /
|
||||||
|
Math.log(2) );
|
||||||
|
|
||||||
//make sure zoom is within bounds
|
//make sure zoom is within bounds
|
||||||
zoom = Math.min( Math.max(zoom, 0),
|
var veZoom = Math.min(Math.max(veZoom, this.minZoomLevel),
|
||||||
this.numZoomLevels-1);
|
this.maxZoomLevel);
|
||||||
|
|
||||||
|
zoom = this.getOLZoomFromVEZoom(veZoom);
|
||||||
|
}
|
||||||
return zoom;
|
return zoom;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -245,7 +255,7 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
|||||||
getOLZoomFromVEZoom: function(veZoom) {
|
getOLZoomFromVEZoom: function(veZoom) {
|
||||||
var zoom = null;
|
var zoom = null;
|
||||||
if (veZoom != null) {
|
if (veZoom != null) {
|
||||||
zoom = veZoom;
|
zoom = veZoom - this.minZoomLevel;
|
||||||
}
|
}
|
||||||
return zoom;
|
return zoom;
|
||||||
},
|
},
|
||||||
@@ -260,7 +270,7 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
|||||||
getVEZoomFromOLZoom: function(olZoom) {
|
getVEZoomFromOLZoom: function(olZoom) {
|
||||||
var zoom = null;
|
var zoom = null;
|
||||||
if (olZoom != null) {
|
if (olZoom != null) {
|
||||||
zoom = olZoom;
|
zoom = olZoom + this.minZoomLevel;
|
||||||
}
|
}
|
||||||
return zoom;
|
return zoom;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user