AnsweredAssumed Answered

Issues with buffering selected features/query task

Question asked by rcsellman on Oct 15, 2014
Latest reply on Nov 27, 2015 by rcsellman

I am trying to give users the ability to select features from a specific feature layer, buffer that selection and query another feature layer using the geometries from the buffer.  I want results from the first selection to be sent to one datagrid and results from the second query to be sent to a different datagrid.  I think I am really close - the way I have it set up now is the user can draw a box to select features (points in this case).  When the drawing ends, it select features within the drawn extent, performs a buffer at a set distance on those features, and uses the buffer extent to select features from a polygon layer.  This all works just fine however, the issue I am having is with the two datagrids.  For some reason, data from the first selection is being pushed to both datagrids.


Here is a bit of JS:


dojo.connect(map, "onLoad", function(map) {
    //initialize the toolbar
    toolBar2 = new esri.toolbars.Draw(map);
    dojo.connect(toolBar2, "onDrawEnd", onDrawEnd);

var featureLayerUrl = "";
featureLayer = new esri.layers.FeatureLayer(featureLayerUrl, {
    mode: esri.layers.FeatureLayer.MODE_SELECTION,
featureLayer.setSelectionSymbol(new esri.symbol.SimpleMarkerSymbol().setSize(8).setColor(new dojo.Color([160, 214, 238])));

function onDrawEnd(extent) {

    var newStore = new{
        data: {
            identifier: "",
            items: []
    var grid = dijit.byId("manholeGrid");


    var query = new esri.tasks.Query();
    query.geometry = extent;
    featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function(features, selectionMethod) {

        var items30 =, function(feature) {
            return feature.attributes;
        var data30 = {
            identifier: "OBJECTID",
            items: items30
        var store30 = new{
            data: data30

        var manholeGrid = registry.byId("manholeGrid");

        manholeGrid.on("rowclick", onRowClickHandler);


        map.setExtent(graphicsUtils.graphicsExtent(featureLayer.getSelectedFeatures()), true);

        gsvc = new GeometryService("");
        var graphics =;
        var selectedGeoms = graphicsUtils.getGeometries(graphics);
        var params = new BufferParameters();
        params.geometries = selectedGeoms;

        params.distances = [500];
        params.unit = GeometryService.UNIT_FOOT;
        params.outSpatialReference = map.spatialReference;
        gsvc.buffer(params, showBuffer);

        function showBuffer(geometries) {

            var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                    new Color([0, 0, 255, 0.65]), 2
                new Color([0, 0, 255, 0.35])

  , function(geometry) {
                var graphic = new Graphic(geometry, symbol);


            queryTaskNew = new esri.tasks.QueryTask("");
            var queryNew = new esri.tasks.Query();
            queryNew.returnGeometry = true;
            queryNew.outFields = ["PARID", "ADDR"];

            queryNew.geometry = geometries[0];

            queryTaskNew.execute(queryNew, showResults300);

            function showResults300(featureSet) {

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

                    var items300 =, function(feature) {
                        return feature.attributes;
                    var data300 = {
                        identifier: "OBJECTID",
                        items: items300
                    var store300 = new{
                        data: data300

                    var grid = registry.byId("parcelGrid");

                    grid.on("rowclick", onRowClickHandler);




And here is the HTML as it pertains to the above code:


<div data-dojo-type="dijit/layout/ContentPane" title="Manhole">
                    <input type="text" id="doesManholeText" value="BA15" />
                    <button id="doesManholeSearch" data-dojo-type="dijit.form.Button" type="button" data-dojo-attach-point="button">Search</button>
                    <button data-dojo-type="dijit.form.Button" onClick="toolBar2.activate(esri.toolbars.Draw.EXTENT);">Select</button>
                    <button id="clearManholeGrid" data-dojo-type="dijit.form.Button" type="button" data-dojo-attach-point="button">Clear</button>
                    <span id="manhole-result-count"></span>
                    <table data-dojo-type="dojox/grid/DataGrid" data-dojo-id="manholeGrid" id="manholeGrid" style="height: 340px" data-dojo-props="rowsPerPage:'100', rowSelector:'20px'">
                                <th field="UNAME">UNAME</th>
                                <th field="INSTALLYR">Install Year</th>
                                <th field="DNAME">DNAME</th>
                                <th field="STREET">Street</th>
                                <th field="EASEMENT">Easement</th>
                                <th field="INVERT">Invert</th>
                                <th field="OWNERSHIP">Ownership</th>


<div id="bottom" data-dojo-type="dojox/layout/ExpandoPane" title="Click the Arrow to Minimize this Panel" data-dojo-props="title: 'Parcel Search', splitter:true, startExpanded: false, region:'bottom'" style="height: 300px;">

    <div data-dojo-type="dijit/layout/ContentPane" title="Selected Parcels">

        <table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="parcelGrid" id="parcelGrid" style="height: 300px" data-dojo-props="rowsPerPage:'100', rowSelector:'20px'">
                    <th field="PARID">Parcel #</th>
                    <th field="ADDR">Address</th>



Can anyone see why I can't get results from the second query, in this case, "queryTaskNew" into the appropriate datagrid?


Any help is much appreciated!!