How do we get the details of the layer when clicking on the ArcGIS map in angular 10. The click event is triggering on the map. Eg: A map showing house numbers. How do we get the house number when clicking on one of the house numbers on the map. I have to use the 'house number' in my code for other functionality.
this._view.on('click', function (event) {
console.log('click working');
//Need to get the value of clicked layer.
});
/Updated code/
this._view.on('click', function (event) {
this._view.hitTest(event).then(function (response) {
const graphic = response.results.filter(function (result) {
// return result.graphic.layer === hurricanesLayer;
return result.graphic.layer;
})[0].graphic;
console.log(graphic.attributes);
});
});
I am getting the error, 'Uncaught TypeError: Cannot read property '_view' of undefined'
That would depend on what you want to achieve. For example, if you want to retrieve the top most feature of each "queryable" layer you could use
hitTest
method from theMapView
. This method takes as a parameter a screen coordinate. In your case would be the result of a click event on the view.Here the docs, ArcGIS API - MapView hitTest
Here an example, ArcGIS Examples - Access features with pointer events