Select to view content in your preferred language

Retrieve attributes of a feature when clicked

826
2
Jump to solution
05-22-2012 12:43 PM
YohanBienvenue
Frequent Contributor
Hi,

Here is a screenshot of my map, where a feature in the map is clicked and an InfoTemplate is displaying the attributes for that feature.

[ATTACH=CONFIG]14527[/ATTACH]

What I want to do is when I click one of the buttons in my InfoTemplate, I want to save the attributes of the feature I just clicked moments before. How do I know what feature I just clicked?


One idea I had was maybe assign a click handler for the layer graphics, but since the features are obtained from a REST map service (which is an asynchronous request) I cannot figure out when to make this assignment since I don't know exactly when the graphics have all been added to the map.

Thanks
0 Kudos
1 Solution

Accepted Solutions
StephenLead
Honored Contributor
I want to save the attributes of the feature I just clicked moments before. How do I know what feature I just clicked?


There are probably a bunch of ways you could approach this - here is one suggested method:

dojo.connect(featureLayer, "onClick", function(evt) {   console.log(evt.graphic.attributes); });


Steve

View solution in original post

0 Kudos
2 Replies
StephenLead
Honored Contributor
I want to save the attributes of the feature I just clicked moments before. How do I know what feature I just clicked?


There are probably a bunch of ways you could approach this - here is one suggested method:

dojo.connect(featureLayer, "onClick", function(evt) {   console.log(evt.graphic.attributes); });


Steve
0 Kudos
YohanBienvenue
Frequent Contributor
There are probably a bunch of ways you could approach this - here is one suggested method:


Yes this method will work for what I want to do..
And I don't know how I missed this in the API documentation. I remember seeing the setAttributes method and thinking "why isn't there a getAttributes too? That would be useful". Somehow I missed it in the properties..
I blame influenza

Thanks Steve 🙂

Yohan
0 Kudos