Arcade Expression Help-Conditional Table

3419
10
Jump to solution
04-28-2018 10:31 PM
SteveCole
Frequent Contributor

I'm having trouble implementing what I want as a popup for a point layer. The points represent physical locations and basically store URLs to photos and video of the location. There are five photo URLfields (photo01, photo02, photo03, photo4, photo5) and five video URL fields (video01, video02, video03, video04, video05).

A site may have UP TO 5 photos or videos or it may have none. Because of this, ideally I'd like the attributes to adjust accordingly. For example, if a site has no photos and 2 videos, the popup would look like this:

Photos:

No Photos currently. Please Check back

Video:

Video 01: <url>

Video 02: <url>

I have some expressions which help me determine if the field is empty but I can't figure out how to incorporate that into a dynamic table in the popup.

Here'e the actual service layer link.

Any ideas?

Steve

0 Kudos
1 Solution

Accepted Solutions
KellyGerrow
Esri Frequent Contributor
10 Replies
KellyGerrow
Esri Frequent Contributor

Hey Steve,

Check out this blog, it may point you in the right direction:

https://community.esri.com/community/gis/web-gis/arcgisonline/blog/2017/07/18/conditional-field-disp...

-Kelly

SteveCole
Frequent Contributor

Thanks, but no- not really. I understand using Arcade, to a point, but AGOL doesn't seem to honor the HTML formatted output that I generate.

Here's my Arcade expression:

// Write a script to return a value to show in the pop-up.
// For example, get the average of 4 fields:
// Average($feature.SalesQ1, $feature.SalesQ2, $feature.SalesQ3, $feature.SalesQ4)

var popupText = '<b>Location: ' + $feature.unitName + '</b><br /><br /><b>360 Degree Photos:</b><table>';
var counter=0;
var tableText = '';
var chkPhoto01Field = IsEmpty($feature["VR_IMG_URL"]);
var chkPhoto02Field = IsEmpty($feature["VR_IMG_U_1"]);
var chkPhoto03Field = IsEmpty($feature["VR_IMG_U_2"]);
var chkPhoto04Field = IsEmpty($feature["VR_IMG_U_3"]);
var chkPhoto05Field = IsEmpty($feature["VR_IMG_U_4"]);
var finalText = '';

if (chkPhoto01Field) {
counter = counter+1;
tableText = tableText + '<tr><td>Photo ' + counter + ':</td><td><a href="' + $feature["VR_IMG_URL"] + '" target="_blank">Click to View</a></td></tr>';
}

if (chkPhoto02Field) {
counter = counter+1;
tableText = tableText + '<tr><td>Photo ' + counter + ':</td><td><a href="' + $feature["VR_IMG_U_1"] + '" target="_blank">Click to View</a></td></tr>';
}

if (chkPhoto03Field) {
counter = counter+1;
tableText = tableText + '<tr><td>Photo ' + counter + ':</td><td><a href="' + $feature["VR_IMG_U_2"] + '" target="_blank">Click to View</a></td></tr>';
}

if (chkPhoto04Field) {
counter = counter+1;
tableText = tableText + '<tr><td>Photo ' + counter + ':</td><td><a href="' + $feature["VR_IMG_U_3"] + '" target="_blank">Click to View</a></td></tr>';
}

if (chkPhoto05Field) {
counter = counter+1;
tableText = tableText + '<tr><td>Photo ' + counter + ':</td><td><a href="' + $feature["VR_IMG_U_4"] + '" target="_blank">Click to View</a></td></tr>';
}

if (counter==0) {
tableText = '<tr><td colspan="2">No Content Currently. Please check back.</td></tr>';
}

finalText = popupText + tableText + '</table>';

return finalText;

and here's the resulting popup:

And here's how I set up the popup output:

Popups support HTML formatting but the end output just treats it as literal text.

0 Kudos
SteveCole
Frequent Contributor

UPDATE:

I rethought how my URLs are stored in my data which better positioned me to try the technique from the blog post. The results are close to what I want but not quite. Here's the HTML table in the popup config:

<table cellpadding="0px" cellspacing="3px">
<tbody>
<tr valign="top">
<td><b>Photos:</b></td>
<td> </td>
</tr>
<tr valign="top">
<td><b>{expression/expr8}</b></td>
<td><a href="{VR_IMG_URL}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr9}</b></td>
<td><a href="{VR_IMG_U_1}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr10}</b></td>
<td><a href="{VR_IMG_U_2}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr11}</b></td>
<td><a href="{VR_IMG_U_3}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr12}</b></td>
<td><a href="{VR_IMG_U_4}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>Videos:</b></td>
<td> </td>
</tr>
<tr valign="top">
<td><b>{expression/expr13}</b></td>
<td><a href="{VR_VID_URL}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr14}</b></td>
<td><a href="{VR_VID_U_1}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr15}</b></td>
<td><a href="{VR_VID_U_2}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr16}</b></td>
<td><a href="{VR_VID_U_3}" target="_blank">Click to View</a></td>
</tr>
<tr valign="top">
<td><b>{expression/expr17}</b></td>
<td><a href="{VR_VID_U_4}" target="_blank">Click to View</a></td>
</tr>
</tbody>
</table>

As you can see, it correctly notes that there is 1 photo and 1 video for this location but it does not hide the row from the table if the URL field is blank. The links for the valid media are correct & work and the links that shouldn't appear are "about:blank".

I'm using the same IIF logic per the blog post for each URL field. Example:

IIF(isEmpty($feature["VR_IMG_URL"]), "", "Photo 1:")

0 Kudos
KenBuja
MVP Esteemed Contributor

Your data has some inconsistencies. I tried two different IIF statements in different expressions.

IIF(IsEmpty($feature["VR_IMG_U_1"]), 'Not Present', "Photo 1") ("Is Empty" popup field)

and

IIF($feature["VR_IMG_U_1"] != ' ', 'Photo1', "Not Present") ("Quoted" popup field)

and I'm seeing different responses for different points. Here's the popups for two different points.

So then I added another expression to make the spaces visible

Replace($feature["VR_IMG_U_1"], " ", "x")

Here are the two popups again

SteveCole
Frequent Contributor

Yes- I noticed an issue last night with the fields and thought I had fixed them prior to my last post. I discovered that the URL fields that I thought were empty actually contained a space. I attempted to remove them from my hosted layer but perhaps I did not do so correctly. I can update my hosted layer once I look at it in Arcmap. That does bring up something I discovered while working on this last night. There is no length function within Arcade, and that would have been more helpful for me instead of using isEmpty. I could have just evaluated a length > 3 to determine the presence of a URL in the field but alas.

0 Kudos
KenBuja
MVP Esteemed Contributor

Search for the "https" in the fields using Find instead.

SteveCole
Frequent Contributor

Roundabout way but, yeah, that would work. Thanks.

0 Kudos
KenBuja
MVP Esteemed Contributor

Not really roundabout. You'd use the same logic as your previous IIF statement.

IIF(Find('https', $feature["VR_IMG_U_1"]) > -1, 'Photo 1', 'Not Present')

SteveCole
Frequent Contributor

I meant that I was focused on looking at the length of field's value to determine if it was populated that I hadn't even considered that you could also just query for part of the URL and get the same, reliable (if not more accurate) result. Hopefully this change will get things the way I want. I'll check it out later today. Thanks again.

0 Kudos