0

Can anybody tell me what wrong in this code. Here I am passing point geometry to query task :

JS code :

var districtName = $('#ddlDistrictd').val();
function showresults() {
    $.ajax({
        type: "POST",
        url: "Agriculture.asmx/GetDistrictpoints",
        data: "{'districtname':'" + districtname + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        //error: OnError

    });

    function OnSuccess(data, status) {
        var myObject = JSON.parse(data.d);
        var querytext = JSON.stringify(myObject);
        var querytext2 = "shape  in (" + querytext + ")";



        map.graphics.clear();

        var graphic;
        var queryTask = new esri.tasks.QueryTask('http://[my_server]/arcgisserver/rest/services/CRD/CRD2/MapServer/0');
        var query = new esri.tasks.Query();
        symbol = new esri.symbol.SimpleMarkerSymbol();
        symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
        symbol.setSize(10);
        symbol.setColor(new dojo.Color([255, 255, 0, 0.5]));
        query.returnGeometry = true;
        query.outFields = ["*"];
        // query.InSpatialReference = { "wkid": 102100 };
        query.where = querytext2;
        queryTask.execute(query, function(featureSet) {

            if (featureSet.features.length == 0) {
                alert("No Results Found");
                // esri.hide(dojo.byId("loadingImg"));
            } else {
                var extent = esri.graphicsExtent(features);
                if (!extent && features.length == 1) {
                    // esri.getExtent returns null for a single point, so we'll build the extent by hand
                    var point = features[0];
                    extent = new esri.geometry.Extent(point.x - 1, point.y - 1, point.x + 1, point.y + 1, point.SpatialReference);
                }

                if (extent) {
                    // assumes the esri map object is stored in the globally-scoped variable 'map'
                    map.setExtent(extent)
                }

            }
        });

    }
}

I am getting the below error :

post request error

and response error is

response

  • Is var querytext = JSON.stringify(myObject); a geomtery object , and what you mean by the shape in ?? in the query clause var querytext2 = "shape in (" + querytext + ")"; do you want to make spatial query ! – Springer F Feb 6 '16 at 21:01
  • I am converting 'myObject' to string and passing it into query task. Here 'shape' is geometry column. I am using two ajax function call. One for data binding to grid and second one for zoom. First one is working. After binding the value, those points should be zoomed.May be problem with passing json string to query task. – Rushya Feb 7 '16 at 8:14
1

You are trying to make a spatial query it would'nt work with query.where ! use query.geometry instead , and use a SPATIAL_REL ( in your case i think SPATIAL_REL_CONTAINS or SPATIAL_REL_INTERSECTS) , So your succes function would be :

function OnSuccess(data, status) {
    var myObject = JSON.parse(data.d);
    //var querytext = JSON.stringify(myObject);
    //var querytext2 = "shape  in (" + querytext + ")";


    map.graphics.clear();

    var graphic;
    var queryTask = new esri.tasks.QueryTask('http://[my_server]/arcgisserver/rest/services/CRD/CRD2/MapServer/0');
    var query = new esri.tasks.Query();
    symbol = new esri.symbol.SimpleMarkerSymbol();
    symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
    symbol.setSize(10);
    symbol.setColor(new dojo.Color([255, 255, 0, 0.5]));
    query.returnGeometry = true;
    query.outFields = ["*"];
    // query.InSpatialReference = { "wkid": 102100 };
    //query.where = querytext2;

    //here you passe your geometry 
    query.geometry = myObject;
    // set the spatial relationship ( here all features contained in this object {all point in polygon})
    query.spatialRelationship =  esri.tasks.Query.SPATIAL_REL_CONTAINS;


    queryTask.execute(query, function(featureSet) {

        if (featureSet.features.length == 0) {
            alert("No Results Found");
            // esri.hide(dojo.byId("loadingImg"));
        } else {
            var extent = esri.graphicsExtent(featureSet.features);
            if (!extent && featureSet.features.length == 1) {
                // esri.getExtent returns null for a single point, so we'll build the extent by hand
                var point = features[0];
                extent = new esri.geometry.Extent(point.x - 1, point.y - 1, point.x + 1, point.y + 1, point.SpatialReference);
            }

            if (extent) {
                // assumes the esri map object is stored in the globally-scoped variable 'map'
                map.setExtent(extent)
            }

        }
    });

}

hope it helps you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.