AnsweredAssumed Answered

Drawing Line Measurement Not Matching Buffer Distance

Question asked by csergent08 Champion on Sep 11, 2014
Latest reply on Oct 8, 2014 by ddemone

I need a line measurement to match my buffer distance. The code modifications should related to this article: Measuring distances and areas when your map uses the Mercator projection | ArcGIS Blog

 

Currently I have a buffer that uses a WKID of 4326 which appears to draw correctly with a measured buffer of 500 feet. The rest of the application uses a WKID 102100 which allows the application to display correctly, but the line tool is coming up with a measurement of about 150 feet more than the buffer. I have changed each 102100 one at a time even ones I did not think I should as I need this app to work in testing. Any idea where I am going wrong with my code so that my measurements work?

 

Here is my code:

/// <reference path="scriptaculous.js" />

/// <reference path="dragdrop.js" />

/// <reference path="effects.js" />

/// <reference path="rico.js" />

/// <reference path="ricoStyles.js" />

/// <reference path="ricoCommon.js" />

/// <reference path="ricoEffects.js" />

 

 

 

 

// Using Intellisense For The Above

// http: //msdn.microsoft.com/en-us/library/bb385682.aspx

 

 

////////// AUTHOR & APPLICATION INFORMATION ////////////////////////////////////////

//

//   Author: Chris Sergent

//   Date:   May 1, 2012

//   Application: SOA

//

////////////////////////////////////////////////////////////////////////////////////

 

 

// Address Points - Layer 0

// Bike Paths - Red Line - Layer 1

// Inhome Daycares - Dark Blue - Layer 2

// Daycare Facilities - Light Blue - Layer 3

// Playgrounds - Purple - Layer 4

// School Property - Green - Layer 5

// Macon Co. Tax Parcels - Layer 6

// Decatur Corporate Boundary - Layer 7

 

 

////////////////////////////////////////////////////////////////////////////////////

//

//              DECLARE AND SET VARIABLES BEGIN

//

////////////////////////////////////////////////////////////////////////////////////

 

 

 

 

////////////////////////////////////////////////////////////////////////////////////

//

//              SET UP DOJO BEGIN

//

////////////////////////////////////////////////////////////////////////////////////

/*

Dojo Framework Require Begin

*/

 

 

dojo.require("dojo.parser");

dojo.require("dojo.number");

 

 

/*

 

 

Parsing dojo.number include four functions

- dojo.number.format() - formats numeric values

- dojo.number.parse() - converts a string to a number

- dojo.number.regexp() - returns a regular expression

- dojo.number.round() - rounds numbers

   

*/

 

 

dojo.require("dojo.data.ItemFileReadStore");

dojo.require("dojo.fx");

 

 

dojo.require("dijit.dijit");

dojo.require("dijit.form.Button");

dojo.require("dijit.Toolbar");

dojo.require("dijit.TitlePane");

dojo.require("dijit.layout.BorderContainer");

dojo.require("dijit.layout.ContentPane");

dojo.require("dijit.Editor");

dojo.require("dijit.layout.TabContainer");

 

 

dojo.require("dojox.grid.DataGrid");

 

 

// Declare Rounding Corners With Rico

var roundCorners = Rico.Corner.round.bind(Rico.Corner);

 

 

/*

Dojo Framework Require End

*/

 

 

//-----------------------------------------------------------

// REST API - Making Tools Available

//-----------------------------------------------------------

 

 

// ESRI dojo objects

// allows you to work with the dynamic map service resource exposed by the ArcGIS REST API.

// Reference: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/arcgisdynamicmapservicelayer.htm#

dojo.require("esri.layers.agsdynamic"); // dynamic map services generate images on the fly.

dojo.require("esri.layers.agstiled"); // cached map service.

 

 

 

 

// esri.Map class created a container and required DOM structure for adding

// -layers, graphics, info_window, and other navigation controls

dojo.require("esri.map");

dojo.require("esri.toolbars.navigation");

dojo.require("esri.toolbars.draw");

 

 

 

 

// ESRI dojo tasks

//  esri.tasks.geometry class represents a geometry service exposed by the ArcGIS REST API.

// Operations include - project, simplify, buffer, and relationships

// Reference: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/geometry.htm#

dojo.require("esri.tasks.geometry");

 

 

// Represents a geocode service resource exposed by the ArcGIS REST API.

// It is used to generate candidates for an address.

// It is also used to find an address for a given location.

// Reference: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/locator.htm#

dojo.require("esri.tasks.locator");

 

 

// ESRI dojo task for querying against the ArcGIS REST API.

// Reference: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/querytask.htm#

dojo.require("esri.tasks.query");

 

 

 

 

// ESRI dojo task for identifying against the ArcGIS REST API.

dojo.require("esri.tasks.identify");

 

 

 

 

// ESRI dojo graphics utility for displaying features in a single layer using the ArcGIS REST API.

// Reference:http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/featurelayer.htm#

dojo.require("esri.layers.FeatureLayer");

 

 

 

 

 

 

/*

ESRI Dojo Objects End

*/

 

 

 

 

////////////////////////////////////////////////////////////////////////////////////

//

//              SET UP DOJO END

//

////////////////////////////////////////////////////////////////////////////////////

 

 

////////////////////////////////////////////////////////////////////////////////////

//

//              DECLARE AND SET VARIABLES END

//

////////////////////////////////////////////////////////////////////////////////////

 

 

////////////////////////////////////////////////////////////////////////////////////

//

//          MAP EXTENTS

//

////////////////////////////////////////////////////////////////////////////////////

/*

Set the extent of one map service.

For multiple map services, see the section titled Setting the beginning extent

when using multiple services at-

http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jshelp_start.htm

*/

////WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING/////////

//

//      WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

//

//          ENSURE YOU HAVE A GEOMETRY SERVICE CREATED AND RUNNING ON

//          ESRI ArcGIS Server OR YOUR MAP MAY NOT DISPLAY

//         

//

//          NOTE:   You do not necessarily need to reference the geometry service

//                  in your code.

//

////WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING/////////

 

 

// Extent and Spatial reference of our map service

//var startExtent = new esri.geometry.Extent({ "xmin": 778733.96207758, "ymin": 1133387.86320644, "xmax": 849794.792685476, "ymax": 1193607.08672764, "spatialReference": { "wkid": 102100} });

// This is the required projection to display in Decatur for imagery

var startExtent = new esri.geometry.Extent({ "xmin": -9907408.2369, "ymin": 4839236.5572, "xmax": -9897146.5658, "ymax": 4847826.1683, "spatialReference": { "wkid": 102100} });

 

 

// Sets the extent for the find address query

var addressExtent, newExtent;

 

 

 

 

 

 

//-----------------------------------------------------------

// Map Services Begin

//-----------------------------------------------------------

 

 

 

 

// Define Map Section

var gisUrl; // GIS Server Location

// Old Url - http://64.107.106.57/

gisUrl = "http://decgis01/";

 

 

var rasSvc; // Raster Service

rasSvc = "Public/Aerial_2012/MapServer";

var mapSvc; // Map Service

mapSvc = "Internal/SOA/MapServer";

 

 

var addrLocSvc; // Address Locator Service

addrLocSvc = "Public/WebAddressLocator/GeocodeServer";

 

 

var geomSvc; // Geometry Service

geomSvc = "Utilities/Geometry/GeometryServer";

 

 

var map, dynamicMapServiceLayer, imageDynamicMapServiceLayer;

dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(gisUrl + "arcgis/rest/services/" + mapSvc);

dynamicMapServiceLayer.setOpacity(0.4);

//imageDynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer(gisUrl + "arcgis/rest/services/" + rasSvc);

imageDynamicMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");

 

 

 

 

// http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/arcgisdynamicmapservicelayer.htm#setImageFormat

//imageDynamicMapServiceLayer.setImageFormat("jpg");

 

 

// Navigation Tools

var navToolbar;

 

 

// Locator service to be used for find address

var locator;

locator = new esri.tasks.Locator(gisUrl + "arcgis/rest/services/" + addrLocSvc);

// SR required for Decatur

var spatialReference = new esri.SpatialReference({ wkid: 102100 });

 

 

locator.setOutSpatialReference(spatialReference);

// Geometry Service

var geometryService;

geometryService = new esri.tasks.GeometryService(gisUrl + "arcgis/rest/services/" + geomSvc);

 

 

 

 

 

 

//-----------------------------------------------------------

// Map Services End

//-----------------------------------------------------------

 

 

 

 

//-----------------------------------------------------------

// ESRI Tasks Begin

//-----------------------------------------------------------

 

 

// Define Macon County Tax Parcels as Layer to Query

// http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_querytask.htm#

var queryTask = new esri.tasks.QueryTask(gisUrl + "arcgis/rest/services/" + mapSvc + "/6");

 

 

// Creates a new query to be used against the current geometry

var queryParams = new esri.tasks.Query();

 

 

var circleSymbol = new esri.symbol.SimpleMarkerSymbol();

circleSymbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);

circleSymbol.setColor(new dojo.Color([153, 0, 51, 0.75]));

 

 

// Declare coordinate for drawing point in find address

var x1, y1;

 

 

// Declare geometry for find address

var geom;

 

 

 

 

 

 

// Identify Task 

var identifyHandle;

var identifyTask, identifyParams;

 

 

// Measure Polyline

var measureLine;

 

 

var lineLengthParams = new esri.tasks.LengthsParameters();

var measureLineGraphic;

 

 

 

 

// Measure Polygon

var measurePolygon;

 

 

var polygonLengthParams = new esri.tasks.AreasAndLengthsParameters();

var measurePolygonGraphic;

 

 

// Project Point

var pt = null;

var point;

var ptSymbol;

var ptGraphic;

var ptOutSR;

 

 

var pointHandle;

 

 

var inTown;

 

 

 

 

//-----------------------------------------------------------

// ESRI Tasks End

//-----------------------------------------------------------

 

 

 

 

//-----------------------------------------------------------

// Query Layers Begin

//-----------------------------------------------------------

// Layers to evaluate if they are in a safe zone based on a sex offender's potential address

var qryBikePaths = new esri.tasks.QueryTask(gisUrl + "arcgis/rest/services/" + mapSvc + "/1")

var qryHomeDayCare = new esri.tasks.QueryTask(gisUrl + "arcgis/rest/services/" + mapSvc + "/2");

var qryDayCare = new esri.tasks.QueryTask(gisUrl + "arcgis/rest/services/" + mapSvc + "/3");

var qryParks = new esri.tasks.QueryTask(gisUrl + "arcgis/rest/services/" + mapSvc + "/4");

var qrySchools = new esri.tasks.QueryTask(gisUrl + "arcgis/rest/services/" + mapSvc + "/5");

 

 

var qryDecaturBoundary = new esri.tasks.QueryTask(gisUrl + "arcgis/rest/services/" + mapSvc + "/7");

 

 

//-----------------------------------------------------------

// Query Layers End

//-----------------------------------------------------------

 

 

 

 

//-----------------------------------------------------------

// Graphics Definition Begin

//-----------------------------------------------------------

 

 

/* Define initial address point to be drawn for find address */

var firstGraphic;

 

 

/* Define queried point to be drawn for find address */

var graphicPt;

 

 

/* Defines the line drawn for the polygon of the parcel */

var selectParcel;

 

 

//-----------------------------------------------------------

// Graphics Definition End

//-----------------------------------------------------------

 

 

 

 

////////////////////////////////////////////////////////////////////////////////////

