Select to view content in your preferred language

Do not show item in LayerList

2030
4
Jump to solution
04-18-2019 04:00 PM
GregoryBologna
Frequent Contributor

JS 4.11

I am looking for a way to loop through the layers before they get added to my LayerList object and hide some layers.

I can use listItemCreatedFunction: function (event) { } to access the layers and sublayers, but setting layer items visible to false does not work.

I tried using LayerListViewModel but I could not find documentation on the class, and it just blows up on function not found.

const layerListViewModel = new LayerListViewModel()({
    view: view
});

layerListViewModel.listItemCreatedFunction = function (event) {

}

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-LayerList-LayerListViewMo...

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
GregoryBologna
Frequent Contributor

Thanks. I implemented this code to hide subitems.

                  if (item.layer.allSublayers && item.layer.allSublayers.length > 0) {
                    item.layer.allSublayers.forEach(function (item) {
                      if (item.sublayers && item.sublayers.length > 0) {
                        item.sublayers.forEach(function (item) {
                          item.listMode = "hide";
                        });
                      }
                    });
                  }

View solution in original post

0 Kudos
4 Replies
KellyHutchins
Esri Frequent Contributor

You'll want to use the listMode property on the layer in order to hide it from the list: 

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-Layer.html#listMode

GregoryBologna
Frequent Contributor

Thanks. I implemented this code to hide subitems.

                  if (item.layer.allSublayers && item.layer.allSublayers.length > 0) {
                    item.layer.allSublayers.forEach(function (item) {
                      if (item.sublayers && item.sublayers.length > 0) {
                        item.sublayers.forEach(function (item) {
                          item.listMode = "hide";
                        });
                      }
                    });
                  }
0 Kudos
NicoKroes
Occasional Contributor

Is there a way to hide layers in the LayerList widget in ArcGIS API for Javascript in the 3.23 version of the API? I do not believe that the listMode property is available on ArcGIS API for Javascript in the 3.23 version.

0 Kudos
KenBuja
MVP Esteemed Contributor

This thread shows how to do that with a map scene.https://community.esri.com/thread/232289-remove-layers-from-the-layerwidget