Select to view content in your preferred language

Returning a text value from a spatial query

984
2
02-01-2013 08:59 AM
soniadickerson1
Regular Contributor
I need to return a text value so that it can be used in Crystal Reports.  The report will access the app by appending the coordinates of a known location as parameters to the app url.

for example:  http://servername/spatialservices/getstate.html?-11920113.271*5345577.536

I'd want the html page to return the name of the state where the given coordinates reside.
The following code works in retrieving the state,  I just don't know how to get it to pass an object that Crystal reports can read as text. 


Here's the code that I have.  Thank you for any help.


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9"/>

<title>getStateName</title>
</head>

  <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>
    <script type="text/javascript">
        dojo.require("esri.tasks.query");
        dojo.require("esri.tasks.geometry");
        dojo.require("esri.geometry");


    function init(){
      
  
       var webParams = document.location.search;
      //format  ?x*y
      //parse out info that comes after the ?
      XYString = webParams.substr(1).split('*');
      XString = XYString[0];
      YString = XYString[1];

      //set xy to preset values to verify the process
      //Wyoming -11920113.271*5345577.536
      //Wisconsin  -10045094.029*5622569.015
      //Alaska  -17076416.186*9905283.420
      //Alabama -9618953.292*3896699.031


      if ((XString != null) && (YString != null)) {
              fimStandQueryTask = new esri.tasks.QueryTask("http://server.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_1990-2000_Population_Change/Map...");
            featureQuery = new esri.tasks.Query();
            featureQuery.returnGeometry = false;
            featureQuery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_WITHIN;
            featureQuery.outFields = ["NAME"];
            featureQuery.geometryType = "esriGeometryPoint";
            featureQuery.where = "1=1";

            var XY = new esri.geometry.Point(XString, YString, new esri.SpatialReference({ wkid: 102100 }));
            featureQuery.geometry = XY;
           
            fimStandQueryTask.execute(featureQuery, showResults);
        } else {
            showResults(null);
        }

    }


    function showResults(featureSet) {

        var s = "NA";
        if (featureSet != null) {
            if (featureSet.features.length > 0) {
                var featureAttributes = featureSet.features[0].attributes;
                for (att in featureAttributes) {
                    s = featureAttributes[att];
                }
            }
        }

        //Build the appropriate data object for our data component
        var data = { "identifier": "StateName", "items": s };
        alert(data.items);
        return data.items;

    }
     
dojo.addOnLoad(init);

  </script>
<body/>
</html>
0 Kudos
2 Replies
JohnGravois
Deactivated User
have you seen this sample?
0 Kudos
soniadickerson1
Regular Contributor
I greatly appreciate your reply.  That sample may be helpful in providing a better way to extract the parameters, but the real concern is building an object that Crystal Reports can use.  If you have any insight on that one, I'd be much obliged.
0 Kudos