2014-04-19 113 views
0

我試圖在網站上顯示一個開放的圖層地圖,但是MVC網站上的地圖甚至沒有顯示縮放按鈕。但在地圖顯示的代碼相同的普通記事本上,我無法找到問題所在。有人能幫助我嗎?MVC地圖中的OpenLayers沒有顯示

這是我的代碼:

<script type="text/javascript"> 
     $(document).ready(function() { 
      init(); 
     }); 

     var map, layer; 
     var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984 
     var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection 

     function init() { 
      map = new OpenLayers.Map("map") 

      var osmlayer = new OpenLayers.Layer.OSM("Simple OSM Map"); 
      map.addLayer(osmlayer); 

      var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic", "http://wms.jpl.nasa.gov/wms.cgi", { layers: "modis,global_mosaic" }); 
      map.addLayer(wms); 

      map.addControl(new OpenLayers.Control.LayerSwitcher()); 
      map.setCenter(new OpenLayers.LonLat(14.505787300000065, 35.8760686).transform(fromProjection, toProjection), 9); 
     } 

    </script> 
</asp:Content> 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

<h2>Home</h2> 
    <div id="mainPage"> 
     <div id="map"></div> 
    </div> 
</asp:Content> 

回答

0

的問題可能出在你的頁面的渲染。看看在你的瀏覽器中生成的源代碼,帶有id =「map」的div可能已經被ASP重命名,並且新的OpenLayers.Map(「map」)不會指向正確的容器對象。