AnsweredAssumed Answered

Include Legend in Layerlist

Question asked by shakibamor on Aug 8, 2017
Latest reply on Aug 9, 2017 by khutchins-esristaff

Hello Everyone. I am doing a project and I am new to API 4.4. What I want to do is to include legend in layerlist below the name of each layer. In 3.21 there is showlegend option in layerlist but in 4.4 it is not. I tried to use actionsSections to define listItem createdfunction and add Legend widget in this way but I am  not sure even the logic is going to work.

I want to look like this. Do you think it is posiible to do that by defining item.actionsSections?

 

        var legend = new Legend({
            view: view,
            layerInfos: [{
                layer: fl,
                title: "Legend"
            }],
        });

 


        var layerList = new LayerList({
            view: view,
            listItemCreatedFunction: defineActions,
            container: "layers"

 

        });

 


        function defineActions(event) {

 


            var item = event.item;


            item.actionsSections =[
                [{
                    title: "showlegend",
                    id: "legendlayers"

 

            }],
            [{
                title: "Increase opacity",
                className: "esri-icon-up",
                id: "increase-opacity"
            }, {
                title: "Decrease opacity",
                className: "esri-icon-down",
                id: "decrease-opacity"
            }]];
        }

 

        layerList.on("trigger-action", function (event) {

 

            var id = event.action.id;

 

            if (id === "legendlayers") {

 

                legend.show();

 

            }
        });

 

        view.ui.add(layerList, "top-left");

Outcomes