我正在尝试添加地图到我的网页。Shapefiles在GeoServer中上传/发布。当发出请求时,网页上不显示地图。以下是代码:
<html>
<head>
<script type="text/javascript" src="OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://localhost:8080/geoserver/New_York_Roads/wms",
{ layers: 'basic' }
);
map.addLayers([wms]);
map.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
<div id="map" style="width: 600px; height: 300px">
</div>
</body>
</html>
改变这一行:
map.addLayers([wms]);
:
map.addLayer(wms);
更多信息在这里