Select to view content in your preferred language

HOW to: Query task with polygon graphic created.

605
1
07-02-2013 02:10 PM
Ravichandran_M_Kaushika
Occasional Contributor
dear Readers,

thank you reading this question of mine. Using http://developers.arcgis.com/en/javascript/samples/graphics_undoredo/ (without undo and redo), we had created the application and integrating the 2nd link: https://developers.arcgis.com/en/javascript/jssamples/query_buffer.html, we were able to do a map click as explained in the 2nd link to query our layer exposed by webservice.

Questions:
1.  instead of sending a evt.MapPoint as indicated in the query buffer lnk with a predetermined buffer, how to send a polygon or a polyline intersect - we want the result as it comes out from query buffer.

2.  another question i had was: in that query_buffer example, example run as-is, returns only Object id for our server - even though i had set query out params = ["*"] and verified that rest service /0 layer queried had all columns exposed in a queriable fashion.

I have 1 idea, i can disable the map-click function in the query buffer and try to use the graphics point button to do the selection.  but i am not still sure about how to set up the query task to ensure that it does not fail.

when i try to send the polyon geometry in the query buffer code, it does not return anything.

wanted to see whether there are any examples that i can use to move forward.

 function addToMap(geometry) {
        var symbol;
        toolbar.deactivate();
        
        //   map.showZoomSlider();
        switch (geometry.type) {
            case "point":
                symbol = new esri.symbol.SimpleMarkerSymbol();
                break;
            case "multipoint":
                symbol = new esri.symbol.SimpleMarkerSymbol();
                break;
            case "polyline":
                symbol = new esri.symbol.SimpleLineSymbol();
                break;
            default:
                symbol = new esri.symbol.SimpleFillSymbol();
                break;
        }
        var graphic = new esri.Graphic(geometry, symbol);
        graphicsDrawnOnScreen = graphic;
        
        map.graphics.add(graphic);
        var params = new esri.tasks.BufferParameters();
        //params.distances = [100];
        params.geometries = graphicsDrawnOnScreen;
      //  params.unit = esri.tasks.GeometryService.UNIT_METER;
        //params.geometries = [evt.mapPoint];     
        //params.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;
        geometryService.buffer(params);
        geometryService.intersect(graphicsDrawnOnScreen);
        toolbarItemClicked == false;      
    }
i tried the above code without commenting out the above lines.

0 Kudos
1 Reply
VinayBansal
Occasional Contributor II
You can make use of draw toolbar to get the polygon geometry by using appropriate tool(Polygon,Extent or Freehand Polygon). On the "onDrawEnd" event of the toolbar you can fetch the geometry and perform a spatial query with this geometry using QueryTask

https://developers.arcgis.com/en/javascript/jsapi/draw.html

And regarding your second query, are you adding the layer as  feature layer on map. Then you must look into this.....
https://developers.arcgis.com/en/javascript/jsapi/featurelayer.html#featurelayer1

Feature layer accept options of "outFields" and documnetation says:

<String[]> outFields A comma delimited list of field names to include in the FeatureLayer. If not specified, the feature layer will return the OBJECTID field and if applicable the start time field, end time field and type id field. You can specify ["*"] to fetch the values for all fields in the layer, this is useful when editing features.
0 Kudos