I have a web map with multiple layers served from my local rest map services. I want to build a web app that will allow me to specify in the url which of those layers are on or off.
I understand the default visibility is set in the web map. But the visibility can be changed in the web app with the LayerList widget. I want to change the visibility at load time without the user having to open the LayerList. I know there is an entry point to affecting the layer visibility through code because LayerList does it.
I want to pass in my url http://<path>/?layers=1,2,3 so that all layers are turned off except those that match to indexes 1, 2, and 3 in my array of layers. I can take care of a lookup to get the names of these layers. Once I have a reference to the operating layers, I can set the visibility property to true or false for the specified layers. When I step through my code, I can see that the visibility values are changed, but there is no corresponding impact on the map.
I think what I am missing are 1) referencing the operating layers correctly (this.operLayerInfos in LayerList/Widget.js); and 2) calling my function from a proper location where it will be invoked when the map loads. Or maybe visibility isn't the right property?
I would appreciate any guidance for how/where to add this functionality.
First draft code in attachment.
You need to work with the jimu.js classes if you want WAB to recognize that you have changed a layers visibility.
Look at the code in the Layer Toggle Button widget. It uses the Jimu LayerStructure class to get the layer objects in the webmap.
I think I found what I need here: Use URL parameters—Web AppBuilder for ArcGIS | Documentation .
I see I can pass in showLayers=<LayerName1>;<LayerName2>. All I need for a numeric lookup is to add in a lookup table.