I know there are numerous posts on the web about this but I cannot get my WMS layer in GeoServer to load in OpenLayers. OpenLayers adds the layer to the 'layer switcher' but it's nowhere to be seen. I'm not sure if it makes a difference (I don't see how it would) but my layer is being stored in a PostGIS database and I can view it fine in GeoServer's layer preview. The layer is in EPSG 4326, which I know is the OpenLayers default, and I'm adding it to an OSM basemap. This is my full URL as in the GeoServer layer preview URL:
http://localhost:8080/geoserver/envision/wms?service=WMS&version=1.1.0&request=GetMap&layers=envision:basecamp_property&styles=&bbox=115.753479003906,-32.2068328857422,116.16431427002,-31.9231204986572&width=512&height=353&srs=EPSG:4326&format=application/openlayers
And this is my code for OpenLayers to access and add the layer:
var wms = new OpenLayers.Layer.WMS('Rezoning Scenario',
'http://localhost:8080/geoserver/envision/wms',
{'layers': 'envision:basecamp_property'},
{isBaseLayer: false}
);
map.addLayer(wms);
Any ideas why it may not be working?
Thanks in Advance.
Ro
Finally! In addition to reprojecting from 4325 to 900913 in GeoServer, I also had to declare the projection as 900913 in the layer properties, like so:
var wms = new OpenLayers.Layer.WMS('Rezoning Scenario',
'http://localhost:8080/geoserver/envision/wms',
{'layers': 'envision:basecamp_property'},
{isBaseLayer: false,
projection: 'EPSG:900913'} //This part was required!
);
map.addLayer(wms);
For some reason, not many examples I've found have had to do this, but I did to make it work.
R