What is the right way to get the full list of sublayers of a WMSLayer?

204
0
01-31-2020 01:02 AM
AlexanderParshin
New Contributor II

My case is the following: I have a custom widget, which displays tree of Layers of a WMS and allows users to select Layers to show on the map. I'd like to use WMSLayer to both get the full list of WMS Layers for the widget and to control visible on the map WMS Layers.

But I don't understand how to do that in the best way because:

  • If I omit the "sublayers" property of WMSLayer during initialization, I get the full list of WMS Layers, but all of them are rendered on the map, which is not what I need
  • If I set the "sublayers" property of WMSLayer during initialization, I have access (through "sublayers") to the description of only those WMS Layers, not to the whole list.

I have to use a workaround:

  1. Don't set "sublayers" and set "visible=false" during instantiation of WMSLayer
  2. When the WMSLayer is loaded, I read the full list of WMS Layers and set proper "sublayers" (WMS Layers I want to see on the map) and "visible=true"

CodePen: https://codepen.io/parshin/pen/NWPZwVV?editors=1000 

But this approach seems a little bit hacky to me. Is there a better way to do it?

0 Kudos
0 Replies