AnsweredAssumed Answered

Set Layer Visibility in URL

Question asked by SandsDOT on Jan 7, 2020
Latest reply on Jan 22, 2020 by SandsDOT

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.