Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How to overlay a wms layer from geoserver (localhost)in Open layers? What is the basic syntax of Geoserver WMS Layer? Details are as follow ! workspace name: india
layer name:hospitals.

 <script defer="defer" type="text/javascript">
 var map = new OpenLayers.Map('map'); 
 var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "labs.metacarta.com/wms/vmap0";, {layers: 'basic'} );
 var twms = new OpenLayers.Layer.WMS( "World Map", "localhost:8080/geoserver/wms? service=wms& version=1.1.1& request=GetCapabilities", 
     map: 'hospitals', 
     transparent: 'true', 
     layers: 'hospitals'
 } ); 
 map.addLayers([wms, twms]);

plz solve this!!


share|improve this question
what have you tried so far? Have you tried this sample: openlayers.org/dev/examples/wms.html –  Devdatta Tengshe Apr 23 '13 at 9:07
Ya i tried the basic wms layer, now i want to overlay my layers from geoserver . what me to do? –  satya chandra Apr 23 '13 at 9:10
please post the code that you have already used, and let us know where you are stuck right now. –  Devdatta Tengshe Apr 23 '13 at 9:20
Please edit your question and put it there, instead of in a comment. Also, what is the url of your geoserver? –  Devdatta Tengshe Apr 23 '13 at 9:32

3 Answers 3

up vote 4 down vote accepted

Your OpenLayers.Layer.WMS statements should look like this:

basemap = new OpenLayers.Layer.WMS( "Layer Name1",
    "http://localhost:8080/geoserver/wms/workspacename", {layers: 'workspacename:layername'} );\
utility = new OpenLayers.Layer.WMS( "Layer Name2",
    "http://localhost:8080/geoserver/wms/workspacename", {layers: 'workspacename:layername', transparent:"true"}, {isBaseLayer:false} );
share|improve this answer
i want add one layer, is it sufficient the follow code? basemap = new OpenLayers.Layer.WMS( "Layer Name1", "localhost:8080/geoserver/wms/workspacename";, {layers: 'workspacename:layername'} ); –  satya chandra Apr 23 '13 at 10:37
thanks i got it, successfully added wms from my geo server –  satya chandra Apr 23 '13 at 10:43

Please consider the version of the your API. Also define suitable projection for your layer.

var layer2 = new OpenLayers.Layer.WMS(maplayer.displayName,
                { layers: [2], version: '1.3.0' ,'srs':maplayer.crs},
                  {singleTile: true,
                      isBaseLayer: false,
                      projection: "EPSG:102113"


share|improve this answer

It should be enough removing '? service=wms& version=1.1.1& request=GetCapabilities' from the url parameter of the layer declaration

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.