Select to view content in your preferred language

Getting multiple feature fields and using them in a Text popup

302
2
Wednesday
RogerDunnGIS
Frequent Contributor

I am in an ArcGIS Enterprise 11.5 Map Viewer. The map contains a Parcels feature layer and an Elementary School Boundaries layer, among others.

I have configured the parcel layer with a pop-up Arcade expression to grab information about the elementary school whose boundary includes the clicked parcel. The elementary school attribute table has a NAME field and URL field.  I would like to later show the user the NAME of the school, with a hyperlink that takes the user to the school's URL.

This is the basis for the code I'm using:

var layer_name = "Elementary School Boundaries";
var field_names = ["Name", "URL"];

var layer = FeatureSetByName($map, layer_name, field_names, false);
var pinhole = Intersects($feature, layer);
var value = Null;

if (!IsEmpty(pinhole))
  value = First(pinhole);
return value;

 

This code returns a Feature, but I've also tried returning a Dictionary, as well as a complete HTML anchor string, but nothing works.  Anyway, the resulting expression is given the value {expression\expr7}

The popup HTML looks a little like this, but I've tried a number of variations:

<ul>
    <li>
        <span style="color:#000000;">Elementary: </span><span style="color:#0088ff;"><a href="{expression/expr7?.URL}" target="_blank">{expression/expr7?.NAME}</a></span>
    </li>
</ul>

 

The anchor tag gets erased by the formatter (meaning, when I click the <> button to get out of code mode) and no text is displayed in the 0088ff color.  If my Arcade code is modified to return a full anchor tag such as:

<a href="https://someschool.org" target="_blank">Some Elementary School</a>

I then modify the HTML to look like this:

<ul>
    <li>
        <span style="color:#000000;">Elementary: </span><span style="color:#0088ff;">{expression/expr7?.NAME}</span>
    </li>
</ul>

Then what happens is that the anchor tag, URL, and school name appear as-is to the user in the pop-up.

A work-around for this problem is to create TWO expressions, both of which mainly have the same code except one expression grabs the NAME and the other grabs the URL.  I've gotten that to work.  But that means two spatial intersections when I only want one.  Please note that I want to do this to many other layers in the map, and I don't want ArcGIS to do twice the work.  I simply want to fetch two fields from each layer and to use those two fields to construct hyperlinks.

 

 

0 Kudos
2 Replies
Neal_t_k
MVP Regular Contributor

Have you tried formatting the HTML inside the arcade instead of in the source code for the popup?

something like this:

var layer_name = "Elementary School Boundaries";
var field_names = ["Name", "URL"];

var layer = FeatureSetByName($map, layer_name, field_names, false);
var pinhole = Intersects($feature, layer);
var value = Null;

if (!IsEmpty(pinhole)) {
  value = First(pinhole);
}

if (value == Null) {
  return {
    type: 'text',
    text: "No intersecting school boundary"
  };
}

var link = "<a href='" + value.URL + "' target='_blank'>" + value.Name + "</a>";

return {
  type: 'text',
  text:
    "<ul>" +
      "<li>" +
        "<span style='color:#000000;'>Elementary:</span> " +
        "<span style='color:#0088ff;'>" + link + "</span>" +
      "</li>" +
    "</ul>"
};
0 Kudos
EMani
by Esri Contributor
Esri Contributor

Hi @RogerDunnGIS 

Complex popups are easier to split between HTML, Text elements and expressions. So you have 3 levels of configuration. My example is a bit simpler with only 2 values, but the idea is similar.

I have a field named {StatusText}

In the Text content, I have just added {StatusText} with this HTML to include the expression.

 <p style="text-align:center;">
        <span style="font-family:Courier;font-size:18px;"><span><strong>Status </strong>is </span></span><span style="color:{expression/expr2};font-family:Courier;font-size:24px;"><span><strong>{StatusText}</strong></span></span>
    </p>

My expression is:

if ($feature.StatusText == '1') {  

    return "#FF5500" // Red 

}  

else {

 return "#4CE600" // Green 

}


Take the link part out of the expression and link the expression field directly in the text content.

Make sure you click the green tick, not just enter, or the link tends to disappear.

EMani_2-1781782416298.png

Here's a great blog that explains why ArcGIS Online scrubs the HTML without warning.

Create pop-ups that perform in ArcGIS Online
There’s lots more HTML you can use for behind the scenes, like trialling font families. Just keep in mind that it must be supported by the ArcGIS framework. If it isn’t, the code you write will be scrubbed before saving. So, unless it’s spring cleaning, check before your code disappears. Or, try this workaround.

0 Kudos