[GIS] Finding URL of GeoServer layer

geoserveropenlayers-2wms

I'm a basic/novice user with GeoServer. I've installed it and have loaded a sample shapefile, which I can view using the Layer Preview option.

enter image description here

Now I want to add this shapefile (as a WMS layer) to a simple OpenLayers map using the methodology listed at http://dev.openlayers.org/docs/files/OpenLayers/Layer/WMS-js.html:

var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
    "http://wms.jpl.nasa.gov/wms.cgi",
    {
    layers: "modis,global_mosaic",
    transparent: true
    }, {
    opacity: 0.5,
    singleTile: true
}); 

How do I find the URL which corresponds to one of the layers in the screenshot above?

If I use the Preview Layer option and choose JPG as the format, the URL is in the form:

http://localhost:8080/geoserver/cite/wms?service=WMS&version=1.1.0&request=GetMap&layers=cite:States2006 … rather than the /wms.cgi form listed above.

Thanks for any advice on getting started with GeoServer and OpenLayers.

Best Answer

The short answer is

http://localhost:8080/geoserver/cite/wms

The longer answer is that the URL in OpenLayers is the base URL of the web map server (so all the bit before the ? in the full URL). OpenLayers then adds the required parameters to make up the URL that is required to get a map. Some of those parameters are added from your layer definition (i.e. layers, transparent etc) and others from the map object (i.e. width/height and bounding box). See Lesson 8 of my old course to see a fuller discussion.

Related Question