HOW TO
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.
Warning:
Layer names are case sensitive.
Code:
var hideArray = new Array();
hideArray[0] = "STATES";
hideArray[1] = "canada";
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';
}
}
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();
}
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;
}
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';
}
}
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;
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();
}
}
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;
}
Article ID:000002262
Get help from ArcGIS experts
Download the Esri Support App