Skip to content

Instantly share code, notes, and snippets.

@stdavis
Created April 6, 2023 16:43
Show Gist options
  • Save stdavis/d7167f31bcdbc457e7f75d486fe75d95 to your computer and use it in GitHub Desktop.
Save stdavis/d7167f31bcdbc457e7f75d486fe75d95 to your computer and use it in GitHub Desktop.
RTP Popup Arcade Expression Example
// 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,
};
@stdavis
Copy link
Author

stdavis commented Apr 6, 2023

You can see this expression in action in the popup config for the "Lines Displayed by Mode" layer in this webmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment