LayerList legend icon missing

581
5
09-06-2023 06:35 AM
ranico
by
New Contributor II

I'm trying to toggle between four layers (in a list of 7 added to my map) with a radio button. Two should appear when one button is clicked (2022) and then hide when the 2023 button is clicked and those layers show instead. I am using layer.listMode to show and hide the layers. By default, the two 2023 layers show and the 2022 ones are in listmode = "hide" mode. 

Everything looks fine by default, but when the radio button is clicked and things switch, the legend icon disappears for one of the data layers. My code is relatively clean and I don't know what is causing only one of the icons to disappear. Note that the order does affect which layer's icon disappears - if I switch the QCT 2022 layers with the DDA 2022 layer, the DDA layer icon will disappear instead.

 

ranico_0-1694006114240.png

Note that both layers show correctly (but the pink layer icon is disappearing in the legend): 

ranico_1-1694006458577.png

 

 

Tags (3)
0 Kudos
5 Replies
JeffreyThompson2
MVP Regular Contributor

I suspect your problem is in the part where you set all of your layers invisible. I believe that the symbology is automatically hidden for invisible layers. How do your layers become visible again? 

GIS Developer
City of Arlington, Texas
0 Kudos
ranico
by
New Contributor II

In the layer constructor, I have the visible property set to false by default for each layer. I also reset all layer visibility to false again when a new year is selected (see the last few lines of code in the original picture that loops through all the layers).

The layers become visible again when a user clicks it in the layer list widget. You can see the layer becomes visible again for both layers but only the DDA list item has the icon.

0 Kudos
ranico
by
New Contributor II

For some reason, the "esri-layer-list-panel" class / div is disappearing when the radio buttons are clicked (but only for the QCT layers). This container is what contains the legend and icon. It's there by default, but when I click 2022 and back to 2023 it disappears.

ranico_0-1694030255831.png

 

0 Kudos
Sage_Wall
Esri Contributor

Hi @ranico, could you please supply a working example as a Codepen, StackBlitz or in some other way.  It's hard to troubleshoot and debug as it looks like you've modified or created a custom layer list.  If you add an unmodified Legend and LayerList widget does it work as expected?

Another option, if you want to use the stock widgets,  might be to use the LayerList with a group layers for 2022 and 2023 and create a parent group layer with the  `visibilityMode` property set to `exclusive` as shown in this sample. I think this would give you the same kind of functionality but would be all out of the box.

https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-actions/

0 Kudos
ranico
by
New Contributor II

Hi! Thank you for trying to help. I can't share my entire code because it is for work but I will get back to you in a week for a status report. We're going to try to debug it more internally. I am using custom CSS for the layer list so implementing a group layer will definitely be tricky because I'll also have to play with the CSS more again. I'll keep looking into it though, thanks for the suggestion.

0 Kudos