Select to view content in your preferred language

Hiding layers added at runtime from LayerList

642
2
Jump to solution
05-16-2023 11:33 AM
JeffreyThompson2
MVP Regular Contributor

I have several map layers that I am adding during runtime that I would like to hide from the LayerList widget. These layers cannot be hidden in the builder mode because they are added later through other custom widgets. Based on my console logs, the LayerList runs once when the Experience first loads and does not render again unless one of the settings are changed in builder mode. I tried to trigger re-renders by loading the mapView, mapView.view.map.layers, and mapView.view.map.layers.length into state, but that did not work. (I realize now that I would need to call setState() to get that idea to work, but I can't do that without changing the props.)  Converting the widget from a PureComponent to a Component triggered so many re-renders that it crashed on loading. I think I could make it work with useEffect(), but it's a class based component so I can't use Hooks. Questions:

1. How are layers added/removed from the LayerList widget without triggering re-renders?

2. Could I create a custom widget to call my custom LayerList widget and pass down changes in props?

3. Would it be easier to make a new widget from scratch?

4. @TonghuiMing Is the development team planning on re-writing this widget into a functional component?

GIS Developer
City of Arlington, Texas
0 Kudos
1 Solution

Accepted Solutions
Grant-S-Carroll
Esri Contributor

Presume you’re adding the layer and assigning properties like an Id etc? Have you seen the layer list mode you can assign? This will allow you to hide the layer from the layer list. See the api doc section here.docs 

View solution in original post

2 Replies
Grant-S-Carroll
Esri Contributor

Presume you’re adding the layer and assigning properties like an Id etc? Have you seen the layer list mode you can assign? This will allow you to hide the layer from the layer list. See the api doc section here.docs 

JeffreyThompson2
MVP Regular Contributor

I didn't know about that property. I was making things way too complicated.

GIS Developer
City of Arlington, Texas