This sample demonstrates how to query features represented by aggregate point clusters. Clustering is a method of reducing points in a FeatureLayer, CSVLayer, GeoJSONLayer, or OGCFeatureLayer by grouping them into clusters based on their spatial proximity to one another. Typically, clusters are proportionally sized based on the number of features within each cluster. See the Point clustering - basic configuration if you are unfamiliar with clustering.
Querying clustered features allows you to do the following:
Query and display statistics describing the clustered features in the popup.
Query the extent of the features and display it in the view.
Query all the clustered features and add them to the popup to be browsed by the user.
To query clustered features, you must provide the ObjectID of the cluster graphic to the Query.aggregateIds property and pass the parameters to the desired query method on the clustered layer's layer view.
const query = layerView.createQuery();
query.aggregateIds = [ 1 ];
// returns the features represented by the cluster with an ObjectID of 1const { features } = await layerView.queryFeatures(query);
Query cluster statistics
To query statistics for the features included in a cluster, reference the ObjectID of the cluster graphic in Query.aggregateIds, then specify the query outStatistics. Since the clustered layer has a UniqueValueRenderer, we'll use groupByFieldsForStatistics to group the statistics by the field used to categorize the features in the renderer.
You may want to display the extent of the features to the user. To do this, reference the cluster graphic's ObjectID in Query.aggregateIds, and call the queryExtent method on the layer view.
Perhaps it's better to show the convex hull of the clustered features rather than the extent since it more accurate represents the distribution of the points. The geometryEngine allows you to do that. Query for all the features in the cluster, get their geometries, then pass them to the convexHull method of geometryEngine.