Select to view content in your preferred language

Enable and Disable LayerList actions

139
1
Jump to solution
11-07-2024 07:06 PM
Aeseir
by
Frequent Contributor

i am trying to figure out how to dynamically enable and disable layerlist actions.

say the actions list example from website

 

enableControls = false;
<button (click)="enableControls = !enableControls">Toggle Control</button>

const layerList = new LayerList({
  view: view,
  // executes for each ListItem in the LayerList
  listItemCreatedFunction: defineActions
});

async function defineActions(event) {
  if(!enableControls)
    return;

  const item = event.item;

  await item.layer.when();

  if (item.title === "US Demographics") {
    item.actionsSections = [
      [
        {
          title: "Go to full extent",
          icon: "zoom-out-fixed",
          id: "full-extent"
        },
        {
          title: "Layer information",
          icon: "information",
          id: "information"
        }
      ],
      [
        {
          title: "Increase opacity",
          icon: "chevron-up",
          id: "increase-opacity"
        },
        {
          title: "Decrease opacity",
          icon: "chevron-down",
          id: "decrease-opacity"
        }
      ]
    ];
  }
}

 

In this case when user clicks toggle controls, i want to enable/disable the controls in layer list.

However this approach doesn't seem to work as it seems to render the controls once off and moves on.

Is there a way to dynamically toggle controls when enableControl value changes effectively?

0 Kudos
1 Solution

Accepted Solutions
Aeseir
by
Frequent Contributor

Solved it, by using a empty function

View solution in original post

0 Kudos
1 Reply
Aeseir
by
Frequent Contributor

Solved it, by using a empty function

0 Kudos