I have a layer with about 50 fields that show up as 50 rows in the popup. Most of these are Null values.
Is there a way to create an expression that will set it up to not show the fields with Null values in the popup without typing 50 expressions?
I've seen HTML solutions and ideas for Map Viewer Classic but I'm using the New Map Viewer.
Thanks to all.
Yes! You can do this very easily with an Arcade popup element and a single expression. You can build a fields list object programmatically and check for nulls and skip them.
The simplest approach is to just iterate over every attribute in a feature:
var fieldInfos = []
var attributes = {}
for (var att in $feature) {
if (!IsEmpty($feature[att])) {
Push(fieldInfos, {fieldName: att})
attributes[att] = $feature[att]
}
}
return {
type: 'fields',
title: 'An Expression to Skip Nulls',
fieldInfos,
attributes
}
Here it is in action, with a regular fields list to show it working:
If you have certain fields you want to skip, you can code those in, too. It sounds like there are a lot of attributes you want to catch, so I don't know if it's going to be faster to grab *everything* and then remove ones you don't want, or to manually define the list of attributes you do want. But this should get you started.
I noticed that your code doesn't show the field aliases (if they are present). Here's a modification that shows them.
var fieldInfos = []
var attributes = {}
var fields = Schema($feature).fields
for (var att in $feature) {
if (!IsEmpty($feature[att])) {
var alias = att;
for (var i in fields){
if (fields[i].name == att) alias = fields[i].alias
}
Push(fieldInfos, {fieldName: alias})
attributes[alias] = $feature[att]
}
}
return {
type: 'fields',
title: 'An Expression to Skip Nulls',
fieldInfos,
attributes
}
Good addition!
Hey @jcarlson ,
I am trying to use your code but my popup does not look anything like what you are showing. My popup only shows gloablId, objectID, and one other attribute from the layer. I changed the code just to return attributes but that only results in the 3 attributes I mention of about 100, that could have data. Curious if you might have any suggestions?
Thanks
I have a layer with about 50 fields that show up as 50 rows in the popup. Most of these are Null values.
Is there a way to create an expression that will set it up to not show the fields with Null values in the popup without typing 50 expressions?
I've seen HTML solutions and ideas for Map Viewer Classic but I'm using the New Map Viewer.
Thanks to all.
This is how I've accomplished this, its a little manual since you have to add the fields induvial but it loads quickly and works well for our applications (add an arcade element then add the code to that):
Do you know how I would add rounding to this? I tried something like-
'Flow Rate': round($feature.flow, 2)
in the return section but that doesn't seem to do anything.