Access features with pointer events


This sample shows how to use the hitTest() method on the MapView to access features in a FeatureLayer. This is done by setting up a pointer-move event handler on the view and passing the returned screen x, y coordinates to the hitTest() method of the view, along with additional options to only include graphics from the FeatureLayer. A promise is returned, which resolves to an array of objects containing any features from the FeatureLayer. If a feature is returned, then the sample displays an information pertaining to this feature.

1
2
3
4
5
6
7
8
9
10
11
12
13
view.on("pointer-move", (event) => {
  // only include graphics from hurricanesLayer in the hitTest
  const opts = {
    include: hurricanesLayer
  }
  view.hitTest(event, opts).then((response) => {
    // check if a feature is returned from the hurricanesLayer
    if (response.results.length) {
      const graphic = response.results[0].graphic;
      // do something with the graphic
    }
  });
});

The sample displays hurricane paths. Click any line segment to view some of its attributes and assign the same symbol to all line segments with the same storm name.

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