Add Legend Icon to LayerList ListItems

391
2
05-22-2019 02:32 PM
GregoryBologna
Occasional Contributor

How do I get to the appropriate legend icon data from within listItemCreatedFunction and add the icon graphic to a Layerlist item? 

I am adding a legend to a LayerList with the legend button to the right of the layer title, and the legend icon graphic below the layer title. 

added with the code here

                  var featureLayer = map.layers.getItemAt(2);
                  if (item.layer.type != "group") {
                    // don't show legend twice
                    item.panel = {
                      content: "legend",
                      layerInfos: [{
                        layer: featureLayer,
                        title: "blah"
                      }],
                      open: false
                    };
                  } // end type

I want to change this so that the legend icons are added to the LayerList Listitems instead.

(image is from a web app. builder. I am not using wab)

0 Kudos
2 Replies
VictorTey
Esri Contributor

Not sure which part of the question are you stuck with

Do you need help getting the legend?

You can get the legend from

https://developers.arcgis.com/rest/services-reference/legend-map-service-.htm

Or do you need help getting the legend to appear under the layerlist item

0 Kudos
GregoryBologna
Occasional Contributor

I need to add the legend icon to appear within each listitem. I will add a button beside the layer to toggle open\close state of all the listitems. 

Web Layer Title             [icon-button] <--- click button to open layer legend

Public Schools

Sales

Web Layer Title            [icon-button] <--- click button to close layer legend

Public Schools

Public Schools

Sales

0 Kudos