1

I'm using a geoserver and openlayers3 with html. I cannot find the way to obtain the child layers from a layer group. I have a layer group, and I show it in html perfectly, but what I want is to be able to access their children layer, in order to print a checkbox for each one to be able to choose if I want to hide or show each one. I don't know if it's possible, and if so, if I have to make a call using the geoserver to get the layers and then make the call to print them, or it is some method inside openlayer.

The code to print the layer group:

new ol.layer.Group({
    title: 'layer1_group',
    layers: [
      new ol.layer.Tile({
        title: 'layer1_group',
        source: new ol.source.TileWMS({
          url: 'http://testestest:8080/geoserver/geo.test/wms?service=WMS',
          params: {'LAYERS': 'layer_group_3layers'},
          serverType: 'geoserver',
          crossOrigin: null
        })
      })
    ]
  })

layer1_group: contains 3 sub layers. Those three are what I want to print separately.

So now I print only the layer group with the children all together, as the shown image: enter image description here

And what I want is to print the children separate:

enter image description here

5
  • Please share some code with us, and possibly a screenshot. Commented Oct 5, 2018 at 11:19
  • Doesn't the GetCapabilities response contain all information that you need?
    – user30184
    Commented Oct 5, 2018 at 11:30
  • @user30184 this bring all info, and I only want the related to the layergroup. Is there a way to filter to only get what I really want?
    – Arnau
    Commented Oct 5, 2018 at 11:33
  • 2
    Geoserver documentation tells me that there are 5 modes for layer groups. Are you sure that your layer group is not an opaque container meaning that it wouldn't list it's layers? Commented Oct 5, 2018 at 11:46
  • @Stefan_Fairphone the layer group is as container-tree so the child are accessible.
    – Arnau
    Commented Oct 5, 2018 at 12:01

1 Answer 1

2

I found the solution.

If you want to get the children layers from a layer group then you have to make a call to the api, like that:

http://your_server/geoserver/your_schema/your_LAYER_GROUP/wms?request=GetCapabilities

So you have to fill in the url with your data, taking care where it puts "your_LAYER_GROUP" to enter your layer group. With this you will have an xml containing a node named as <Layer> and inside it, it will appear N nodes deppending on the number of sub layers that the parent has.

Then to print it dinamically from an html site, using javascript is easy:

var layerNew = new ol.layer.Tile({
        title: 'new ',
        source: new ol.source.TileWMS({
          url: 'http://your_server/geoserver/your_schema/wms?service=WMS',
          params: {'LAYERS': 'THE_LAYER_NAME_THAT_APPEARS_IN_THE_XML'},
          serverType: 'geoserver',
          crossOrigin: null
        }) });

map.addLayer(layerNew)

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.