1

I am new to JavaScript/OpenLayers. I would like to add a WMS layer (BLD_504) from dwasa (workspace) locally. The code is as follows:

<!DOCTYPE HTML>
<html>
<head>
<title> Dhaka WASA </title>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script src="http://openweathermap.org/js/OWM.OpenLayers.1.3.4.js">  
</script>
<script>
function init() {
    // Add osm background layer
    map = new OpenLayers.Map("mapdiv");
    var mapnik = new OpenLayers.Layer.OSM();
    map.addLayer(mapnik);
    // Add wms layer locally
    var dma_504 = new OpenLayers.Layer.WMS( "Buildings 504","http://localhost:8080/geoserver/dwasa", 
        {layers: 'dwasa:BLD_504', transparent:true}, {isBaseLayer:false} );
    map.addLayer(dma_504);
    // Set the centre of the map
    var lonlat = new OpenLayers.LonLat(90.4, 23.78).transform(
        new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
        new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator
      );
    var zoom = 14;
    map.setCenter(lonlat, zoom);
    map.addControl(new OpenLayers.Control.LayerSwitcher());
}
</script>
<style>
#mapdiv { width:1000px; height:700px; }
div.olControlAttribution { bottom:3px; }
</style>
</head>
<body onload="init();">
<div id="mapdiv"></div>
</body>
</html>

When I zoom in I see the following: The corner of the error of WMS is always at (0,0)

The data looks good in GeoServer: The data is good in GeoServer / OpenLayers

  • 1
    It may be a problem with projections - does geoserver serve the WMS in EPSG:900913? Also, why do you use 900913 and not 3857? 3857 is the official code, 900913 was self-assigned by google and should not be used. See gis.stackexchange.com/questions/40538/… . – til_b Oct 15 '14 at 10:29
  • I looked in the dev.openlayers. And it states the following: Note that the “srs” param will always be ignored. Instead, it will be derived from the baseLayer’s or map’s projection. My 'layer' is in 4326. I'll save it as 3857 in geoserver. – Jonne Kleijer Oct 15 '14 at 10:41
  • Use Firebug or similar to look at the request and response that OpenLayers is making for that data. Chances are it's returning an XML error; Firebug will expose it. – GIS-Jonathan Oct 15 '14 at 14:04
  • Did you find the issue? – nmtoken Oct 11 '16 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.