AnsweredAssumed Answered

Cannot get layers to populate layer list

Question asked by inteller on Jul 30, 2015
Latest reply on Aug 4, 2015 by inteller

When I add the map service in I can get a list of layers that are able to be turned on and off.


When I add the same service to my javascript viewer (template viewer) I only get one layer which is the service name.  From what I can tell it looks like I should be getting a list of layers that can be toggled on and off as well:


function addLayerList(layers) {     var layerList = buildLayerVisibleList(layers);     if (layerList.length > 0) {         //create a menu of layers         layerList.reverse();         var menu = new dijit.Menu({             id: 'layerMenu',             baseClass: "customMenu"         });         dojo.forEach(layerList, function (layer) {             menu.addChild(new dijit.CheckedMenuItem({                 label: layer.title,                 checked: layer.visible,                 onChange: function () {                     if (layer.layer.featureCollection) {                         //turn off all the layers in the feature collection even                         //though only the  main layer is listed in the layer list                         dojo.forEach(layer.layer.featureCollection.layers, function (layer) {                             layer.layerObject.setVisibility(!layer.layerObject.visible);                         });                     } else {                         layer.layer.setVisibility(!layer.layer.visible);                     }                 }             }));         });         var button = new dijit.form.DropDownButton({             label:,             id: "layerBtn",             iconClass: "esriLayerIcon",             title:,             dropDown: menu         });         dojo.byId('webmap-toolbar-center').appendChild(button.domNode);     } } //build a list of layers for the toggle layer list - this list //is slightly different than the legend because we don't want to list lines,points,areas etc for each //feature collection type. function buildLayerVisibleList(layers) {     var layerInfos = [];     dojo.forEach(layers, function (mapLayer, index) {         if (mapLayer.featureCollection && !mapLayer.layerObject) {             if (mapLayer.featureCollection.layers) {                 //add the first layer in the layer collection... not all  - when we turn off the layers we'll                 //turn them all off                 if (mapLayer.featureCollection.layers) {                     layerInfos.push({                         "layer": mapLayer,                         "visible": mapLayer.visibility,                         "title": mapLayer.title                     });                 }             }         } else if (mapLayer.layerObject) {             layerInfos.push({                 layer: mapLayer.layerObject,                 visible: mapLayer.layerObject.visible,                 title: mapLayer.title             });         }     }); return layerInfos; }