How do I create a widget that retrieves the feature that I click on?

393
0
07-11-2017 08:10 AM
BradLindgren
New Contributor

This function selects a polygon, then selects the features of another layer that are within the selected polygon. This function only selects the first polygon in the layer, not the polygon that was actually clicked on (see the bold line, only the first feature is selected). How do I edit this so that the polygon feature I click on gets selected?

selectByPolygonFeatureGeometry: function () {
// Select features using a polygon feature

if(!this.polygonDS){
alert("The Operation View does not contain a polygon data source");
return;
}

this.clearResult();

var featureQuery = this.createQueryObject();
var spatialQuery = this.createQueryObject();

// Query for all features from the point data source, then use the geometry of the first feature as the spatial filter
featureQuery.where = "1=1";
this.polygonDS.executeQuery(featureQuery).then(function (featureSet) {
if (!featureSet || !featureSet.features || featureSet.features.length === 0) {
alert("featureSet is invalid");
return;
}

// Grab the geometry of the first polygon feature
var feature = featureSet.features[0];
var polygon = {
"geometry": feature.geometry,
"symbol": {
"color": [0, 0, 0, 64],
"outline": {
"color": [1, 255, 255, 255],
"width": 1, "type": "esriSLS", "style": "esriSLSSolid"
},
"type": "esriSFS", "style": "esriSFSSolid"
}
};
this.graphicsLayerProxy.addOrUpdateGraphic(new Graphic(polygon));

// Set the feature's geometry as the query's spatial filter
spatialQuery.geometry = feature.geometry;
this.selectionDS.selectFeatures(spatialQuery);

this.expectedResultLbl.innerHTML +=
"features intersecting with the geometry of " + feature.attributes[this.dataSource.objectIdFieldName]
+ ": " + feature.attributes[this.dataSource.displayFieldName];
}.bind(this));
},

0 Kudos
0 Replies