HOW TO

Hide layers in the HTML Viewer legend

Last Published: April 25, 2020

Summary

Data layers can be hidden in the legend for the HTML Viewer by editing two files in the HTML Viewer web site. NOTE: the edits will cause the Legend not to automatically refresh to show/hide scale-dependent layers. To refresh the legend, click the Legend/LayerList button in the Viewer's toolbar.Warning! The edits described in the steps below are complex. Code examples are given for illustration only. Take care to avoid syntax errors.

Procedure



  1. Open the ArcIMSParams.js file in a text editor such as WordPad. This file is created by ArcIMS Designer and placed in the HTML directory under your WebSite directory.
  2. At the end of the code in the ArcIMSParams.js file, create a new array object and add to it the names of layers you want to hide. Check your MapService's AXL file to determine what the layer names are.
    Warning:
    Layer names are case sensitive.

    For example:

    Code:
    var hideArray = new Array();
    hideArray[0] = "STATES";
    hideArray[1] = "canada";

  3. Save and close the ArcIMSParams.js file.
  4. Open the aimsXML.js file in a text editor such as WordPad. This file is also created by ArcIMS Designer and placed in the \javascript directory of the website.
  5. Find the writeXML function. Assuming the code has not already been edited, the beginning of the function will look like this:

    Code:
    // prepare the request in xml format for Main Map
    function writeXML() {
    var theString = '<ARCXML VERSION="1.0.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<ENVELOPE minx="' + left + '" miny="' + bottom + '" maxx="' + right + '" maxy="' + top + '" />\n';
    theString += '<IMAGESIZE height="' + iHeight + '" width="' + iWidth + '" />\n';
    var visString = "";
    if (aimsLayersPresent) {
    // tell the server which layers are to be visible
    if (toggleVisible) {
    theString += '<LAYERLIST >\n';
    for (var i=0;i<layerCount;i++) {
    if (LayerVisible[i]==1) {
    theString += '<LAYERDEF id="' + LayerID[i] + '" visible="true" ';
    if (aimsClassRenderPresent) {
    theString += addSpecialRenderToMap(i);
    }
    else {
    theString += '/>\n';
    }
    }
    else {
    theString += '<LAYERDEF id="' + LayerID[i] + '" visible="false" />\n';
    }
    }
    theString += '</LAYERLIST>\n';
    }
    }

  6. In the writeXML function, find the code that adds the Legend to the request. Cut and Paste (do not just Copy) this section of code into a location near the top of the writeXML function, but after the <PROPERTIES> tag has been opened. When done, the beginning of the function should look like this:

    Code:
    function writeXML() {
    var theString = '<ARCXML VERSION="1.0.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n<ENVELOPE minx="' + left + '" miny="' + bottom + '" maxx="' + right + '" maxy="' + top + '" />\n';
    theString += '<IMAGESIZE height="' + iHeight + '" width="' + iWidth + '" />\n';
    var visString = "";

    //### Step 6
    // Moved from below
    if (aimsLegendPresent) {
    // create a legend image
    if (legendVisible) theString += addLegendToMap();
    }

  7. Just below the function just moved, add code to determine if the map will be redrawn. One way to determine if the map will be redrawn is by checking to see if the <DRAW> tag is present in the Request string, for example:

    Code:
    //### Step 6
    // Moved from below
    if (aimsLegendPresent) {
    // create a legend image
    if (legendVisible) theString += addLegendToMap();
    }

    //### Step 7
    //determine if map is to be redrawn
    var mapBeingRedrawn = true;
    var posLastTag = theString.lastIndexOf('<');
    if (theString.substring(posLastTag + 1, posLastTag + 5) == "DRAW") {
    var posDrawBool = theString.charAt(posLastTag + 11);
    if (posDrawBool == "f") mapBeingRedrawn = false;
    }

  8. The next section of code in the writeXML function adds layers to the Request. This section of code requires the following modifications:

    a) Add a line of code to join hideArray to a variable.
    b) Check to see whether the layer being added should be visible or not.

    Code:
    //### Step 7
    //determine if map is to be redrawn
    var mapBeingRedrawn = true;
    var posLastTag = theString.lastIndexOf('<');
    if (theString.substring(posLastTag + 1, posLastTag + 5) == "DRAW") {
    var posDrawBool = theString.charAt(posLastTag + 11);
    if (posDrawBool == "f") mapBeingRedrawn = false;
    }

    //### Step 8.a
    var hideStr = hideArray.join();
    //### end Step 8.a
    if (aimsLayersPresent) {
    // tell the server which layers are to be visible
    if (toggleVisible) {
    theString += '<LAYERLIST >\n';
    for (var i=0;i<layerCount;i++) {
    if (LayerVisible[i]==1) {

    //### Step 8.b
    if ((hideStr.search(LayerName[i]) != -1) && (legendVisible) && (mapBeingRedrawn == false)) {
    theString += '<LAYERDEF id="' + LayerID[i] + '" visible="false" ';
    theString += '/>\n';
    }
    else {
    theString += '<LAYERDEF id="' + LayerID[i] + '" visible="true" ';
    if (aimsClassRenderPresent) {
    theString += addSpecialRenderToMap(i);
    }
    else {
    theString += '/>\n';
    }
    }

    //### end Step 8.b
    }
    else {
    theString += '<LAYERDEF id="' + LayerID[i] + '" visible="false" />\n';
    }
    }
    theString += '</LAYERLIST>\n';
    }
    }

  9. Still in aimsXML.js, find the getXYs() function, and add the single line of code shown below to the very beginning of the function:

    Code:
    // get the map extents from xml reply
    function getXYs(theString) {

    //### Step 9
    // Prevent legend from changing as a result of pan/zoom
    hasTOC = false;

    var tempStr = "";
    var smallStr = "";
    var startpos = 0;

  10. Save and close the aimsXML.js file. Find and open aimsLegend.js in WordPad. This file is located in the same directory as the aimsXML.js file.
  11. In the showLegend function, comment out or delete the entire else{} portion of the if (hasTOC) statement. If you choose to delete the specified code, the result will look like this:

    Code:
    // write out the legend display
    function showLegend() {

    if (hasTOC) {
    parent.TOCFrame.document.open();
    parent.TOCFrame.document.writeln('<html><head><title>Legend</title>');
    parent.TOCFrame.document.writeln('<style type="text/css">a {text-decoration:none;}</style>');
    parent.TOCFrame.document.writeln('</head>');
    parent.TOCFrame.document.writeln('<body BGCOLOR="White" text="Black" leftmargin=0 topmargin=0 rightmargin=0 link="Black" vlink="Black" alink="Black">');
    parent.TOCFrame.document.writeln('<center>');
    parent.TOCFrame.document.writeln('<IMG SRC="' + legendImage + '" HSPACE=0 VSPACE=0 BORDER=0 ALT="Legend"></center>');

    parent.TOCFrame.document.writeln('</body></html>');
    parent.TOCFrame.document.close();
    }
    }

  12. Finally, locate the addLegendToMap() function and modify it as follows:

    Code:
    // add Legend to XML request
    function addLegendToMap() {
    // MOD Jason Hine 10/17/00 - to keep legend from redrawing with hidden layers
    var legString = '<LEGEND title="' + legTitle + '" font="' + legFont + '" width="' + legWidth + '" height="' + legHeight + '" ';
    legString += 'autoextend="true" backgroundcolor="255,255,255" />\n';
    if (drawLegendOnly) legString = legString + '<DRAW map="false" />\n';
    //### Step 12 - Prevent Legend from going to window
    hasTOC=true;

    return legString;
    }

  13. Save and close the aimsLegend.js file.
  14. The HTML Viewer Web site will need to be fully refreshed before the changes will take effect. In Internet Explorer, press Ctrl-F5. In Netscape, click the Reload button.

Article ID:000002262

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic