I have my layers that I load up during the initial start up of my map that you can see below. However, I have a layer that I add in later like this:
StoresResultsLayer.setVisibleLayers([3, 4]);
map.addLayer(StoresResultsLayer);
I would like this to show up in my table of contents but I would also like to allow the user the ability to turn the individual layers on and off as well. I'm going to have one be my results for my layer and the other will be labeling for those layers. How can I do this?
Below is my code on startup for the TOC
map.on("layers-add-result", function (results) {
var toc = new TOC({
map: map,
layerInfos: [{
layer: dlDRegionDistrictPolygons,
title: "Boundary Files",
collapsed: true,
showGroupCount: false,
slider: true
},{
layer: dlMCY_Stores,
title: "Macys Stores",
collapsed: true
}
]
}, 'sliderDiv');
toc.startup();
toc.on('toc-node-checked', function (evt) {
// When dlMCY_Stores is turned off I want flMCY_Stores_Labels to turn off as well and vice versa.
if(dlMCY_Stores.visible == true){
//Show feature layer Labels because dynamic layers allow for infotemplate
flMCY_Stores_Labels.show();
}
else{
//Hide Labels
flMCY_Stores_Labels.hide();
}
} );
});
map.addLayers([dlDRegionDistrictPolygons,flMCY_Stores_Labels,dlMCY_Stores,flDistricts,flRegions]);