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.