WebMap Arcade how to hide a field that do not have values in a popup window

1961
8
08-05-2021 10:25 AM
JoseSanchez
Occasional Contributor III

Hello everyone,

 

In a WebMap I am looking for a way to  hide a field when it does not have values, and show it when it has values in a Popup window, when clicking in  feature on the webmap.

 

Thanks

 

0 Kudos
8 Replies
JayantaPoddar
MVP Esteemed Contributor

Please check the following blog Hide Field in Pop-up Using Arcade 



Think Location
jcarlson
MVP Esteemed Contributor

I can't believe I missed that blog post! That's a really useful example, one that I will be using in a number of maps.

- Josh Carlson
Kendall County GIS
0 Kudos
jcarlson
MVP Esteemed Contributor

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:

jcarlson_0-1628186774917.png

And the resulting popup:

jcarlson_1-1628186796369.png

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

 

jcarlson_0-1628187415289.png

 

- Josh Carlson
Kendall County GIS
BrianBaldwin
Esri Regular Contributor

Here is a simple example that could work:

var FIRE = $feature.FIRE
var popuptext = ''

If(FIRE=='Yes'){
    popuptext = 'There is a fire here.';
}

return popuptext

-----------------------------------

Brian Baldwin, Esri Inc., Lead Solution Engineer
https://www.linkedin.com/in/baldwinbrian
0 Kudos
JoseSanchez
Occasional Contributor III

Thank you for your samples.

 

Now how can I make the field clickable, because what I want to show/hide is a ProjectURL

Thanks

0 Kudos
jcarlson
MVP Esteemed Contributor

Well, that is a very different thing. If you want clickable links, you have to do it one expression per field, there's just no way to get the "<a href=...>" HTML tags into a dynamic list within a single expression. Configuring a popup to show "<a href={expression/expr0}>{expression/expr0</a>" works, where the expression returns a valid URL.

However, if the popup was "{expression/expr0}", where the expression returns all the <a href...></a> tags within it, that will not work, as the HTML tags will be read and displayed as text characters. With that in mind, you could try:

  1. Write an expression for each URL field that only returns something if there's a value.
  2. In the popup, define a link to have the text and URL come from that expression.

jcarlson_0-1628189619074.png

There's no way to get the newline character into the link, however, so you'll be once again stuck with either a really long horizontal string of text, or a tall list with empty rows.

Add to this the fact that your URLs may be long, and you may wish to display some other text. If you wish to do that, you'll need TWO expressions per field, one for the URL, one for the link text.

PS - Sorry for accepting and then unaccepting your post as a solution, I was meaning to click "reply". 😬

EDIT: You could probably get nicer URL labels with one expression per field using the method in the blog post @JayantaPoddar linked to.

- Josh Carlson
Kendall County GIS
JoseSanchez
Occasional Contributor III

Thanks Josh,

Your first sample worked for me.  

I only have one field that has URL values in my Popup window. And I am not using the table HTML, just the default  custom text display.  Now it show as a text field, I need to find a way to make if clickable.

 

 

 

var relatedrecords = OrderBy(FeatureSetByRelationshipName($feature,"CIPProject"), "ProjectURL")

var cnt = Count(relatedrecords);
var relatedinfo = "";
if (cnt > 0) {
var info = First(relatedrecords);
relatedinfo = info.ProjectURL ;
}

return relatedinfo;

 

0 Kudos
JoseSanchez
Occasional Contributor III

Hello again,

I was able to convert the field to a hyperlink field. I just selected the field, added hyperlink and copied {relationships/0/ProjectURL}" inside.

Thanks