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 = "http://summitmaps.summitoh.net/arcgis/rest/services/DOES_Mercator/MapServer/2";
featureLayer = new esri.layers.FeatureLayer(featureLayerUrl, {
    mode: esri.layers.FeatureLayer.MODE_SELECTION,
    outFields: ["UNAME", "INSTALLYR", "DNAME", "STREET", "EASEMENT", "INVERT", "OWNERSHIP"]
});
featureLayer.setSelectionSymbol(new esri.symbol.SimpleMarkerSymbol().setSize(8).setColor(new dojo.Color([160, 214, 238])));
map.addLayer(featureLayer);


function onDrawEnd(extent) {


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


    toolBar2.deactivate();


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


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


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


        manholeGrid.on("rowclick", onRowClickHandler);


        manholeGrid.setStore(store30);


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


        gsvc = new GeometryService("http://summitmaps.summitoh.net/arcgis/rest/services/Utilities/Geometry/GeometryServer");
        var graphics = featureLayer.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])
            );


            arrayUtils.map(geometries, function(geometry) {
                var graphic = new Graphic(geometry, symbol);
                map.graphics.add(graphic);


            });


            queryTaskNew = new esri.tasks.QueryTask("http://summitmaps.summitoh.net/arcgis/rest/services/Cadastral/Parcels/MapServer/0");
            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 = dojo.map(features, function(feature) {
                        return feature.attributes;
                    });
                    var data300 = {
                        identifier: "OBJECTID",
                        items: items300
                    };
                    var store300 = new dojo.data.ItemFileReadStore({
                        data: data300
                    });


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


                    grid.on("rowclick", onRowClickHandler);


                    grid.setStore(store300);
                }
            }


        };
    });

 

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'">
                        <thead>
                            <tr>
                                <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>
                            </tr>
                        </thead>
                    </table>
                </div>

 

<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'">
            <thead>
                <tr>
                    <th field="PARID">Parcel #</th>
                    <th field="ADDR">Address</th>
                </tr>
            </thead>
        </table>
    </div>


</div>







 

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!!

Outcomes