//

//          PAGE INITIALIZATION

//

////////////////////////////////////////////////////////////////////////////////////

 

 

function init() {

 

 

    // Initialize JavaScript Framework Controls

 

 

    // Round Sidebar Corners

    roundSidebarCorners();

 

 

    // Add Sidebar

    addSideBar();

 

 

    // Add Sidebar Title

    addSideBarTitle();

 

 

    // Add Map Navigation Title

    addMapNavigationTitle();

 

 

    // Add Map Navigation Content

    addMapNavigationContent();

 

 

    // Add Map Tools Title

    addMapToolsTitle();

 

 

    // Add Map Tools Content

    addMapToolsContent();

 

 

    // Add Address Search Title

    addAddressQueryTitle();

 

 

    // Add Address Search Content

    addAddressQueryContent();

 

 

 

 

    $("sideBarTop").style.cursor = "hand"; // Sidebar Top - To Drag the Sidebar

    $("sideBarTopFill").style.cursor = "hand"; // Sidebar Top Fill - To Drag the Sidebar

    $("sideBarBottom").style.cursor = "hand"; // Sidebar Bottom - To Drag the Sidebar

    $("sideBarBottomFill").style.cursor = "hand"; // Sidebar Bottom Fill - To Drag the Sidebar

 

 

 

 

    $("dojoGrid").style.display = 'none';

    $("btnClearGraphics").style.display = 'none';

 

 

 

 

    // Add Footer Section

    addFooterSection();

    addFooter();

 

 

    // Enable Sidebar Drag

    EnableDrag();

 

 

 

 

    // Set Browser to Full Size

    maxBrowserWindow();

 

 

    /*

    The proxy section is defined on the ESRI sample. I have included it as

    part of the documentation reads that the measuring will not work.

    I thought that might be important.

    */

 

 

    // Proxy Definition Begin

    //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.

    //If this null or not available the project and lengths operation will not work.  Otherwise it will do a http post to the proxy.

    esriConfig.defaults.io.proxyUrl = "proxy.ashx";

    esriConfig.defaults.io.alwaysUseProxy = false;

 

 

    // Proxy Definition End

 

 

    // Programmatically define web services

 

 

    // Add controls to the interface

    esriConfig.defaults.map.sliderLabel = null;

 

 

    ////////////////////////////////////////////////////////////////////////////////////

    //

    //   Note:

    //          The last layer added to the map is the top layer.

    //          Setting the opacity as shown below allows for hidden

    //          layers to become visible.

    //

    ////////////////////////////////////////////////////////////////////////////////////

 

 

 

 

    ////////////////////////////////////////////////////////////////////////////////////

    //

    //          LAYERS

    //

    ////////////////////////////////////////////////////////////////////////////////////                   

    /* Add a dynamic layer */

    /*

    All map services use a unique reference to identify the map service

    In ESRI ArcGIS Server, the unique reference is the URL of the published

    map service

    */

 

 

    map = new esri.Map("mapSection", { extent: startExtent });

 

 

    // Enable identify

    dojo.connect(map, "onLoad", initFunctionality);

 

 

    // The dynamic layer is added to the map

    map.addLayer(imageDynamicMapServiceLayer);

    map.addLayer(dynamicMapServiceLayer);

    //alert(dynamicMapServiceLayer.layerInfos[5].name);

    //alert((dynamicMapServiceLayer.visibleLayers.length) + 1);

 

 

 

 

 

 

    // Add toolbar

    navToolbar = new esri.toolbars.Navigation(map);

 

 

    // Sets the navigation bar up to handle previous and next extent

    dojo.connect(navToolbar, "onExtentHistoryChange", extentHistoryChangeHandler);

 

 

    // Reference - http://forums.arcgis.com/threads/48318-Set-zoomToFullExtent-to-be-my-Initial-Extent

    navToolbar.zoomToFullExtent = function () {

        map.setExtent(startExtent);

    }

 

 

 

 

    // Add Polygon Tool

    measurePolygon = new esri.toolbars.Draw(map);

    dojo.connect(measurePolygon, "onDrawEnd", function (geometry) {

        removePolygon();

        deactivatePoint();

        // This line of code is a guess

        polygonLengthParams.polygons = [geometry];

        polygonLengthParams.areaUnit = esri.tasks.GeometryService.UNIT_SQUARE_FEET;

        polygonLengthParams.areaUnit = esri.tasks.GeometryService.UNIT_ACRES;

        geometryService.simplify([geometry], function (simplifiedGeometries) {

            polygonLengthParams.polygons = simplifiedGeometries;

            geometryService.areasAndLengths(polygonLengthParams);

        });

        geometryService.lengths(polygonLengthParams);

        measurePolygonGraphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleFillSymbol()));

    });

 

 

 

 

 

 

    // Add Line Tool

    measureLine = new esri.toolbars.Draw(map);

    dojo.connect(measureLine, "onDrawEnd", function (geometry) {

        deactivatePoint();

        removePolygon();

        lineLengthParams.polylines = [geometry];

        lineLengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_FOOT;

        lineLengthParams.geodisc = true;

 

 

        geometryService.lengths(lineLengthParams);

        measureLineGraphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol()));

    });

 

 

 

 

 

 

    // Diplay Polygon Area and Distance after measuring

    dojo.connect(geometryService, "onAreasAndLengthsComplete", outputAreaAndLength);

 

 

    // Display Line Distance after measuring

    dojo.connect(geometryService, "onLengthsComplete", outputDistance);

 

 

    // Make Address Locator Available

    dojo.connect(locator, "onAddressToLocationsComplete", showResults);

 

 

 

 

    // Connect the row click item to the dojo grid

    dojo.connect(dojoGrid, "onRowClick", onRowClickHandler);

 

 

    // Enable tab display for identify

    dojo.connect(map.infoWindow, "onShow", function () {

        dijit.byId("tabs").resize();

    });

 

 

 

 

}

 

 

/*

Map Tools Begin

*/

 

 

// Add history reference for previous and next extent on map toolbar

function extentHistoryChangeHandler() {

    $("btnPrevExtent").disabled = navToolbar.isFirstExtent();

    $("btnNextExtent").disabled = navToolbar.isLastExtent();

}

 

 

 

 

/*

Find Address Point Function Begins

*/

function findAddress() {

    if (Page_IsValid) {

        // Clear the map

        map.graphics.clear();

        $("lblResponse").innerHTML = "";

        $("lblAddressStatus").innerHTML = "";

        var add = dojo.byId("txtAddress").value.split(",");

        var address = {

            SingleKey: add[0]

        };

        /*

        Locator begins searching for address matches when the method addressToLocations is called.

        The event listener onAddressToLocationsComplete calls the function showResults()

 

 

        onAddressToLocationsComplete fires when Locator.addressToLocation() has completed

        */

        locator.addressToLocations(address);

 

 

    }

}

 

 

function showResults(candidates) {

    var candidate;

    var symbol = new esri.symbol.SimpleMarkerSymbol();

    var infoTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />Score: ${score}");

    symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);

    symbol.setColor(new dojo.Color([255, 0, 0, 0.75]));

 

 

    var points = new esri.geometry.Multipoint(map.spatialReference);

 

 

    var incrementor = 0;

    var validRecords = 0;

    var xLoc, yLoc, singleAddress;

 

 

    $("dojoGrid").style.display = 'inherit';

 

 

    var items = [], obj = {}, loc;

    dojo.forEach(candidates,

  function (candidate) {

     if (candidate.score > 50) {

         obj = {};

         obj['address'] = candidate.address;

         obj['score'] = candidate.score;

         loc = candidate.location;

         obj['x'] = loc.x;

         obj['y'] = loc.y;

         obj['location'] = loc.x + ', ' + loc.y;

         items.push(obj);

     }

  }

  );

    console.log(items);

    // Create data object to be used in store

    var data = {

        items: items

    };

 

 

    // Create data store and bind to grid

    store = new dojo.data.ItemFileReadStore({ data: data });

    var grid = new dojox.grid.DataGrid;

    grid = dijit.byId('dojoGrid');

 

 

 

 

    grid.setStore(store);

 

 

    // Evaluate number of addresses returned

    // if there is only one address, set the height of the grid to 0

    if (items.length == 1) {

        $("dojoGrid").style.height = 0

    }

    else {

        // if there is more than one address set the height 50x the number of items addresses returned

        $("dojoGrid").style.height = 50 * items.length;

    }

 

 

    // Evaluate if any candidates exist

    if (candidates.length == 0) {

        $("lblAddressStatus").innerHTML = "The Address you entered is not recognized. Make sure you entered it correctly.";

        $("lblAddressStatus").className = "warningMessage";

 

 

        $("lblResponse").innerHTML = " Your address should be like the example:" +

        "<br> 111 E MAIN ST " +

        "<br> And the format should be:" +

        "<br> Street Address";

        $("lblResponse").className = "warningMessage";

        $("lblBikePath").innerHTML = "";

        $("lblHomeDayCare").innerHTML = "";

        $("lblDayCare").innerHTML = "";

        $("lblParks").innerHTML = "";

        $("lblSchools").innerHTML = "";

        $("lblCityLimits").innerHTML = "";

        $("btnClearGraphics").style.display = 'none';

        $("dojoGrid").style.display = 'none';

        navToolbar.zoomToFullExtent();

 

 

        // exit code

        return;

 

 

    }

    else {

        // Check all candidates for a matching score greater than 50

        for (incrementor; incrementor < candidates.length; incrementor++) {

            candidate = candidates[incrementor];

 

 

            if (candidate.score > 50) {

 

 

                var attributes = { address: candidates[incrementor].address, score: candidates[incrementor].score };

                var graphic = new esri.Graphic(candidates[incrementor].location, symbol, attributes, infoTemplate);

 

 

                map.graphics.add(graphic);

                map.graphics.add(new esri.Graphic(candidate.location, new esri.symbol.TextSymbol(attributes.address).setOffset(0, 8)));

                points.addPoint(candidate.location);

                validRecords = incrementor + 1;

 

 

                xLoc = candidates[incrementor].location.x;

                yLoc = candidates[incrementor].location.y;

                singleAddress = candidates[incrementor].address;

            }

        }

        if (validRecords > 1) {

            $("lblAddressStatus").innerHTML = "Success!";

            $("lblAddressStatus").className = "normalMessage";

            map.setExtent(points.getExtent().expand(3));

            $("btnClearGraphics").style.display = 'inherit';

        }

        else if (validRecords == 0) {

            $("lblAddressStatus").innerHTML = "The Address you entered is not recognized. Make sure you entered it correctly.";

            $("lblAddressStatus").className = "warningMessage";

 

 

            $("lblResponse").innerHTML = " Your address should be like the example:" +

        "<br> 111 E MAIN ST " +

        "<br> And the format should be:" +

        "<br> Street Address";

            $("lblResponse").className = "warningMessage";

            $("lblBikePath").innerHTML = "";

            $("lblHomeDayCare").innerHTML = "";

            $("lblDayCare").innerHTML = "";

            $("lblParks").innerHTML = "";

            $("lblSchools").innerHTML = "";

            $("lblCityLimits").innerHTML = "";

            $("btnClearGraphics").style.display = 'none';

            $("dojoGrid").style.display = 'none';

            navToolbar.zoomToFullExtent();

 

 

 

 

        }

        else if (validRecords == 1) {

            // Coordinates of single address returned

            $("lblAddressStatus").innerHTML = "The Address " + singleAddress + " was found.";

            $("lblAddressStatus").className = "normalMessage";

            map.setExtent(points.getExtent());

            $("btnClearGraphics").style.display = 'inherit';

 

 

            map.graphics.clear();

 

 

            $("lblResponse").innerHTML = "";

            x1 = xLoc;

            y1 = yLoc;

 

 

            geom = new esri.geometry.Point(x1, y1, new esri.SpatialReference({ wkid: 343 }));

 

 

            graphicPt = new esri.Graphic(geom, symbol);

 

 

 

 

 

 

            // Add Point

            map.graphics.add(graphicPt);

 

 

            // Initialize Query

            // http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_querytask.htm#

            var qry = new esri.tasks.Query();

            qry.returnGeometry = true;

            qry.ourSpatialReference = { "wkid": 102100 };

            qry.geometry = geom;

 

 

            // Check if point is in city limits

            qry.spatialRelationship = esri.tasks.Query.SPATIAL_INTERSECTS;

            qryDecaturBoundary.execute(qry, qryDecaturBoundary_complete);

 

 

 

 

        }

    }

 

 

}

 

 

 

 

 

 

/*

 

 

Display Grid Cell That Was Clicked

*/

function onRowClickHandler(evt) {

    map.graphics.clear();

 

 

    $("lblAddressStatus").innerHTML = "";

    $("lblResponse").innerHTML = "";

 

 

    // Set X and Y Coordinates

    x1 = dojoGrid.getItem(evt.rowIndex).x;

    y1 = dojoGrid.getItem(evt.rowIndex).y;

 

 

    // Declare geometry and assign coordinates

 

 

    // http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/point.htm#

    // http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/point.htm#PointConst1

    // Required for Decatur

    geom = new esri.geometry.Point(x1[0], y1[0], new esri.SpatialReference({ wkid: 102100 }));

 

 

 

 

 

 

    graphicPt = new esri.Graphic(geom, circleSymbol);

 

 

 

 

    // Add Point

    map.graphics.add(graphicPt);

 

 

    // Initialize Query

    // http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_querytask.htm#

    var qry = new esri.tasks.Query();

    qry.returnGeometry = true;

    qry.ourSpatialReference = { "wkid": 102100 };

    qry.geometry = geom;

 

 

    // Check if point is in city limits

    qry.spatialRelationship = esri.tasks.Query.SPATIAL_INTERSECTS;

    qryDecaturBoundary.execute(qry, qryDecaturBoundary_complete);

 

 

 

 

 

 

 

 

}

 

 

 

 

// Custom Buffer Sample

// http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/util_buffergraphic.html#

// http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/exp_cors_buffer.html

function doBuffer(geometry) {

    // Set up buffer parameters

    var params = new esri.tasks.BufferParameters();

    params.distances = [500];

    params.bufferSpatialReference = new esri.SpatialReference({ wkid: 3435 });

    params.outSpatialReference = map.spatialReference;

    params.unit = esri.tasks.GeometryService.UNIT_FOOT;

 

 

    geometryService.simplify([geometry], function (geometries) {

        params.geometries = geometries;

        geometryService.buffer(params, showBuffer);

    });

 

 

 

 

 

 

}

 

 

 

 

function showBuffer(bufferedGeometries) {

    map.graphics.clear();

 

 

    var symbol = new esri.symbol.SimpleFillSymbol(

                esri.symbol.SimpleFillSymbol.STYLE_SOLID,

                new esri.symbol.SimpleLineSymbol(

                    esri.symbol.SimpleLineSymbol.STYLE_SOLID,

                    new dojo.Color([255, 0, 0, 0.65]), 2

                ),

                new dojo.Color([255, 0, 0, 0.35])

            );

    var graphic;

    dojo.forEach(bufferedGeometries, function (geometry) {

        graphic = new esri.Graphic(geometry, symbol, { buffer: true });

        // Add point

        map.graphics.add(graphicPt);

        // Add polygon

        map.graphics.add(firstGraphic);

        // Add Buffer

        map.graphics.add(graphic);

    });

 

 

    map.setExtent(bufferedGeometries[0].getExtent().expand(2));

 

 

    // evaluate if buffered geometries intersect with safe zones

    queryParams.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;

    queryParams.returnGeometry = true;

 

 

    queryParams.geometry = graphic.geometry;

 

 

 

 

    // Evaluate if buffer intersects with bikepaths

    qryBikePaths.execute(queryParams, qryBikePaths_complete);

 

 

    // Evaluate if buffer intersects with a daycare

    qryDayCare.execute(queryParams, qryDayCare_complete);

 

 

    // Evaluate if buffer intersects with playground equipment

    qryParks.execute(queryParams, qryParks_complete);

 

 

    // Evaluate if buffer intersects with a Home Daycare

    qryHomeDayCare.execute(queryParams, qryHomeDayCare_complete);

 

 

    // Evaluate if buffer intersects with a school

    qrySchools.execute(queryParams, qrySchools_complete);

 

 

 

 

 

 

 

 

}

 

 

// Evaluate if address is in City Limits

function qryDecaturBoundary_complete(featureSets) {

    if (featureSets.features.length > 0) {

        $("lblResponse").innerHTML = "";

 

 

        // Initialize Query

        // http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_querytask.htm#

 

 

        var query = new esri.tasks.Query();

        query.returnGeometry = true;

        // This SR is requirer to draw the parcel polygon

        query.outSpatialReference = { "wkid": 102100 };

        query.geometry = geom;

 

 

        // Checks where point intersects with parcel

        query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;

        queryTask.execute(query);

 

 

 

 

        // Declare the graphic for the polygon

        firstGraphic = null;

        selectParcel = null;

        // +++++Listen for QueryTask onComplete event+++++

        dojo.connect(queryTask, "onComplete", function (graphics) {

            firstGraphic = graphics.features[0];

            selectParcel = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([98, 194, 204]), 3), new dojo.Color([255, 0, 0, 0]));

            firstGraphic.setSymbol(selectParcel);

 

 

            // Add Polygon Graphic On parcel as Selection

            map.graphics.add(firstGraphic);

 

 

            geometry = graphics.features[0].geometry;

 

 

            // Buffer polygon

            doBuffer(geometry);

 

 

        });

 

 

    }

    else {

        $("lblResponse").innerHTML = "It's outside the city.";

 

 

    }

    return inTown;

}

 

 

