Explanation:
I'm currently trying to change the visible legend when a user selects one of three grouped layers to view. These can then be interacted with in a LayerList widget. Only one layer can be selected at a time, so the legend won't clash with any others. I've tried to look up for an event that runs on selecting a different layer via the LayerList, but haven't come across anything yet. Is this possible?
Code:
var groupLayer = new GroupLayer({
title: 'Tauranga Points of Interest',
visible: true,
visibilityMode: 'exclusive',
layers: [LAYERS_ADDED_IN_HERE],
opacity: 0.7
})
Images:
Solved! Go to Solution.
Hi there,
It should work. Perhaps you are adding one of layer types that is not supported in the Legend widget? You can see the list of unsupported layers from the sdk doc.
If it is not working, could you please provide a test app? Looks like you probably already know about this sample: https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-actions/
I have updated this sample to use legend and did not see any issues: https://codepen.io/U_B_U/pen/mdRQpwM?editors=1000
-Undral
Hi there,
It should work. Perhaps you are adding one of layer types that is not supported in the Legend widget? You can see the list of unsupported layers from the sdk doc.
If it is not working, could you please provide a test app? Looks like you probably already know about this sample: https://developers.arcgis.com/javascript/latest/sample-code/widgets-layerlist-actions/
I have updated this sample to use legend and did not see any issues: https://codepen.io/U_B_U/pen/mdRQpwM?editors=1000
-Undral
Thank you! I hadn't thought about adding the LayerGroup as the layer for the legend widget, so this was exactly what I was looking for.
Hey!
It looks like your Legend is limiting the layers being displayed in one of two ways. The layers that don't have a legend may have the legendEnabled property set to false OR the Legend widget itself has layerInfos set that don't include the other layers.
Make sure layer.legendEnabled is true for all layers and that the Legend.layerInfos is null. If it's null the Legend widget should handle visibility of layers automatically... Let me know if that wasn't the issue...
Kristian