AnsweredAssumed Answered

How do I add an Action Section to a whole LayerList Widget?

Question asked by gsalvador0 on Aug 11, 2017
Latest reply on Aug 15, 2017 by gsalvador0

Howdy all,


An easy question for the pros:

In the "LayerList widget with actions" sample code ( the code gives some actions to a layer. I've modified that example to add a "save" button that writes a cookie with the currently visible layers, so I can reload the page and have my new default layers be visible. However, when I add more layers, the save button shows up on each layer and each sublayer. I was looking for a way to have the save button appear once, but I don't really want it as part of any specific layer. Is there a way to do this?  


This is what I have so far:

//LayerListWidget initialization

var layerList = new LayerList({

view: view,

listItemCreatedFunction: onLayerWidgetStartup


function onLayerWidgetStartup(event) {

var item = event.item;

  item.actionsSections = [[{

  title: "Save Layer visibility",

  className: "esri-icon-save"



//rest of stuff to write cookies


Since I'm calling onLayerWidgetStartup for each listItem, I get a Save Layer button on each.