Select to view content in your preferred language

Conditional Arcade Expression

598
2
04-04-2024 02:14 PM
Labels (2)
ShawnWampler
Occasional Contributor

Hello, I'm trying to create a popup that includes a URL to report a problem based on a field.  If the user chooses a State Road my pop up indicates that the road is maintained by the State but I want to include a URL to report a problem to the State.  If the road is maintained by the City I want a different URL for those problems.  Then I have some roads that are private that I do not wish to include a URL at all.  I have a working maintenance expression to show the maintenance but I'm not sure how to show only certain jurisdictions having a URL.    Thanks in advance for any help!

if ( $feature.MAINTENANCE == "CITY" ) {
return "The City of Annapolis  "
}
else if ( $feature.MAINTENANCE == "PRIVATE") {
return "A Private Entity"
}
else if ( $feature.MAINTENANCE == "STATE" ) {$feature
return "State Highway Adminstration"
}
else if ( $feature.MAINTENANCE == "NAVAL ACADEMY" ) {$feature
return "United States Naval Academy"
}
else if ( $feature.MAINTENANCE == "COUNTY" ) {$feature
return "Anne Arundel County"
}
else if ( $feature.MAINTENANCE == "FUTURE (CITY)" ) {$feature
return "Private but future City"
}
else {

return "UNKNOWN"

}


0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

You'll want to use an Arcade popup element for this, where you can include HTML.

Also, when you're series of if/else/then statements are nice and simple like this, you can replace them with a When statement. "When(condition1, response1, ... conditionN, responseN, fallback_response)"

However, when your conditions all use the same field, you can also just replace it with Decode. "Decode(field, value1, response1... valueN, responseN, fallback_response)"

var maintainer = Decode(
  $feature.MAINTENANCE,
  'CITY', '<a href="link to city URL">The City of Annapolis</a>',
  'STATE', '<a href="link to state URL">State Highway Administration</a>',
  'PRIVATE', 'A Private Entity', // no link on this one!
  'NAVAL ACADEMY', '<a href="link to academy URL">United States Naval Academy</a>',
  'COUNTY', '<a href="link to county URL">Anne Arundel County</a>',
  'FUTURE (CITY)', 'Private but future City',
  'UNKNOWN'
)

return {
  type: 'text',
  text: maintainer
}

 

- Josh Carlson
Kendall County GIS
CarsonMorton
Regular Contributor

I don't know if this works for the original poster, but hot diggity dog I am saving this for later! (both the Decode and the HTML)

0 Kudos