我试图在网站上显示一个开放的图层地图,但MVC网站上的地图甚至没有显示缩放按钮。但是在正常的记事本中,地图显示的代码相同,我无法找到问题所在。有人能帮帮我吗?
这是我的代码:
<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 :(得分:0)
问题可能在于呈现您的网页。查看浏览器中生成的源代码,id =&#34; map&#34;可能已被ASP重命名,而新的OpenLayers.Map(&#34; map&#34;)则没有指向正确的容器对象。