简体   繁体   中英

Where should I place the layerList.multipleSelectionEnabled=false; property in ArcGIS Maps SDK for JavaScript 4.x?

I am trying to create a web application that allows users to explore layers related to climate safe neighborhoods. When I asked some of my colleagues to try an out of the box template from ArcGIS Online, they had difficulty understanding that they need to turn off layers above the layer they want to see to view it. I want to code a map that only allows users to select one layer at a time, so this doesn't happen, and I also want the legends to show with the layer list item. There's a solution that allows only one layer selection at a time that I found on this site, but it doesn't also show the legend, and it uses an older version of the API which I am not familiar with Single layer visible in LayerList widget (ArcGIS JavaScript) .

Most of my data is Choropleth, so the layers cover each other even when I lower their opacity. I located an html file I created from my web mapping course in college, and I've been trying to modify it to allow only one selection at a time within the layerList. Once I figure that out, I want to apply that code to my Climate Safe Neighborhoods Map. The API documentation says to add the following code, but it doesn't say where.

layerList.selectionEnabled = true; layerList.multipleSelectionEnabled = false;

I assumed these are attributes of the object so I added them here with no luck.

View in Visual Studio Code full html file

const layerList = new LayerList ({
        view: view,
        container: "legendDiv",
        selectionEnabled: true,
        multipleSelectionEnabled: false,
        listItemCreatedFunction: function(event){
            const item = event.item;
            if (item.layer.type !="group"){
                item.panel = {
                    content: "legend",
                    open: true
                };
            }
        }
});

I also tried adding the API documentation suggested code after the constant was created, and that didn't work. Thank you so much to anyone who can help me out with this. I am new to coding, and I have never done anything with this much complexity.

I received an answer to this question on the ESRI Community Forum. Solution to allow only one selectable layer at a time

This ERSI Community response helped me add a legend to go along with the GroupLayerList.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM