This is a great enhancement, I do have a problem though, I was able to get some layers to be excluded but others wont work. Here is a snippet from the config file:
<excludelayerfromlegend>Internal Webmap/0</excludelayerfromlegend>
<excludelayerfromlegend>Internal Webmap/1</excludelayerfromlegend>
<excludelayerfromlegend>Internal Webmap/5</excludelayerfromlegend>
<excludelayerfromlegend>Internal Webmap/12</excludelayerfromlegend>
<excludelayerfromlegend>Internal Webmap/30</excludelayerfromlegend>
<excludelayerfromlegend>Internal Webmap/50</excludelayerfromlegend>
<excludelayerfromlegend>Internal Webmap/51</excludelayerfromlegend>
<excludelayerfromlegend>Internal Webmap/52</excludelayerfromlegend>
Layers 12-32 are all under the group Parcels in my mxd. So Layer id 12 is that layer. When I tried to do layer id 30, it didn't actually remove the layer from the legend, so I added 12 and of course that did eliminate 30 but I didn't really want to remove everything under 12. Does that make any sense? An excerpt from my REST Services Directory is below. Layers 13-28 are all annotation layers.
[ATTACH=CONFIG]23560[/ATTACH]
private function getLegendOptions():LegendOptions { var result:LegendOptions = new LegendOptions(); var legendLayers:Array = []; for each (var layer:Layer in hostBaseWidget.map.layers) { if (layer.name.indexOf("hiddenLayer_") == -1 && !(layer is GraphicsLayer && !(layer is FeatureLayer))) { var isBaseMapLayer:Boolean = false; for each (var baseMapLayer:Object in hostBaseWidget.configData.basemaps) { if (baseMapLayer.label == layer.id) { isBaseMapLayer = true; break; } } if (!isBaseMapLayer) { // filter the layer through the list of names of excluded layers. var isExcludedLayer:Boolean = false; var excludedSublayers:Array = []; for each (var excludeName:String in excludeLayersFromLegend) { if (excludeName == layer.id) { isExcludedLayer = true; break; } else { const index:int = excludeName.indexOf("/"); if (index != -1) { const layerName:String = excludeName.substring(0, index); const sublayerId:Number = Number(excludeName.substring(index + 1)); if (layerName == layer.id) { excludedSublayers.push(sublayerId); } } } } if (!isExcludedLayer) { var legendLayer:LegendLayer = new LegendLayer(); legendLayer.layerId = layer.id; if ((layer is ArcGISDynamicMapServiceLayer || layer is ArcGISTiledMapServiceLayer) && excludedSublayers.length) { var includedSublayers:Array = []; const layerInfos:Array = layer is ArcGISDynamicMapServiceLayer ? ArcGISDynamicMapServiceLayer(layer).layerInfos : ArcGISTiledMapServiceLayer(layer).layerInfos; for each (var layerInfo:LayerInfo in layerInfos) { if (excludedSublayers.indexOf(layerInfo.layerId) == -1) { includedSublayers.push(layerInfo.layerId); } } legendLayer.subLayerIds = includedSublayers; } legendLayers.push(legendLayer); } } } } result.legendLayers = legendLayers; return result; }