Pergunta

I'm trying to view a WMS layer with OpenLayers, but nothing is displayed. No error messages are shown in the console. Moreover, when I try to access the request string with the browser (Firefox), the map displays just fine. Here is the code.

<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>

Can anyone tell what is wrong with my code?

Foi útil?

Solução

Map is created correctly, but you haven't zoomed to correct location yet, therefore you can't see anything. Use zoomToMaxExtent() to fit view:

map.addLayer(wms);
map.zoomToMaxExtent();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top