如果改变了一些OpenLayers代码,并且一个副作用是Google Street基础层不再显示合理的地图,而是缩小到3 x世界视图。我没有把任何内容放入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]);
}
}
答案 0 :(得分:0)
可能有一件事是您拼错了 sphericalMercator 。它还需要一个布尔值,而不是数字。
sphericalMercator: true
请更改此内容:
var mapoptions = {
projection: mercator,
units: "m",
maxExtent: world
};
为此:
var mapoptions = {
projection: new OpenLayers.Projection("EPSG:900913"),
units: "m",
maxExtent: world
};