[英]OpenLayers - Map refusing to zoom to max extent
如果圍繞某些OpenLayers代碼進行更改,則副作用是Google Street基本圖層不再顯示明智的地圖,而是縮小到3倍的世界視圖。 我在api建議的代碼中沒有做任何工作。
相同的代碼-但經過重新排列-過去可以正常使用(但不幸的是,它不允許更大的畫面起作用)
我是這方面的新手,並且超出了我的舒適范圍,因此對代碼的健全性檢查將不勝感激:
function ProfileMap(mapName)
{
this.name = mapName;
this.layers = [];
// define Map options
var mapoptions = {
projection: mercator,
units: "m",
maxExtent: world
};
// define Base Layer
var baselayer = new OpenLayers.Layer.Google(
"Google Streets",
{numZoomLevels: 20, spehericalMercator: 2}
);
this.init = function(mapdiv, keydiv)
{
var layerswitcher = new OpenLayers.Control.LayerSwitcher(
{div: document.getElementById(keydiv)}
);
this.map = new OpenLayers.Map(mapdiv, mapoptions);
this.map.addLayer(baselayer);
this.map.setCenter(mapcenter);
this.map.zoomToMaxExtent();
};
this.addMapLayer = function(layerName)
{
var layerid = this.layers.length;
this.layers[layerid] = new OpenLayers.Layer.Markers(layerName);
this.map.addLayer(this.layers[layerid]);
}
}
// Map actually created by a call to this function
function createMap(mapName, div, keydiv, mapLayers)
{
mapName = new ProfileMap(mapName);
mapName.init(div, keydiv);
for(var i=0; i < mapLayers.length; i++)
{
mapName.addMapLayer(mapLayers[i]);
}
}
可能一件事是您拼錯了sphericalMercator 。 此外,它接受布爾值,而不是數字。
sphericalMercator: true
請更改此:
var mapoptions = {
projection: mercator,
units: "m",
maxExtent: world
};
為了這:
var mapoptions = {
projection: new OpenLayers.Projection("EPSG:900913"),
units: "m",
maxExtent: world
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.