Parsing queryResult

Feedback


queryResult is the query result resource that storing the result of the map query. The queryResult resource and its URI are generated by implementing the POST request on the queryResults resource.

The queryResult resource not only supports the representation in json, rjson, html, and xml, but also supports the png, bmp, jpeg, and gif format representation if the spatial information (geometry) is included in the query result.

By implementing the GET request on the qureyResult resource, we can get the information of the resource. Please refer to queryResult. Below is the code for getting the information of the distance query result of the example for Distance Query.

//Parse the queryResult resource

function getQueryResult()

{

    var commit=getcommit();

    //The URI of the distance query result

    var uri=document.getElementById("queryURI");

    //Set the request body parameters

    var entry=null;

    commit.open("GET",encodeURI(uri),false,"","");

    commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

    commit.send(toJSON(entry));

    // Parse the json string returned from the server to a JavaScript object

    var response = json_parse(commit.responseText, null);       

    //The number of recordsets

    var resordserNum=response.recordsets.length;

    //The number of fields

    var fieldcount;

    //The number of features in the recordset

    var count;

    //Gets the Div container for display.

    var container = document.getElementById('container');

    container.innerHTML="";

    container.innerHTML+="There are "+ resordserNum+" recordset(s): ";    

    for(var i=0;i<resordserNum;i++)

    {

        container.innerHTML+="<p>Recordset "+ (i+1)+": </p>";        

        fieldcount=response.recordsets[i].fieldCaptions.length;

        count=response.recordsets[i].features.length;

        for(var j=0;j<count;j++)

        {

            container.innerHTML+="Feature "+(j+1)+": ";

            for(var k=0;k<fieldcount;k++)

            {                container.innerHTML+=response.recordsets[i].fields[k]+"="+response.recordsets[i].features[j].fieldValues[k]+",";

            }

            container.innerHTML+="<br>";

        }

    }

}

The number of recordsets in queryResult is identical to the number of elements in the "queryParams":[…] collection. That is to say, the number of parameters groups decides the number of recordsets in the result. As to DistanceQuery, there is one group of query in parameters--queryParameters.queryParams--"sortClause":null,"ids":null,"name":"World@World","attributeFilter":null,"groupClause":null,"linkItems":null,"joinItems":null,"fields":["smID","Country"]). The query result has only one recordset, as shown below: