Created
April 6, 2023 16:43
-
-
Save stdavis/d7167f31bcdbc457e7f75d486fe75d95 to your computer and use it in GitHub Desktop.
RTP Popup Arcade Expression Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is because the webmap can't parse our code for the fields that we are | |
// using since they are buried in field info dictionaries. | |
// This could be optimized to include only the fields that you use below | |
Expects($feature, '*'); | |
// I can't believe that arcade doesn't define an expression like this! | |
function concat(target, source) { | |
for (var i in source) { | |
Push(target, source[i]); | |
} | |
} | |
var commonFields = [ | |
{ | |
fieldName: 'begin_place', | |
label: 'From', | |
}, | |
{ | |
fieldName: 'end_place', | |
label: 'End', | |
}, | |
{ | |
fieldName: 'mode', | |
label: 'Mode', | |
}, | |
]; | |
if ($feature.mode == 'Highway') { | |
var highwayFields = [ | |
{ | |
fieldName: 'current_lanesTEXT', | |
label: 'Current Lanes', | |
}, | |
{ | |
fieldName: 'region', | |
label: 'UDOT Region', | |
}, | |
]; | |
concat(commonFields, highwayFields); | |
} | |
var additionalFields = [ | |
{ | |
fieldName: 'route_name', | |
label: 'Route Name', | |
}, | |
]; | |
concat(commonFields, additionalFields); | |
// just so that we can see what fields are available... | |
Console($feature); | |
return { | |
type: 'fields', | |
fieldInfos: commonFields, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can see this expression in action in the popup config for the "Lines Displayed by Mode" layer in this webmap.