In case you want to exclude a layer not to show up, on the LayerList then you probably don't want it appear in the Legend and Attribute Table either.
LayerList Widget
The LayerList widget through the Settings provides a way to exclude layers to be listed in the Layer List. However, if you add a layer programmatically, the layer is not listed in the Settings.
You can exclude a layer by accessing the LayerListView.js under the LayerList widget folder under the addLayerNode function and add this simple script. In this script, a layer with the text "Outside" in the title of the layer will be excluded. You can use any other layerinfo property to specify which layer to exclude.
Under the the LayerListView.js
drawListNode: function(layerInfo, level, toTableNode, position) {
var nodeAndSubNode, showLegendDiv;
if(this.isLayerHiddenInWidget(layerInfo) || layerInfo.title.includes("Outside")) {
return;
}
---------------------
---------------------
Attribute Table Widget
Under the widget.js there are two places to modify the script.
Under the initDiv function (add line 8 and line 12)
-------------
-------------
paneJson.paneId = json.id;
paneJson.title = json.name;
paneJson.name = json.name;
paneJson.layerType = this._layerTypes.FEATURELAYER;
paneJson.style = "height: 100%; width: 100%; overflow: visible;";
if (!paneJson.name.includes("Outside")) {
var cp = new ContentPane(paneJson);
this.layerTabPages[j] = cp;
this.tabContainer.addChild(cp);
}
}
}
----------------
----------------
Under the onReceiveData function add lines 6 and 26
-------------------------
-------------------------
params.layer = params.layer || params.layerInfo;
console.log(params)
if (!params.layer.title.includes("Outside")) {
if (!this.showing) {
this._openTable().then(lang.hitch(this, function () {
var isInResources = !!this._resourceManager.getLayerInfoById(params.layer.id);
if (!isInResources) {
this._resourceManager.updateLayerInfoResources(false)
.then(lang.hitch(this, function () {
this._addLayerToTable(params);
}));
} else {
this._addLayerToTable(params);
}
}));
} else {
this._resourceManager.updateLayerInfoResources(false)
.then(lang.hitch(this, function () {
this._addLayerToTable(params);
}));
}
}
}
----------------------------
--------------------------
Legend Widget
Thanks to Robert Scheitlin's solution at:
How to remove a layer from the Legend widget in Developer Addition Web App Builder? We are programma...
I was able to remove from Legend widget as well with a slight modification, probably because it is a different WAB version and the widget code has been modified.
Added lines 14-21 and comment out line 23. The other lines were already comment out by ESRI. I am using WAB version 2.8.
_getLayerInfosParam: function() {
var layerInfosParam;
layerInfosParam = legendUtils.getLayerInfosParam(this.config);
filteredLayerInfosParam = layerInfosParam.filter(function(layerInfoParam) {
if(!layerInfoParam.title.includes("Outside")){
console.log(layerInfoParam)
return layerInfoParam;
}
});
return filteredLayerInfosParam;
},