Im using the LayerList (4.13) with the legend integrated into it. I'd like for the legend to toggle open when the user clicks to make the layer visible. I'm watching the layers visible property but cannot figure out the code to toggle the legend open. Any ideas?
It looks like if you uncomment line 1829 in the github code (it was line 1699 for me locally), and set the `open` property to `true`, the legend swatches show by default.
item.panel = { content: "legend", //open: true }
Hi, sorry to reply to this old post but I'm trying to do the same thing. I don't think the sample acutally toggles the visibility of the legend. Adding the legend widget to the layerlist item panel adds the legend toggle button next to the layer item name. If you set the item.panel open property to item.visible it will indeed open and display the legend of the layers that are turned on when the map first loads. However, if you turn the layer off it doesn't actually close the panel. It displays No Legend, which is confusing for the user. If you click the legend button again it correctly closes the item.panel. You can see this in the sample you linked to. The layer visibility and legend visibility work independently of each other. I would like to link the layer visibility (eyeball button) to the actual item.panel.open property. So that the legend panel actually closes (and doesn't display No Legend) when a user turns off the layer. How would I do that?
Sure. See link below.
github
Wanna share some code/repro case and I can take a look?
Noah
Not sure if it is because I have over 20 different layers, I'm not using a webmap, or the fact I have 4 grouplayers but, it does not function in the same way. I turn on a layer and I still have to click the legend button to see it.
I'm pretty sure that's what we do in this sample:
ArcGIS API for JavaScript Sandbox
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.