[英]OpenLayers - Map refusing to zoom to max extent
If been changing round some OpenLayers code, and one side effect is that by Google Street base layer no longer displays a sensible map, but instead zooms out to a 3 x world view. 如果围绕某些OpenLayers代码进行更改,则副作用是Google Street基本图层不再显示明智的地图,而是缩小到3倍的世界视图。 Nothing I put into the code which the api suggests should work does. 我在api建议的代码中没有做任何工作。
The same code - but rearranged - worked OK in the past (but didn't allow the bigger picture to work unfortunately) 相同的代码-但经过重新排列-过去可以正常使用(但不幸的是,它不允许更大的画面起作用)
I'm new to all this and way out of my comfort zone so a sanity check of the code would be much appreciated: 我是这方面的新手,并且超出了我的舒适范围,因此对代码的健全性检查将不胜感激:
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]);
}
}
One thing it could be is that you've misspelled sphericalMercator . 可能一件事是您拼错了sphericalMercator 。 Also it takes in a boolean value, not numeric. 此外,它接受布尔值,而不是数字。
sphericalMercator: true
Please change this: 请更改此:
var mapoptions = {
projection: mercator,
units: "m",
maxExtent: world
};
for this: 为了这:
var mapoptions = {
projection: new OpenLayers.Projection("EPSG:900913"),
units: "m",
maxExtent: world
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.