HOW TO
Instructions provided are for hiding the layers from the layerlist so that the specific layers will be hidden from either the legend or the TOC only. On page 16 of the "Customizing HTML Viewer" document, there is a description about hiding the layers from both the TOC and legend.
Note:
This article is applicable only when using HTML Viewer with Image Service. ArcMap Service doesn't allow hiding layers from the Legend.
Code:
// Toggle the check of nonlisting of layers in LayerList and Legend.
// If true, noListLayer array must have an element defined for each layer.
var hideLayersFromList=false;
// Layers that will be listed in the LayerList or Legend
// Note: This does not affect the map display.
var noListLayer = new Array();
// noListLayer[0] = true;
// noListLayer[1] = true;
// noListLayer[2] = false;
// noListLayer[3] = true; // This one will not be listed.
// noListLayer[4] = false;
var hideLayersFromLegend=true;
// Layers that will be listed in the LayerList or Legend
// Note: This does not affect the map display.
var noLegendLayer = new Array();
noLegendLayer[0] = true;
noLegendLayer[1] = false;
Code:
// Add Legend to the XML request.
function addLegendToMap() {
var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
legString += 'autoextend="true" backgroundcolor="255,255,255"';
if (hideLayersFromLegend) {
legString += '>\n<LAYERS>\n';
for (var legvar=0;legvar<noLegendLayer.length;legvar++) {
if (noLegendLayer[legvar]) legString += '<LAYER id="' + LayerID[legvar] + '" />\n';
}
legString += '</LAYERS>\n';
legString += '</LEGEND>\n';
} else {
legString += ' />\n';
}
if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
return legString;
}
Article ID:000006334
Get help from ArcGIS experts
Download the Esri Support App