How can we help? How can we help?
How can we help?

Drop us a line and we’ll get back to you asap!

    Thank you for your inquiry with DVG! We will reach out as soon as possible.

    Arcade is a scripting language that Esri developed for use within the ArcGIS platform for creating custom labeling expressions and calculations. It allows to you make calculations, perform geometry functions, and dynamically style labels without actually editing your database. One very useful feature is the ability to add content to pop-ups for layers within and ArcGIS Online web map. This two-part blog will demonstrate and discuss several ways of using Arcade expressions to add useful information to a layer’s pop-up that do not exist as attributes in the layer itself. This two-part post will demonstrate 1) adding attributes from a related layer, and 2) calculating a new attribute from a related layer then 3) on an unrelated layer in the same map using a common attribute, and 4) by performing an on-the-fly spatial overlay.

    To illustrate this, I have created a simple ArcGIS Online web map with New Jersey address data. This map has an Address Points layer (Hudson County Addresses) which represents a single feature for each building address and has a related Address Units table with individual units in a 1:M relationship.

    Attributes from a Related Table

    The Hudson County Addresses data represent a single point feature for each building address and has a related table with individual units, Address Units, in a 1:M relationship. The unit table has minimal data in it, just two fields: Unit and ADDR_ID to join it to relate it to the address point record. This is a good data structure as you don’t want to store and maintain duplicate information in multiple place. The bulk of the address information lives in the address point layer: Full Address, Municipality, Postal Code, County, etc. Since these attributes are not part of the Address Units table they are not in the attribute table. If you go into the configuration of the pop-up you will see the fields from the relationship listed, but you cannot add the values within those fields themselves, only a Statistic Operator of the related record(s) such as count or sum.

    ArcGIS Online layer Configure Attribute window showing fields from related layer and Statistic Operator options

    While is useful for other purposes, it doesn’t help me here. This where Arcade comes in. I can write an Arcade expression to grab the values from the related address point record and add to the attribute table and pop-up of the Address Units record. Here’s how:

    In the Contents panel of your web map, hover over the target layer and click the More Options icon
    then click Configure Pop-up.

    Under the Attribute Expressions heading, click the Add button. This will open the Arcade expression editor window along with the interactive list of globals, functions, and constants.

    Here is the expression for adding the Street Address attribute from the related address point record to the Unit pop-up.

    Arcade script utilizing FeatureSet function to access attributes from a related feature layer; Esri Arcade expression language

    The way data are accessed from other layers is by using FeatureSet functions. So the first thing I am going to do is define a FeatureSet called addr_fs using the FeatureSetByRelationshipName function.
    var addr_fs=FeatureSetByRelationshipName($feature, "HudsonCty_AddrPts")

    The nature of FeatureSets, as you may have guessed, is to return a set of features. That means that even if only one record is returned by the function the variable is treated as a set of features. Based on what I know about my dataset there should only be one related feature. To access the single record I am going to use the First function to select the first record of the set.
    var St_Addr=First(addr_fs).STADDR;

    In the same statement I call the FULLADDR attribute from that record, and return the variable.

    Now a field called {expression/expr0} with an alias of Street Address is available for display in the attribute table and pop-up for Address Units. It’s that easy.

    Screenshot of ArcGIS Online layer attribute table with field values added using Arcade scripting; Screenshot of ArcGIS Online layer Pop-up Configure Attributes window with fields created using Arcade expressions

    I have used a similar expression to add Municipality and County to the Unit pop-up also, with the final lines of code being:

    Arcade code snippet utilizing FeatureSet function to access attributes from a related feature layer; Esri Arcade expression language
    Arcade code snippet utilizing FeatureSet function to access attributes from a related feature layer; Esri Arcade expression language

    Attributes from Calculation in a Related Table

    I have several attribute values directly from the related address point record in my units pop-up. I would also like to display the coordinate values of the address in the pop-up but they do not as a field in the units attribute table. And the units layer is a table so it does not have geometry from which I can calculate the latitude and longitude. Once again, Arcade to the rescue. I can write an Arcade expression to calculate the X and Y of the Address Points geometry layer and then pass the values through the related record. Here is the expression:

    Arcade script calculating latitude geometry from a related feature layer utilizing FeatureSet function to access attributes from a related record; ArcGIS Arcade expression language
Arcade script ; Esri Arcade expression language

    Like the previous example, I am first going to define a FeatureSet and I am going to select the first of the returned records.
    // feature set of related record(s)
    var rel_addr = FeatureSetByRelationshipName ($feature,"HudsonCty_AddrPts");
    // first record from feature set
    var addr_first = First(rel_addr);

    Then I am going to use the Geometry function to return the y-coordinate of the Address Point and return it at the end of the expression.
    var addrGeometry = Geometry(addr_first);
    var AddrY = addrGeometry.y;
    return AddrY;

    I can go into Configure Pop-up and display the field attributes that I have created using Arcade. Now I have a more meaningful pop-up for my Address Units features without having had to add any new fields to the attribute table. And if data get updated in the Hudson County Addresses point layer, either attributes or geometry, those changed will update dynamically when the map is reloaded or the Arcade expression is otherwise reevaluated.

    I hope this demonstration of using Arcade within pop-ups was helpful. In part two of the blog post, I will cover how to use Arcade to add attributes to a pop-up from unrelated layers in your web map.

    Categories: ArcGIS, Blog, Esri, GIS
    Using ArcGIS Arcade to Power your Pop-Ups: Part 1

    Share On:

    Verified by MonsterInsights