I have a feature layer that is not preselected on map load and I want to get the ID of a point on the map when I click on it, on a certain point. Further on, I'll get that ID and send it to a backend method for further data processing.
My question is how do I get the ID of a point on the map when I click on it? How do I always get the ID with each new click on a different point?
First click on 2, get the ID. Then click on 1, get the ID, etc.
I tried something like this
disLayer = new FeatureLayer({
title: restService.label,
url: restService.restServiceLink,
outFields: ["*"], // Return all fields so it can be queried client-side
popupTemplate: { // Enable a popup
title: "<b>" + restService.label + ": {" + restService.searchAndPopupFieldName + "} </b>",
content: photoContentHtml
}
});
map.add(disLayer, 0);
on(disLayer, 'click', function (e) {
console.log("e", e);
});
I wanted to see what 'e' contains, but I can't print it out. The on click event doesn't work and it's not printing e. How do I get the ID of a point on map when I click the point?
Solved! Go to Solution.
Hi @Anonymous User ,
Please refer to this sample this will provide you some reference to get the attributes for the clicked feature on the map.
https://developers.arcgis.com/javascript/latest/sample-code/view-hittest/
What you have in your code snippet, will return object only, you will need to further modify the code to get attributes.
Hope this helps.
Hi @Anonymous User ,
Please refer to this sample this will provide you some reference to get the attributes for the clicked feature on the map.
https://developers.arcgis.com/javascript/latest/sample-code/view-hittest/
What you have in your code snippet, will return object only, you will need to further modify the code to get attributes.
Hope this helps.