Is there a way to get the all the layers present in a store in geoserver?

My JS file contains code for each layer present in a store. So when I publish a new layer in geoserver I have to manually include the code of the new layer in JS. But what I want is to put a for loop in JS with the layer names present in a store, like

for(i<=all layers present in store)                 
   var wmslayer2 = new OpenLayers.Layer.WMS("Layer2","http://localhost:8080/geoserver/wms", 
   {'layers': '**cite:layer[i]**', 'format':'image/png', 'transparent':'true'},
   {'opacity': 1.0, 'isBaseLayer': false, 'visibility': true}); 

2 Answers 2


The restconfig api allows you to do this:


You can request data be sent back in JSON as well which is handy from javascript code. The WMS caps has the same info but it is a huge xml document... so expensive to parse on the client side.


The answer to the GetCapabilities request contains a list of all layers offered by the server. But it's probably easier to create a layer group in Geoserver that simply contains all layers. Then you only have to request that group.

  • But layer group contains all the layers which are shown as a single layer on map. I mean my layer switcher has only a single overlay at that time, Is it not??? Commented Jun 13, 2011 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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