我试图用OpenLayers查看一个WMS层,但是什么也没有显示。控制台中未显示任何错误消息。此外,当我尝试使用浏览器(Firefox)访问请求字符串时,地图显示得很好。下面是代码。
<html>
<head><title>OpenLayers WMS test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script>
function init() {
var map = new OpenLayers.Map("maparea");
var wms = new OpenLayers.Layer.WMS("Maakuntakaava", "http://kartat.lounaispaikka.fi/wms/maakuntakaava",
{'format':'png', 'layers':'mk_tiet', width:600, height:600,
bbox:'224609.4426922916318290,6702129.8832325218245387,265885.8128110636025667,6720672.7353315912187099'},
{ projection: new OpenLayers.Projection("EPSG:3067"),
units: "m",
maxResolution: 1000,
maxExtent: new OpenLayers.Bounds(224609.4426922916318290,6702129.8832325218245387,265885.8128110636025667,6720672.7353315912187099)});
map.addLayer(wms);
alert("Request string: " + wms.getFullRequestString());
}
</script>
</head>
<body onload="init()">
<h1>WMS test</h1>
<div id="maparea"></div>
</body>
</html>有人能说出我的代码出了什么问题吗?
发布于 2012-11-22 19:20:19
地图已正确创建,但您尚未缩放到正确的位置,因此您看不到任何内容。使用zoomToMaxExtent()调整视图:
map.addLayer(wms);
map.zoomToMaxExtent();https://stackoverflow.com/questions/13509908
复制相似问题