Select to view content in your preferred language

Console.log attributes of selected features

1893
6
Jump to solution
12-27-2021 04:50 AM
Vakhtang_Zubiashvili
Frequent Contributor

Hi guys,

 

I am going to use this sample to select features on my map and display attributes in my custom html table, so for the first step i want to show selected results in console.log().

In 269 line i added console.log(results.features.attributes.unit_name) , but it returns undefined. 

How can i get selected features attributes?

 

Thanks

 

0 Kudos
1 Solution

Accepted Solutions
Kishore
Frequent Contributor

@Vakhtang_Zubiashvili  - Please add following code to display the attributes:

results.features.forEach((feature)=>{console.log(feature.attributes["unit_name"]);});

You cannot get the attributes for the collection. you have to loop through the array and display the attribute values.

 

Regards,
Kishore

View solution in original post

6 Replies
Kishore
Frequent Contributor

@Vakhtang_Zubiashvili  - you code pen sample is not working as you share the editor URL. please share the code her to check.

 

Regards,
Kishore
0 Kudos
Vakhtang_Zubiashvili
Frequent Contributor

Thanks Kishore, i have changed link.

0 Kudos
Kishore
Frequent Contributor

@Vakhtang_Zubiashvili  - Please add following code to display the attributes:

results.features.forEach((feature)=>{console.log(feature.attributes["unit_name"]);});

You cannot get the attributes for the collection. you have to loop through the array and display the attribute values.

 

Regards,
Kishore
Vakhtang_Zubiashvili
Frequent Contributor

Thanks Kishore, 

But after i do other features selection, it returns previous selection + current selection,  i want to get only current selection 😞 

0 Kudos
Kishore
Frequent Contributor

@Vakhtang_Zubiashvili  - 

Clear the graphics before you draw the sketch. add following in line 219

polygonGraphicsLayer.removeAll();

 

Regards,
Kishore
Vakhtang_Zubiashvili
Frequent Contributor

Thanks Kishore, it works like a charm ❤️

0 Kudos