Query Related Features

This sample demonstrates how to query related features from a FeatureLayer by using the queryRelatedFeatures() method. Each hexagon on the map represents one or more major cities in the U.S. Clicking on a hexagon will trigger a query for its related features, which will be displayed in a table added to the view's UI.

How it works

A function calls queryObjectIds() whenever the user clicks on the map, which returns the objectId of the corresponding hexagon in the layer.

1
2
3
4
5
6
layer.queryObjectIds({
  geometry: point,
  spatialRelationship: "intersects",
  returnGeometry: false,
  outFields: ["*"]
})

We highlight the hexagon, then use the queryRelatedFeatures() method to query for the related features attached to this object id.

1
2
3
4
5
return layer.queryRelatedFeatures({
  outFields: ["NAME", "SUM_POPULATION"],
  relationshipId: layer.relationships[0].id,
  objectIds: objectIds
});

Then, we get the attributes from the resulting FeatureSet and create a table element that can hold the resulting data.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

The developer dashboard has moved

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close