English

How To: Automate the process of zooming into the first returned geocoded result (HTML Viewer)

Summary

You can have the Locate Address tool automatically zoom in to the first returned geocoded result by doing a few simple edits to your HTML Viewer's aimsGeocode.js file, as described below. The first result will always be the result with the highest score. This article also illustrates how to zoom in on the geocode result only if one result is returned.

Procedure

  1. Open the HTML Viewer's aimsGeocode.js file in a text editor.

  2. Find the following block of code at the very end of the file:

    Code:
    if (GCpointCount==1) sendMapXML();
    //if (GCpointCount==1) zoomToPoint(GCpointX[0], GCpointY[0], true, geocodeLabel);


    Note:
    This should take you to the bottom of the parseGeocodeResults function, which is responsible for parsing the ArcXML geocode response from the spatial server.

  3. Replace the above block of code with the following:

    Code:
    //if (GCpointCount==1) sendMapXML();
    var gcptx = parseFloat(GCpointX[0]);
    var gcpty = parseFloat(GCpointY[0]);
    //if (GCpointCount==1) zoomToPoint(gcptx, gcpty, true, geocodeLabel);
    zoomToPoint(gcptx, gcpty, true, geocodeLabel);


    Note:
    This will result in the map automatically zooming to the first geocode result returned. The zoomToPoint function is already set up to do this.

  4. Comment out the following blocks if you want to zoom only when one result is returned:

    Code:
    if (GCpointCount==1) zoomToPoint(gcptx, gcpty, true, geocodeLabel);


    Code:
    zoomToPoint(gcptx, gcpty, true, geocodeLabel);


    Note:
    Two forward slashes (//) are the comment characters in Java Script.

  5. Save the file.
  6. Quit and restart your browser.

Related Information