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.

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}); 
}
share|improve this question

2 Answers 2

up vote 6 down vote accepted

The restconfig api allows you to do this:

http://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html

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.

share|improve this answer
    
    
can you plz tell me how to request the data in any format?? i mean is it through a url or any command to be given or by a php/html file or etc??? I mean I dont know how to execute those operations specified in ur link –  Vikash Talanki Jun 14 '11 at 22:02

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.

share|improve this answer
    
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??? –  Vikash Talanki Jun 13 '11 at 15:10

Your Answer

 
discard

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.