Access features with click events

This device does not support 3D.

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 click event handler on the view and passing the returned screen x, y coordinates to the hitTest() method of the view. A promise is returned, which resolves to an array of objects containing any features from a GraphicsLayer or FeatureLayer.

view.on("click", function(event){
  view.hitTest(event)
    .then(function(response){
       // do something with the result graphic
       var graphic = response.results[0].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

There were no match results from your search criteria.