It is through a customized widget that I customized from the Addlayer widget (AddLayer Widget ). The original widget is used to add one layer when a check box is checked. It works with the layerlist which expands the layer node. What I have customized is to add a dijit/form/Select above the layer list in the widget.html. When the value changes in the select, a few map services are added to the map. The map services are added to the map in a loop. I have also noticed that Web AppBuilder build-in Legend widget only display the legend for the layer which is expandable in the layerlist widget.
Here is the code which load a few map services. addLayerToMap is reused from the original code. Themelayers is the array of IDs for map services which will be loaded in the map.
array.forEach(this.config.layers, function (layer) {
if (themeLayers.indexOf(layer.name) != -1) //find the fire
{
//1. Check box checked
var cb = registry.byId(layer.name);
cb.setValue(true);
//2. Load layer to map
this.addLayerToMap(layer);
}
}, this);
The screenshot below shows when Planning is selected, map services "Other Info", "Small CellInfo", "Trans Plan Info" are loaded to the map.