HOW TO
Instructions provided describe the process of adding a tool to an ArcIMS HTML Viewer to accomplish the functionality described below.
Projected data can be served while allowing a user to click on the map and display geographic coordinates. Implementing an ArcXML request into the application accomplishes this. This ArcXML GET_IMAGE request will return an envelope in geographic coordinates. These values are extracted from the response and the center point of this envelope is calculated and displayed in a Javascript pop-up window.
Note: While this article addresses the steps for adding specific functionality into the HTML Viewer, the same principles and approach can be used to project or unproject any set of x,y values, using any of the ArcIMS connectors.
Warning: In the upcoming steps specified code from this document will be inserted into the .htm and .js files. It is not recommended that this document be copied due to extra formatting characters that also are added to the code when copying.
var useExtract=false;After this line, insert the following code:
var useUnprojectPt=true;This will allow you to easily remove the tool from the application in the future. Setting the value to false will prevent the tool from displaying in the toolbar.
if (parent.MapFrame.useIdentifyAll) document.identifyall.src="images/identifyall_1.gif";After this line and before the squiggly bracket that closes the revertToolPic function, insert the following line of code:
if (parent.MapFrame.useUnprojectPt) document.unproject.src="images/xy_1.gif";In the next function, setToolPic, find the following block of code:
} else if (functName=="Identify All") { document.identifyall.src="images/identifyall_2.gif"; }After this block of code (on the same line as the above block's closing squiggly bracket), and before the squiggly bracket that closes the function, insert the following line of code:
else if (functName=="unproject") { document.unproject.src="images/xy_2.gif"; }Now locate the following block of code:
if (parent.MapFrame.allowOptions) { // Options. . . requiers aimsOptions.js... allowOptions is set to true in this file document.write('<td align="center" valign="middle">'); document.write('<img src="images/wrench.gif" width=16 height=16 hspace=1 vspace=1 border=0 alt=" ' + t.buttonList[40] + '" onmousedown="parent.MapFrame.writeOptionForm();" onmouseover="window.status=\' ' + t.buttonList[40] + '\'">'); isSecond = !isSecond document.writeln('</td>'); if (isSecond) document.write('</tr><tr>'); }Before the next if statement, add the following block of code:
if (parent.MapFrame.useUnprojectPt) { // Unproject point. . . requiers aimsCustom.js document.write('<td align="center" valign="middle">'); document.write('<img src="images/xy_1.gif" width=16 height=16 hspace=1 vspace=1 border=0 alt=\'Return Decimal Degrees\' name="unproject" onmousedown="parent.MapFrame.clickFunction(\'unproject\'); setToolPic(\'unproject\');" onmouseover="window.status=\'Return Decimal Degrees\'">'); isSecond = !isSecond document.writeln('</td>'); if (isSecond) document.write('</tr><tr>'); }Save and close the file.
Note: When saving the file remember to name the file as described above, preserving case sensitivity as well.
function clickFunction (toolName) { if (hasLayer("measureBox")) hideLayer("measureBox"); switch(toolName) {Below this block of code insert the following block of code:
case "unproject": toolMode = 1001; if (isIE) { document.all.theTop.style.cursor = "crosshair"; theCursor = document.all.theTop.style.cursor; } modeBlurb = "Return decimal degrees"; break;Save and close the file.
unprojectPoint(e); return false;In the useCustomFunction function's "if" statement that checks if XMLMode==1001, insert the following line of code:
extractPtVal(theReply);At the very end of this file, add the following two functions:
function unprojectPoint(e) { //send a request that will return unprojected coordinates getImageXY(e); getMapXY(mouseX,mouseY); var theString = '<ARCXML VERSION="1.0.1">\n<REQUEST>\n<GET_IMAGE>\n<PROPERTIES>\n'; theString += '<ENVELOPE minx="' + (mapX-5) + '" miny="' + (mapY-5) + '" maxx="' + (mapX+5) + '" maxy="' + (mapY+5) + '" />\n'; theString += '<IMAGESIZE height="1" width="1" />\n'; theString += '<LAYERLIST >\n'; for (var i=0;i<layerCount;i++) { theString += '<LAYERDEF id="' + LayerID[i] + '" visible="false" />\n'; } theString += '</LAYERLIST>\n'; // FILTERCOORDSYS is the id of the ArcIMS service's output coordinate system. // FEATURECOORDSYS is the id of the desired coordinate system of the resulting coordinates. theString += '<FILTERCOORDSYS id="54030" />\n<FEATURECOORDSYS id="4326" />\n'; theString += '</PROPERTIES>\n</GET_IMAGE>\n</REQUEST>\n</ARCXML>'; //alert(theString); sendToServer(imsURL,theString,1001); //XMLmode for unproject xy is 1001 return false; }
function extractPtVal(theReply) { var theXYs = getEnvelopeXYs(theReply, 0) var limitLeft = theXYs[0]; var limitBottom = theXYs[1]; var limitRight = theXYs[2]; var limitTop = theXYs[3]; var theX = (limitLeft + limitRight)/2; var theY = (limitBottom + limitTop)/2; alert("X: " + theX + "\n" + "Y: " + theY); }
Note: The unprojectPoint function creates an ArcXML request that returns projected coordinates. Remember to change this request's FILTERCOORDSYS id to that of the ArcIMS service's output coordinate system, and the FEATURECOORDYS id to whatever coordinate system values to be returned.
Get help from ArcGIS experts
Download the Esri Support App