Tuesday 21 February 2017

openlayers 2 - Get the list of layers in a store from geoserver



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});
}

Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...