Hide GroupLayer on LayerList by default (on page load)

356
2
Jump to solution
11-29-2022 11:54 AM
klzheng
New Contributor II

Hello, does anyone know how to hide an entire GroupLayer by default? Meaning that when the page loads, one of the GroupLayers are hidden (eye icon crossed out) on the LayerList.

Here is what it looks like right now (on page load): 

klzheng_0-1669751549553.png

As you can see on the LayerList, both "eye" icons are not crossed out

 

Here is what I am trying to achieve: 

klzheng_1-1669751605554.png

You can see that the first GroupLayer is toggled to be hidden. But I was only able to do this after the page loads, is there a way to code it so that the first GroupLayer would be toggled to be hidden by default? Thanks!

 

Here is the codepen: LayerList widget with actions | Sample | ArcGIS API for JavaScript 4.25 (codepen.io)

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Set the GroupLayer's visibility to false when you construct it

 

var incomeGroupLayer = new GroupLayer({
  title: "Income GroupLayer",
  layers: [tractIncomeLayer, countyIncomeLayer, stateIncomeLayer],
  visible: false
});

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

Set the GroupLayer's visibility to false when you construct it

 

var incomeGroupLayer = new GroupLayer({
  title: "Income GroupLayer",
  layers: [tractIncomeLayer, countyIncomeLayer, stateIncomeLayer],
  visible: false
});

 

klzheng
New Contributor II

Thank you so much! 

0 Kudos