Use dictionary to configure pop-up?

1115
2
05-31-2019 02:16 PM
ChrisWiebke
New Contributor III

I would like to display text in a pop-up that is based on a dictionary.  Can i write an arcade if statement that compares the attribute to the dictionary "value", then return the dictionary "label" in the pop-up?  I am not very familiar with javascript and unsure how to test for the attribure value equal to the dictionary "value".  for example, I have this so far:

var dict = [{label: "N-1", value: "001"},
{label: "N-2", value: "002"},
{label: "N-4", value: "004"},
{label: "N-5", value: "005"}],

for(var k in dic){
var kValue = dic.value;
var kLabel = dic.label;
var routeid = $feature.FIRST_RouteID;
var popup = IIF(routeid == kValue ,kLabel,"NoVal");
return popup;
}

this is returning "N-1" when i test the result, but does not work when clicking on a feature.  It must not be looping through the dictionary like I think it should?

I solved this by changing my array variable and using the When function like so:

var routeid = $feature["FIRST_RouteID"];
var routeLabel = When(
routeid == "001","N-1",
routeid == "002","N-2",
routeid == "004","N-4",

routeid == "S93A","S93A",
'n/a')
return routeLabel

Thanks,

Chris

0 Kudos
2 Replies
KenBuja
MVP Honored Contributor

Take a look at this discussion that uses dictionaries in Arcade

XanderBakker
Esri Esteemed Contributor

You should probably format your dictionary differently and change your code:

var dict = {"001":"N-1", "002":"N-2", 
            "004":"N-4", "S93A":"S93A"};

var example_val = "002";
if (HasKey(dict, example_val)) {
    return dict[example_val];
} else {
    return "n/a";
}

This example will return "N-2"...