2012-03-01 93 views
0

如果一直在改變一些OpenLayers代碼,並且一個副作用是Google街道基礎層不再顯示合理的地圖,而是縮小爲3 x世界視圖。我沒有把它放入API所建議的代碼應該工作的代碼中。OpenLayers - 地圖拒絕放大到最大程度

相同的代碼 - 但重新排列的 - 在過去的工作確定(但並沒有讓大局觀可惜工作)

我是新來的這一切,我的出路安樂窩所以理智的代碼的檢查,將不勝感激:

它可能是
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

可否請你在公共URL暴露你的頁面所以我們可以測試它和ge對於問題是什麼?或[讓它在這裏工作](http://jsfiddle.net/XzKvP/)。它會讓你的問題更快解決。 – capdragon 2012-03-01 16:01:53

回答

0

的一件事是你拼錯sphericalMercator。它也需要一個布爾值,而不是數字。

sphericalMercator: true 

Reference

更新#1:

請更改此:

var mapoptions = { 
    projection: mercator, 
    units: "m", 
    maxExtent: world 
}; 

此:

var mapoptions = { 
    projection: new OpenLayers.Projection("EPSG:900913"), 
    units: "m", 
    maxExtent: world 
}; 
+0

感謝您的發現。我在代碼中改變了它,但似乎沒有解決問題。奇怪的是,這些錯誤是從工作代碼中剪切和粘貼的! – 2012-03-01 15:46:20

+0

@ChristianMayne:有趣的是如何工作代碼是一個相對的事情。好的,試試我的更新。 – capdragon 2012-03-01 15:57:19

+0

再次感謝。試過 - 沒有改變。我注意到3 x世界寬度適合div寬度的大小。 div的高度大於1 x世界高度。這可能與地圖上的造型有關,還是應該沒有區別? – 2012-03-01 16:03:52