how to Get all selected features Ids from a buffer results

1182
4
Jump to solution
08-11-2016 12:21 AM
HushamHassan
Occasional Contributor

Is it Possible to get prop_id  for each  Parcels   selected in a buffer results,  so I can pass them to  SQL query,  for example  if the buffer return  10  parcels  I need to get all the prop_id for the 10 parcels..

_showBuffer: function(features){
            $('.results.multipleBuffer').hide();
            var bufferSymbol = symbols.buffer;
            map.graphics.clear();
            if (features.length > 0) {
                var graphic = new Graphic(features[0], bufferSymbol);
                map.graphics.add(graphic);
                queryTask = new QueryTask(config.mapServices.dynamic + "/" + config.parcelLayerID);
                var bufferQuery = new Query();
                bufferQuery.outFields = ["*"];
                bufferQuery.returnGeometry = true;
                bufferQuery.geometry = features[0];
                queryTask.execute(bufferQuery).then(lang.hitch( this, function (fset) {
                    var bufferFeatures = fset.features;
                    console.log(bufferFeatures);
                    this._createTable(bufferFeatures);
                    //console.log(bufferFeatures);
                    navEvent('point');
                    if (fset.features.length > 0) {
                        var allGraphics = array.map(fset.features, function (feature) {
                            return feature;
                        });
                        unionExtent = graphicsUtils.graphicsExtent(allGraphics);
                        map.setExtent(unionExtent.expand(1.5));
                    }
                }));
            }
        },
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Husham,

  You are already looping through the results so it would simply be something like this:

                    if (fset.features.length > 0) {
                        var Gids = [];
                        var allGraphics = array.map(fset.features, function (feature) {
                            Gids.push(feature.attributes.prop_id);
                            return feature; 
                        }); 
                        unionExtent = graphicsUtils.graphicsExtent(allGraphics); 
                        map.setExtent(unionExtent.expand(1.5)); 
                    }
                    //Then you use the Gids array to populate your SQL query i.e. var sqlText = "Select * from TableX Where FieldX IN (" + Gids.join() + ")";

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Husham,

  Sure you can. You already have the graphics that are selected based on intersecting the buffer(s). So you would loop through the fset.features and once you have a single feature (i.e. var feat = fset.features😉 then you would get that features attributes property and then the field you are interested in (i.e. fset.features[0].attributes.prop_id).

HushamHassan
Occasional Contributor

Thank you Robert,  Could you please provide code sample for the loop.

Regards

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Husham,

  You are already looping through the results so it would simply be something like this:

                    if (fset.features.length > 0) {
                        var Gids = [];
                        var allGraphics = array.map(fset.features, function (feature) {
                            Gids.push(feature.attributes.prop_id);
                            return feature; 
                        }); 
                        unionExtent = graphicsUtils.graphicsExtent(allGraphics); 
                        map.setExtent(unionExtent.expand(1.5)); 
                    }
                    //Then you use the Gids array to populate your SQL query i.e. var sqlText = "Select * from TableX Where FieldX IN (" + Gids.join() + ")";
HushamHassan
Occasional Contributor

Robert,

That is really great Help.

Thank you

0 Kudos