AnsweredAssumed Answered

How do I add multiple layers to the LayerList?

Question asked by gsalvador0 on Aug 24, 2017
Latest reply on Aug 25, 2017 by rscheitlin

Hi all,

 

I would like to add multiple layers to the LayerList dijit (using 3.21). I tried to add each layer to an array as it was added to the map and then reference the array when making the LayerList, but this left out all of the sublayers. here is my code:

var layerArray = new Array();
var tempLayer = new ArcGISDynamicMapServiceLayer(
"https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer");
layerArray.push(map.addLayer(tempLayer));

.....repeated with different layers.......

//layerlist widget initialization
var layerListWidget = new LayerList({
map: map,
layers: layerArray
}, "layerList");
layerListWidget.startup();

 

Is there a way to add all of the layers (and sublayers) to the layerList Dijit programmatically?

Outcomes