I am trying to overlay a layer from Geoserver on an OpenStreetMap base layer. If I load the Geoserver layer as a base layer, I can see it - but if I set baselayer to false it disappears.
My code is:
<!DOCTYPE HTML>
<html>
<head>
<title>OpenLayers Demo</title>
<style type="text/css">
html, body, #basicMap {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<script src="../OpenLayers-2.13.1/OpenLayers.js"></script>
<script>
function init() {
map = new OpenLayers.Map("basicMap");
var mapnik = new OpenLayers.Layer.OSM({transparent:true});
map.addLayer(mapnik);
map.addLayer(new OpenLayers.Layer.WMS("Test Addresses","http://localhost:8080/geoserver/os_lv/wms",{layers: 'os_lv:test_addresses',transparent: true},{ isBaseLayer: false,opacity: 0.5})) ;
// map.addLayer(new OpenLayers.Layer.WMS("Test Addresses","http://localhost:8080/geoserver/os_lv/wms",{layers: 'os_lv:test_addresses',transparent: true},{opacity: 0.5})) ;
map.addControl(new OpenLayers.Control.LayerSwitcher()) ;
}
</script>
</head>
<body onload="init();">
<div id="basicMap"></div>
<p id="shortdesc">
Shows the basic use of openlayers using a WMS layer
</p>
</body>
</html>
I've used firebug to investigate the calls being made to geoserver. In the case where I add the WMS as a base layer I see the following:
<img class="olTileImage" style="visibility: inherit; opacity: 0.5; position:
absolute; left: 664px; top: 81px; width: 256px; height: 256px;"
src="http://localhost:8080/geoserver/os_lv/wms?
LAYERS=os_lv%3Atest_addresses&TRANSPARENT=TRUE&SERVICE=WMS
&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS=EPSG%3A4326
&BBOX=-3.4157819747925,50.611286201963,-3.3442823886872,50.682785788068
&WIDTH=256&HEIGHT=256" id="null">
whereas when baselayer is false it's
<img class="olTileImage" style="visibility: inherit; opacity: 0.5; position:
absolute; left: 773px; top: 16px; width: 256px; height: 256px;"
src="http://localhost:8080/geoserver/os_lv/wms?
LAYERS=os_lv%3Atest_addresses&TRANSPARENT=TRUE&SERVICE=WMS
&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng
&SRS=EPSG%3A900913&BBOX=-180,-90,2265.9849047852,2355.9849047852
&WIDTH=256&HEIGHT=256">
The first call returns a PNG showing my data, the second one is empty.
A final point is that my data in Geoserver has native SRS EPSG:4258 and declared SRS EPSG:4326 - I have set the "Reproject native to declared" option.