It can be kind of tricky to do this and have it formatted nicely, but here's a way to do it:
var x = $feature['attribute']
if(!IsEmpty(x)){
return `\nSome Attribute: ${x}`
}
Then in the popup configuration, put all the expressions on the same line. The \n in the returned string will separate multiple values.
To show what this might look like in practice, I'll use a static dict instead of the feature's attributes so that you can see the skipped values. My input:
var d = {
'first': 'the first value',
'second': null,
'third': null,
'fourth': 'and the fourth'
}
And the popup configuration:
And the resulting popup:
You'll have to do extra work if you want the output to look nice or have a tabular alignment, but this can at least give you a list of non-null / non-empty attributes in your feature that won't leave blank spaces.
EDIT: It occurred to me after posting that that there's no need for multiple expressions. If you build a dict from the attributes you want, you can return a single string with all the attributes in one go:
var attrs = {
'First': $feature['attribute1'],
'Second': $feature['attribute2'],
'Third': $feature['attribute3']
}
out_str = 'Attributes:'
for(var a in attrs){
if(!IsEmpty(attrs[a])){
out_str += `\n${a}: ${attrs[a]}`
}
}
return out_str
- Josh Carlson
Kendall County GIS