I'm currently using arcade in a popup to combine 4 fields into a single line in one field. This code below works but I'd like to make it better/cleaner, since it's possible that the "GPS" field is empty. I'm sure there is a way to write what is in the GPS field in parenthesis only if it has text in it, and not write anything if it is empty. I'm new to arcade and just struggling on how to write the logic for when and if statements.
Currently if the GPS field doesn't have text in it the code writes:
SiteName (): Lat, Long
Trying to get to:
If GPS does have text in it: SiteName (GPS abbreviation): Lat, Long
If GPS does not have text in it: SiteName: Lat, Long
var oneline = $feature.Site + " (" + $feature.GPS + "): " + $feature.Latitude + ", " + $feature.Longitude
return oneline
Solved! Go to Solution.
I left missed the closing parenthesis for the GPS text. Since I can't edit my post, it's updated here
IIf (IsEmpty($feature.GPS),
`${$feature.Site}: ${$feature.Latitude}, ${$feature.Longitude}`,
`${$feature.Site} (${$feature.GPS}): ${$feature.Latitude}, ${$feature.Longitude}`
)
You can do that this way. This uses an implicit return and template literals
IIf (IsEmpty($feature.GPS),
`${$feature.Site}: ${$feature.Latitude}, ${$feature.Longitude}`,
`${$feature.Site} (${$feature.GPS}: ${$feature.Latitude}, ${$feature.Longitude}`
)
I left missed the closing parenthesis for the GPS text. Since I can't edit my post, it's updated here
IIf (IsEmpty($feature.GPS),
`${$feature.Site}: ${$feature.Latitude}, ${$feature.Longitude}`,
`${$feature.Site} (${$feature.GPS}): ${$feature.Latitude}, ${$feature.Longitude}`
)
Thank you so so much!!