Hello! I have an AGOL hosted feature layer for park amenities. Each amenity is in it's own field and each park that has any of the amenities, have been set with a domain of YES or NO. I hope to be able to have the pop up show a simple list of the amenities that exist at each park but not the amenities that are not. I then hope for people to be able to search for a park based on the amenities that they are interested in having access to.
I was trying to use a tutorial that I found on YouTube but it didn't work for what I am trying to do. Any feedback and advice would be greatly appreciated.
Below is an example of what my data table looks like if that is helpful.
There are a few ways you might tackle this. Considering you want to run a similar check for each attribute, it makes sense to use a loop here. We'll iterate over a feature's attributes, and if the value is "Yes", we'll add it to a string, then return the full string at the end.
var out_str = 'Amenities available:'
for (var attr in $feature){
if ($feature[attr] == 'Yes'){
out_str += `\n${attr}`
}
}
return out_str
Testing this against a sample feature as follows:
EDIT: I noticed your post referenced a domain. Just be sure that the if condition references the actual value, not the label, so "YES" or 1, or whatever you happen to be using.
Thank you so much Josh!
So, this is what I have so far, however I seem to be missing something when it comes to returning the name of the field. Ignorance is sometimes bliss, but sometimes it's not. 😄
Oh, note that the added string is in backticks, not single quotes. ` instead of '. It's next to the 1 key.
In Arcade, as in JavaScript, a backtick string allows you to access variables and other values within a ${...} inside of the string.
EDIT: You could also do out_str += '\n' + attr. We want to add "attr" to the string, as that will reference the key (the attribute name) as opposed to its value.
So this isn't working for me. Not sure what I'm doing wrong. So I tried to do an IF/ELSE statement but that didn't work either. I am horrible at stuff like this.
Is the layer public? I could pull it into a web map and make a similar attempt using the same data you're working with.