Select to view content in your preferred language

Arcade - Return list of values from a dictionary in popup

3119
2
Jump to solution
03-23-2022 10:00 PM
Labels (1)
TKPAdmin
New Contributor II

I'm new to Arcade and hoping for some advice and examples on where to start...

I have a field with numeric values  e.g 1, 3 , 5. In the popup I want to replace these values with their descriptions. The field may contain one or many values for each location. I'm assuming I add the values and description to a dictionary and then split the field by comma, add to an array and return the list? I'm just not sure what that looks like! Any help gratefully received. 

 

1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You assume right.

// define your decode dictionary
var decode_dict = {
    "1": "a",
    "3": "c",
    "5": "e"
}

// get an array of your coded values
// here, I'm removing spaces from the field and then split by comma
var coded_values = Split(Replace($feature.Field, " ", ""), ",", -1, true)

// create an empty array and append the decoded values
var decoded_values = []
for(var i in coded_values) {
  Push(decoded_values, decode_dict[coded_values[i]])
}

// convert the array to string (here, I concatenate with comma) and return
return Concatenate(decoded_values, ", ")

 

The ArcGIS Developer page for Arcade is a good place to start:

Getting Started | ArcGIS Arcade | ArcGIS Developer

I find the function reference especially important, this is a page that I have bookmarked:

Function Reference | ArcGIS Arcade | ArcGIS Developer

If you want to play around, you can do so in the Arcade Playground:

Playground | ArcGIS Arcade | ArcGIS Developer

If you're looking for examples, there is a Github with Arcade expressions for diffferent profiles:

GitHub - Esri/arcade-expressions: ArcGIS Arcade expression templates for all supported profiles in t...


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

You assume right.

// define your decode dictionary
var decode_dict = {
    "1": "a",
    "3": "c",
    "5": "e"
}

// get an array of your coded values
// here, I'm removing spaces from the field and then split by comma
var coded_values = Split(Replace($feature.Field, " ", ""), ",", -1, true)

// create an empty array and append the decoded values
var decoded_values = []
for(var i in coded_values) {
  Push(decoded_values, decode_dict[coded_values[i]])
}

// convert the array to string (here, I concatenate with comma) and return
return Concatenate(decoded_values, ", ")

 

The ArcGIS Developer page for Arcade is a good place to start:

Getting Started | ArcGIS Arcade | ArcGIS Developer

I find the function reference especially important, this is a page that I have bookmarked:

Function Reference | ArcGIS Arcade | ArcGIS Developer

If you want to play around, you can do so in the Arcade Playground:

Playground | ArcGIS Arcade | ArcGIS Developer

If you're looking for examples, there is a Github with Arcade expressions for diffferent profiles:

GitHub - Esri/arcade-expressions: ArcGIS Arcade expression templates for all supported profiles in t...


Have a great day!
Johannes
TKPAdmin
New Contributor II

That's great. Thanks for your help Johannes. 

0 Kudos