You are using a browser that is no longer supported. Please use the latest version of Google Chrome, Mozilla Firefox, Apple Safari, or Microsoft Edge. For more information please see the System Requirements.

Unsupported browser

You are using a browser that is not supported. JavaScript API works on the latest versions of Google Chrome, Mozilla Firefox, Apple Safari, or Microsoft Edge. Use one of these browsers and provide your feedback through GeoNet, the Esri Community.

  • {i18n.unsupportedBrowser.chrome}
  • Firefox
  • Safari
  • undefined
Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

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.

view.on("pointer-move", function(event) {
  // only include graphics from hurricanesLayer in the hitTest
  const opts = {
    include: hurricanesLayer
  }
  view.hitTest(event, opts).then(function(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.

Sample search results

TitleSample
Loading...