IrfanClemson
IrfanClemson

Reputation: 1779

ESRI Javascript API: Looping to Build a Layer Selection Menu

For reference, please see this: https://developers.arcgis.com/javascript/jssamples/map_dynamiclayerlist.html

But, unlike the ESRI example, I am loading several different Services and each Service has multiple Layers. So I have modified the ESRI code per the following:

var visible = [];
function buildLayerList() {           
   arrayUtils.forEach(map.layerIds, function (id) {
     var currLayer = map.getLayer(id); 
     var items = arrayUtils.map(currLayer.layerInfos, function (info, index) {
        if (info.defaultVisibility) {
                      visible.push(info.id);
        }
        return "<input type='checkbox' class='list_item'" + (info.defaultVisibility ? "checked=checked" : "") + "' id='" + info.id + "'' /><label for='" + info.id + "'>" + info.name + "</label>";
       });
  });
     //more code per ESRI
}

But, in my case, the items variable is not getting any values; it is returning as null or not defined. I presume that is because I have basically two loops, unlike ESRI's.

So how do I fix it? I would hate to hard-code the layer selection menu option but may have to if I cant figure this out.

Note: These are all Arcgis Dynamic Layers.

Thanks!

Upvotes: 0

Views: 359

Answers (1)

IrfanClemson
IrfanClemson

Reputation: 1779

Never mind: All I needed was a Esri Javascript API's 'TOC Widget'; I downloaded that and implemented in my code. Much easier than trying to re-invent the wheel. Thanks--especially to @Pointy.

Upvotes: 0

Related Questions