Question

I have a problem with WMS overlays in OpenLayers. Basically I just want to add data from a WMS server as an overlay and not as a base layer. This appears to be a very simple problem but I am unable to find a solution. If I set singleTile to true, the overlays appears over the whole map but you cannot zoom in. If it is set to false, only one tile is displayed at every zoom level. If I set it as a base layer, it works just fine but I really want the overlay solution so I can make it transparent and see the map behind it.

Demonstration of the problem, with a different dataset but the issue is the same: http://jsfiddle.net/adbnC/2/

I think it might be related to some coordinate system issues but I am no expert so any help is appreciated.

Thanks a lot!

Here is the relevant section of the code that does not work as expected:

var pop_layer = new OpenLayers.Layer.WMS("Population Density in 2000",
    "http://sedac.ciesin.columbia.edu/geoserver/ows", {
        layers: 'gpw-v3:gpw-v3-population-density_2000',
        transparent: true
     }, {
         opacity: 0.5,
         isBaseLayer: false,
         // Setting single tile to true will kind of work but than one
         // cannot zoom in any more.
         singleTile: false
     }
);
Was it helpful?

Solution

I can't quite get what exactly is wrong here, but I think it has something to do with messed up reference systems. Here is a workaround:

Modified Jsfiddle.net

I changed the map projection to spherical mercator and now it seems to work fine for me:

var mapOptions = {
    div: "map",
    projection: new OpenLayers.Projection("EPSG:900913"),
    units: "m"
};

map = new OpenLayers.Map('map', mapOptions);

var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);

var pop_layer = new OpenLayers.Layer.WMS("Population Density in 2000", "http://sedac.ciesin.columbia.edu/geoserver/ows", {
    layers: 'gpw-v3:gpw-v3-population-density_2000',
    transparent: true
}, {
    opacity: 0.5,
    isBaseLayer: false
});

map.addLayer(osm);
map.addLayer(pop_layer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(new OpenLayers.LonLat(0, 0), 2);​

Let me know if that helped!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top