If you load a FeatureLayer onto the map, you can create a map click handler basically to listen for clicks on your map, do a hit test, and do some logic with whatever it clicked. Doesn't have to be a FeatureLayer, could be a GeoJSONLayer if you want. I believe it should be the same workflow for any type of layer.
Actually clicking on the map and getting the data from the feature would be setting up a click handler on the view (MapView or SceneView whichever you're working with) and then using a hit test based on the coordinates clicked.
Something to the effect of...
view.on("click", function(event) {
view.hitTest({x: event.x, y: event.y}).then(function(response) {
//response.results would hold the features you clicked
if (response.results.length) {
const graphic = response.results[0].graphic;
// do something with the graphic
const attributes = resposne.results[0].graphic.attributes;
// do something with the attributes
}
});
});
You can see a similar example here for mouse hover events I adapted that from: https://developers.arcgis.com/javascript/latest/sample-code/view-hittest/ with more information about performing hit tests on maps and getting results back here in the documentation: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…