// Evaluate Safe Zones

 

 

function qryBikePaths_complete(featureSet) {

    if (featureSet.features.length > 0) {

        $("lblBikePath").innerHTML = "Caution, Bikepath";

        $("lblBikePath").className = "cautionMessage";

    }

    else {

        $("lblBikePath").innerHTML = "Bikepath Safe";

        $("lblBikePath").className = "successMessage";

    }

}

 

 

function qryHomeDayCare_complete(featureSet) {

    if (featureSet.features.length > 0) {

        $("lblHomeDayCare").innerHTML = "Home Daycare Unsafe";

        $("lblHomeDayCare").className = "warningMessage";

    }

    else {

        $("lblHomeDayCare").innerHTML = "Home Daycare Safe";

        $("lblHomeDayCare").className = "successMessage";

    }

}

 

 

function qryDayCare_complete(featureSet) {

    if (featureSet.features.length > 0) {

        $("lblDayCare").innerHTML = "Daycare Unsafe";

        $("lblDayCare").className = "warningMessage";

 

 

    }

    else {

        $("lblDayCare").innerHTML = "Daycare Safe";

        $("lblDayCare").className = "successMessage";

    }

}

 

 

function qryParks_complete(featureSet) {

    if (featureSet.features.length > 0) {

        $("lblParks").innerHTML = "Parks Unsafe";

        $("lblParks").className = "warningMessage";

    }

    else {

        $("lblParks").innerHTML = "Parks Safe";

        $("lblParks").className = "successMessage";

    }

}

 

 

function qrySchools_complete(featureSet) {

    if (featureSet.features.length > 0) {

        $("lblSchools").innerHTML = "Schools Unsafe";

        $("lblSchools").className = "warningMessage";

    }

    else {

        $("lblSchools").innerHTML = "Schools Safe";

        $("lblSchools").className = "successMessage";

    }

}

 

 

 

 

function clearResults() {

    $("btnClearGraphics").style.display = 'none';

    $("dojoGrid").style.display = 'none';

    $("lblResponse").innerHTML = "";

    $("lblAddressStatus").innerHTML = "";

    $("lblBikePath").innerHTML = "";

    $("lblHomeDayCare").innerHTML = "";

    $("lblParks").innerHTML = "";

    $("lblDayCare").innerHTML = "";

    $("lblSchools").innerHTML = "";

    $("lblCityLimits").innerHTML = "";

    $("txtAddress").value = "111 MAIN ST";

    map.graphics.clear();

    navToolbar.zoomToFullExtent();

}

 

 

 

 

function initFunctionality(map) {

 

 

 

 

    identifyTask = new esri.tasks.IdentifyTask(gisUrl + "arcgis/rest/services/" + mapSvc);

 

 

    identifyParams = new esri.tasks.IdentifyParameters();

    identifyParams.tolerance = 3;

    identifyParams.returnGeometry = true;

    identifyParams.layerIds = [0, 1, 2, 3, 4, 5, 6];

    identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;

    identifyParams.width = map.width;

    identifyParams.height = map.height;

 

 

    map.infoWindow.resize(415, 200);

    map.infoWindow.setContent(dijit.byId("tabs").domNode);

    map.infoWindow.setTitle("Identify Results");

 

 

}

 

 

function doIdentify(evt) {

    identifyParams.geometry = evt.mapPoint;

    identifyParams.mapExtent = map.extent;

    identifyTask.execute(identifyParams, function (idResults) { addToMap(idResults, evt); });

}

 

 

function addToMap(idResults, evt) {

    addressResults = { displayFieldName: null, features: [] }; // 0

    inHomeDayCareResults = { displayFieldName: null, features: [] }; //2

    dayCareFacilitiesResults = { displayFieldName: null, features: [] }; //3

    playgroundResults = { displayFieldName: null, features: [] }; //4

    schoolPropertyResults = { displayFieldName: null, features: [] }; //5

    maconTaxParcelResults = { displayFieldName: null, features: [] }; // 6

 

 

 

 

 

 

    // evaluate for layers 0,1, 3, 4, 5, and 6

    for (var i = 0, il = idResults.length; i < il; i++) {

        var idResult = idResults[i];

       

        if (idResult.layerId === 0) {

            if (!addressResults.displayFieldName) { addressResults.displayFieldName = idResult.displayFieldName };

            addressResults.features.push(idResult.feature);

            dijit.byId("safeZoneTab").setContent(layerTabContent(addressResults, "addressResults"));

            i = idResults.length + 1;

        }

        else if (idResult.layerId === 2) {

            if (!inHomeDayCareResults.displayFieldName) { inHomeDayCareResults.displayFieldName = idResult.displayFieldName };

            inHomeDayCareResults.features.push(idResult.feature);

            dijit.byId("safeZoneTab").setContent(layerTabContent(inHomeDayCareResults, "inHomeDayCareResults"));

            i = idResults.length + 1;

        }

 

 

        else if (idResult.layerId === 3) {

            if (!dayCareFacilitiesResults.displayFieldName) { dayCareFacilitiesResults.displayFieldName = idResult.displayFieldName };

            dayCareFacilitiesResults.features.push(idResult.feature);

            dijit.byId("safeZoneTab").setContent(layerTabContent(dayCareFacilitiesResults, "dayCareFacilitiesResults"));

            i = idResults.length + 1;

        }

        else if (idResult.layerId === 4) {

            if (!playgroundResults.displayFieldName) { playgroundResults.displayFieldName = idResult.displayFieldName };

            playgroundResults.features.push(idResult.feature);

            dijit.byId("safeZoneTab").setContent(layerTabContent(playgroundResults, "playgroundResults"));

            i = idResults.length + 1;

        }

        else if (idResult.layerId === 5) {

            if (!schoolPropertyResults.displayFieldName) { schoolPropertyResults.displayFieldName = idResult.displayFieldName };

            schoolPropertyResults.features.push(idResult.feature);

            dijit.byId("safeZoneTab").setContent(layerTabContent(schoolPropertyResults, "schoolPropertyResults"));

            i = idResults.length + 1;

        }

        else if (idResult.layerId === 6) {

            if (!maconTaxParcelResults.displayFieldName) { maconTaxParcelResults.displayFieldName = idResult.displayFieldName };

            maconTaxParcelResults.features.push(idResult.feature);

            dijit.byId("safeZoneTab").setContent(layerTabContent(maconTaxParcelResults, "maconTaxParcelResults"));

            i = idResults.length + 1;

        }

       

        map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));

    }

 

 

 

 

 

 

}

 

 

