Using listMode to hide layers in LayerList

362
2
06-17-2019 01:25 PM
AshleyPeters
Occasional Contributor II

It's been a couple of years since I've done much work with the JavaScript API. I'm beginning the process to update several of our maps to the newest version of the API and to make them more mobile-friendly.

I'm working with the Layer list with a legend sample and would like to hide two out of my three layers. It looks like the easiest way to do this would be to use listMode. I've tried a few different things and can successfully get only one of the two layers to hide.

Here's my layer list code currently:

var layerList = new LayerList({
    view: view,
    container: document.createElement ("div"),
        listItemCreatedFunction: function(event) {
            const item = event.item;
            if (item.layer.type != "group") {
              // don't show legend twice
              item.panel = {
                content: "legend",
                open: true
              };
            }
          }
    
    });
    
    var llExpand = new Expand({
    view: view,
    content: layerList.domNode,
    expandIconClass: "esri-icon-layer-list"
    });
    
    view.ui.add(llExpand, "top-right");
    });

I've tried this option - https://community.esri.com/thread/232289-remove-layers-from-the-layerwidget - with little to no success.

Any help would be appreciated. Thanks!

Ashley

Tags (2)
0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Ashley,

  What about the method Ken Shows in that link are you having a hard time with?

DavidWilson3
Occasional Contributor

Hi Ashley,

If you want to have your layers still be in the list but be un-selected you can make the visibilityMode property of the GroupLayer "independent" and then set the visible property of the layers to false. Also if you have a GroupLayer you could just remove the layers you do not want from the GroupLayer.

0 Kudos