Get the ID of graphics on featureLayer

1003
1
Jump to solution
10-12-2021 04:12 PM
by Anonymous User
Not applicable

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?

NovicaJ_0-1634080078789.png

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?

0 Kudos
1 Solution

Accepted Solutions
ManishPatel
Esri Contributor

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.

Cheers,
Manish

View solution in original post

0 Kudos
1 Reply
ManishPatel
Esri Contributor

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.

Cheers,
Manish
0 Kudos