function layerTabContent(layerResults, layerName) {

    var content = "";

    switch (layerName) {

        case "addressResults":

            content = "<i>Total features returned: " + layerResults.features.length + "</i>";

            content += "<table border='1'><tr><th>Address</th><th>PIN</th></tr>";

            for (var i = 0, il = layerResults.features.length; i < il; i++) {

                content += "<tr><td>" + layerResults.features[i].attributes['ADDRESS'] + " </td>";

                content += "<td>" + layerResults.features[i].attributes['PIN_NUM'] + "</td>";

            }

            content += "</tr></table>";

            break;

        case "inHomeDayCareResults":

            content = "<i>Total features returned: " + layerResults.features.length + "</i>";

            content += "<table border='1'><tr><th>Description</th><th>Address</th></tr>";

            for (var i = 0, il = layerResults.features.length; i < il; i++) {

                content += "<tr><td>" + layerResults.features[i].attributes['USAGE_DESC'] + " </td>";

                content += "<td>" + layerResults.features[i].attributes['ADDRESS'] + "</td>";

            }

            content += "</tr></table>";

            break;

        case "dayCareFacilitiesResults":

            content = "<i>Total features returned: " + layerResults.features.length + "</i>";

            content += "<table border='1'><tr><th>Description</th><th>Name</th></tr>";

            for (var i = 0, il = layerResults.features.length; i < il; i++) {

                content += "<tr><td>Daycare Facilities</td>";

                content += "<td>" + layerResults.features[i].attributes['SCHOOL_NAM'] + "</td>";

            }

            content += "</tr></table>";

            break;

        case "playgroundResults":

            content = "<i>Total features returned: " + layerResults.features.length + "</i>";

            content += "<table border='1'><tr><th>Description</th><th>Name</th></tr>";

            for (var i = 0, il = layerResults.features.length; i < il; i++) {

                content += "<tr><td>Playgrounds</td>";

                content += "<td>" + layerResults.features[i].attributes['PARKNAME'] + " </td>";

            }

            content += "</tr></table>";

            break;

        case "schoolPropertyResults":

            content = "<i>Total features returned: " + layerResults.features.length + "</i>";

            content += "<table border='1'><tr><th>Description</th><th>Name</th></tr>";

            for (var i = 0, il = layerResults.features.length; i < il; i++) {

                content += "<tr><td>School Property</td>";

                content += "<td>" + layerResults.features[i].attributes['SCHOOL_NAM'] + "</td>";

            }

            content += "</tr></table>";

            break;

        case "maconTaxParcelResults":

            content = "<i>Total features returned: " + layerResults.features.length + "</i>";

            content += "<table border='1'><tr><th>Name</th><th>Address</th></tr>";

            for (var i = 0, il = layerResults.features.length; i < il; i++) {

                content += "<tr><td>" + layerResults.features[i].attributes['PRIMARYNAME'] + " </td>";

                content += "<td>" + layerResults.features[i].attributes['SITEADDRESS'] + " </td>";

            }

            content += "</tr></table";

            break;

    }

    return content;

}

 

 

 

 

function runIdentify() {

    measureLine.deactivate();

    removePolygon();

    removePolyline();

    measurePolygon.deactivate();

    identifyHandle = dojo.connect(map, "onClick", doIdentify);

    identifyHandle;

}

 

 

 

 

function outputDistance(result) {

    dojo.byId("lblDistance").innerHTML = "  " + dojo.number.format(result.lengths[0]) + " feet";

    measureLine.deactivate();

}

 

 

 

 

function outputAreaAndLength(result) {

    console.log(dojo.toJson(result));

    dojo.byId("lblDistance").innerHTML = "  " + dojo.number.format(result.areas[0]) + " sq. feet";

    measurePolygon.deactivate();

}

 

 

function removePolyline() {

    // Remove line graphics

    map.graphics.remove(measureLineGraphic);

    // Deactivate measure line

    measureLine.deactivate();

    // Remove point

    map.graphics.remove(ptGraphic);

    // Deactivate pointhttp://maps.decaturil.gov/ArcGIS/rest/services/InternalMapSampleServiceTest/MapServer/2 or the current URL

    dojo.disconnect(pointHandle);

 

 

}

 

 

function removeMeasureTools() {

    // Remove line graphics

    map.graphics.remove(measureLineGraphic);

    // Deactivate measure line

    measureLine.deactivate();

    // Remove point

    map.graphics.remove(ptGraphic);

    // Deactivate point

    dojo.disconnect(pointHandle);

    // Remove polygon

    map.graphics.remove(measurePolygonGraphic);

    // Deactivate polygon

    measurePolygon.deactivate();

 

 

}

 

 

