Select to view content in your preferred language

On a group layer in the sdk if visibilityMode is set to independent why does it not respect this

173
3
07-23-2024 09:49 AM
MikeBehan
New Contributor

On a group layer like below

            new GroupLayer({
              title: 'Example',
              visibilityMode: "independent",
              layers: featureLayers
            }

In the follow screen shot if a user checks the eye of the whole group layer  to hide then go to a sublayer and check that to show nothing happens our users are find this confusing

Screenshot 2024-07-23 at 5.43.22 PM.png 

version is 4.29 of the SDK

0 Kudos
3 Replies
Sage_Wall
Esri Contributor

Hi @MikeBehan ,

I'm sorry to hear that your users are finding it confusing.  I could be misunderstanding the question, but the `independent` visibility mode is designed to work in the way described.  The parent group layer and it's children's visibility are independent from each other.  Perhaps `inherited` would be a better choice for your use case.  This would match the visibility of the child layers to that of it's parent group layer, but with the disadvantage of not being able to control the individual child layer's visibility outside of that of the group layer. 

Sage_Wall_0-1721774114628.png

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

0 Kudos
Sage_Wall
Esri Contributor

Hi @MikeBehan , If you do want to enable this kind of behavior where the child layer set's the parent to visible when it is visible you could likely add something like this in the listItemCreatedFunction

https://codepen.io/sagewall/pen/rNELgJa 

 

      listItemCreatedFunction: (event) => {
        const { layer } = event.item;
        if (layer.type === "group") {
          layer.layers.forEach((layer) => {
            reactiveUtils.watch(
              () => layer.visible,
              (visible) => {
                if (visible && !layer.parent.visible) {
                  layer.parent.visible = true;
                }
              }
            );
          });
        }
      },

 

 

0 Kudos
JohnGrayson
Esri Regular Contributor

Another option I've done previously, and if you're controlling the entire UX, is to disable the ability of the child layers to change their own visibility if the parent layer is not visible.

0 Kudos