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.
Note that both layers show correctly (but the pink layer icon is disappearing in the legend):