// Deactivates Navtoolbar and Identify

function deactivateNavToolbar() {

    // Deactivate Toolbar

    navToolbar.deactivate();

    // Deactivate Identify

    dojo.disconnect(identifyHandle);

}

 

 

// Deactivates Identify

function deactivateIdentify() {

    // Disables identify

    dojo.disconnect(identifyHandle);

}

 

 

 

 

 

 

function projectPoint() {

    // Remove the line graphics

    map.graphics.remove(measureLineGraphic);

    // Deactivate measure line

    measureLine.deactivate();

    // Remove polygon graphics

    map.graphics.remove(measurePolygonGraphic);

    // Deactivate polygon

    measurePolygon.deactivate();

    // Deactivate the nav toolbar

    navToolbar.deactivate();

    // Deactivate identify

    deactivateIdentify();

    // Wire up the point handle to run the projectToWebMercator

    pointHandle = dojo.connect(map, "onClick", projectToWebMercator);

    pointHandle;

 

 

}

 

 

function projectToWebMercator(evt) {

    map.graphics.remove(ptGraphic);

    point = evt.mapPoint;

    ptSymbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);

    ptGraphic = new esri.Graphic(point, ptSymbol);

    ptOutSR = new esri.SpatialReference({ wkid: 102100 });

 

 

    map.graphics.add(ptGraphic);

 

 

    geometryService.project([point], ptOutSR, function (projectedPoints) {

        point = projectedPoints[0];

        dojo.byId("lblDistance").innerHTML = "  x:" + dojo.number.format(point.x) + ", y:" + dojo.number.format(point.y);

 

 

    });

 

 

    // Disconnect point handle

    dojo.disconnect(pointHandle);

 

 

}

 

 

function clearPointAndPolygon() {

    removePoint();

    removePolygon();

}

 

 

function clearPointAndLine() {

    removePoint();

    removePolyline();

}

 

 

function removePoint() {

    map.graphics.remove(ptGraphic);

}

 

 

function removePolygon() {

    map.graphics.remove(measurePolygonGraphic);

}

 

 

function removePolyline() {

    map.graphics.remove(measureLineGraphic);

}

 

 

 

 

function deactivatePoint() {

    map.graphics.remove(ptGraphic);

    dojo.disconnect(pointHandle);

}

 

 

 

 

 

 

function printMap() {

    alert("Print Map");

}

 

 

 

 

function getHelp() {

    alert("Help Me");

}

 

 

 

 

 

 

 

 

/*

Map Tools End

*/

 

 

// Rico Functions

 

 

// Round Sidebar Corners

function roundSidebarCorners() {

    roundCorners('sideBarTop',

                    {

                        corners: "top",

                        color: "#E1EBFB"

                    });

    roundCorners('sideBarBottom',

                    {

                        corners: "bottom",

                        color: "#E1EBFB"

                    });

}

 

 

 

 

// Dojo Function

 

 

// Add Sidebar

function addSideBar() {

    var sideBarConfig = new dijit.layout.BorderContainer({

    },

        $("sideBar")

        );

}

 

 

 

 

// Add Sidebar Title

function addSideBarTitle() {

    var sideBarTitleConfig = new dijit.TitlePane({

        title: "SOA Tools"

    },

        $("sideBarTitle")

        );

}

 

 

 

 

// Add Map Navigation title

function addMapNavigationTitle() {

    var mapNavigationTitleConfig = new dijit.TitlePane({

        title: "Navigation", open: true

    },

            $("mapNavigationTitle")

            );

}

 

 

 

 

// Add Map Navigation Content

function addMapNavigationContent() {

    var mapNavigationContentConfig = new dijit.layout.ContentPane({

    },

        $("mapNavigationContent")

        );

}

 

 

 

 

// Add Map Tools Title

function addMapToolsTitle() {

    var mapToolsTitleConfig = new dijit.TitlePane({

        title: "Map Tools", open: false

    },

            $("mapToolsTitle")

            );

}

 

 

 

 

// Add Map Tools Content

function addMapToolsContent() {

    var mapToolsContentConfig = new dijit.layout.ContentPane({

    },

        $("mapToolsContent")

        );

}

 

 

 

 

// Add Address Query Title

function addAddressQueryTitle() {

    var addressQueryTitleConfig = new dijit.TitlePane({

        title: "Address Search", open: true

    },

        $("queryAddressTitle")

        );

}

 

 

// Add Query Address Content

function addAddressQueryContent() {

    var addressQueryContentConfig = new dijit.layout.ContentPane({

    },

    $("queryAddress")

    );

}

 

 

 

 

// Add Footer Section

function addFooterSection() {

    var footerSection = new dijit.TitlePane({

        title: "Ask For Assistance", open: false

    },

            $("footerTitle")

            );

}

 

 

// Add Footer

function addFooter() {

    var pageFooter = new dijit.layout.ContentPane({

    },

        $("footer")

        );

}

 

 

 

 

// Scriptaculous Functions

 

 

// Enable Sidebar Drag

function EnableDrag() {

    new Draggable($("sideBar"));

}

 

 

 

 

 

 

//Maximize Browser Window Begin

// Reference - http://www.javascriptfreecode.com/53.htm

function maxBrowserWindow() {

    top.window.moveTo(0, 0);

    if (document.all) {

        top.window.resizeTo(screen.availWidth, screen.availHeight);

    }

    else if (document.layers || document.getElementById) {

        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {

            top.window.outerHeight = screen.availHeight;

            top.window.outerWidth = screen.availWidth;

        }

    }

}

// Maximize Browser Window End

 

 

 

 

// Initialize Page

dojo.addOnLoad(init);@

Outcomes