Select to view content in your preferred language

Arcade expressions not working in pop-ups

960
5
Jump to solution
12-20-2021 10:38 AM
SepheFox1
Regular Contributor

For some reason, the arcade expression I am using to convert wind directions from degrees to compass rose letters, which works perfectly in Map Viewer is not working properly in Dashboard. When a feature is identified on, the pop-up always shows the wind direction as "N", no matter what the actual compass value. In Map Viewer it converts the compass direction to the correct corresponding letters. Oddly, it also works correctly in Dashboard when that  same layer is added to a "Details" window, with the wind direction being displayed with correct compass directions, such as N, NE, S, SE, etc.

The expression I am using is:

var lookup = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SSE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N']
lookup[ Round(Number( Split( Text( $feature["WIND_DIRECT"] / 11.25), '.')[0]) / 2)]

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

That does seem odd that your expression wouldn't work in certain settings.

I really like the concise approach you've got, but could you try it as a series of conditional statements instead, to see if that works any better?

var d = $feature["WIND_DIRECT"];
var outstr;

if (d < 11.25){
    outstr = 'N'
} else if (d < 33.75) {
    outstr = 'NNE'
}
... and so on.

Or perhaps get your lookup index a little simpler?

var d = Floor(($feature["WIND_DIRECT"]+ 11.25) / 22.5)

var lookup = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SSE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N']

return lookup[d]
- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
jcarlson
MVP Esteemed Contributor

That does seem odd that your expression wouldn't work in certain settings.

I really like the concise approach you've got, but could you try it as a series of conditional statements instead, to see if that works any better?

var d = $feature["WIND_DIRECT"];
var outstr;

if (d < 11.25){
    outstr = 'N'
} else if (d < 33.75) {
    outstr = 'NNE'
}
... and so on.

Or perhaps get your lookup index a little simpler?

var d = Floor(($feature["WIND_DIRECT"]+ 11.25) / 22.5)

var lookup = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SSE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N']

return lookup[d]
- Josh Carlson
Kendall County GIS
SepheFox1
Regular Contributor

Josh, thank you so much. I went with your second idea and it did fix the issue. Not only that, but it fixed the other issue I was having, which was the wrong feature attributes would appear on the pop-up. This is my first foray into using arcade, so I have a lot to learn.

0 Kudos
jcarlson
MVP Esteemed Contributor

You're welcome, and I'm glad it took care of two problems at once! Arcade is pretty nice once you get the hang of it. The Arcade Playground is a really nice page to just test out different functions and get familiar with it.

- Josh Carlson
Kendall County GIS
0 Kudos
SepheFox1
Regular Contributor

Thank you! I was trying to play in the Arcade Playground, but I couldn't understand how to reference layers in order to use the fields as Globals. What am I missing there?

0 Kudos
jcarlson
MVP Esteemed Contributor

You have to choose a Profile, so that the playground mimics writing expressions for popups, for example, as opposed to labelling. Arcade's capabilities change depending on where it's being used.

jcarlson_0-1640029953891.png

 

- Josh Carlson
Kendall County GIS
0 Kudos