English

How To: Hide the layers from the legend but not from the TOC in HTML Viewer

Summary

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.

Procedure

This article requires editing the ArcIMSParam.js file usually located in the ArcIMS/Website/<Website_Name> folder and the aimsLegend.js file in the ArcIMS/Website/<Website_Name>/JavaScript folder.

  1. Set the hideLayersFromList variable to true and define noListLayer array as explained on page 16 of the "Customizing HTML Viewer" document if hiding the layers from the TOC is desired.
  2. In the ArcIMSParam.js file, define a new variable hideLayersFromLegend and set it to true. Also, create a new array noLegendLayer with the topmost layer having index 0. Set these variables to true if the layer should be hidden and false if it should be shown. In the following example, there are two layers. The top layer is hidden from the legend, while the bottom layer is be shown.

    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;

  3. In the aimsLegend.js file, find the function addLegendToMap(). Change it as follows:

    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;
    }

Related Information