Solved! Go to Solution.
require([ "esri/map", "esri/layers/FeatureLayer", "esri/dijit/Legend","esri/dijit/BasemapGallery", "esri/arcgis/utils", "dojo/_base/array", "dojo/parser", "esri/dijit/LocateButton", "esri/dijit/HomeButton", "esri/dijit/OverviewMap", "esri/layers/ArcGISDynamicMapServiceLayer", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/TitlePane","dijit/layout/AccordionContainer", "dojo/domReady!" ], function( Map, FeatureLayer, Legend,BasemapGallery, arcgisUtils, arrayUtils, parser , LocateButton, HomeButton, OverviewMap, ArcGISDynamicMapServiceLayer )
I have a similar question to all of this. i have several table of contents that are grouped by types of data. The client wants a separate legend that they can open and see a list of layers that are checked in the other TOCs and be able to check the layers in the new TOC for identifying. Here is a screenshot of what i have so far:
The bottom left is the new TOC that i want to just list visible layers that are turned on elsewhere. Thanks!
p.s. i know its redundant but that's what they want!
        
         map.on("layers-add-result", function (evt) {
                         buildLayerList(evt)
                     });
                     function buildLayerList(evt) {
                         array.forEach(evt.layers, function (layer) {
                             var vis = [];
                             visible.push(vis);
                             buildCheckboxes(layer);
                         });
                     }
                     function buildCheckboxes(layer) {
                         array.forEach(layer.layer.layerInfos, function (info, index) {
                             var checkBox = new CheckBox({
                                 name: "checkBox" + layer.layer.id + info.id,
                                 value: layer.layer.id + "_" + info.id,
                                 checked: info.defaultVisibility,
                                 onChange: function (evt) {
                                     var thisArray = this.value.split("_")
                                     var layerID = thisArray[0];
                                     var infoID = parseInt(thisArray[1]);
                                     var clayer = map.getLayer(thisArray[0]);
                                     var visArray = clayer.visibleLayers;
                                     var ind = visArray.indexOf(infoID);
                                     if (ind > -1) {
                                         visArray.splice(ind, 1);
                                     }
                                     else {
                                         visArray.push(infoID);
                                     }
                                     if (visArray.length == 0) { visArray.push(-1);}
                                     clayer.setVisibleLayers(visArray);
                                 }
                             });
layers = dojo.queryToObject(URLparams).layers;
layerList = (layers) ? layers.split(',') : [];
for (a in layerList ) {
 layerList = parseInt(layerList);
}
 if (layer.loaded) {
  buildLayerList(layer);
 } else {
  dojo.connect(layer, "onLoad", buildLayerList);
 }
