Skip to main content

“Arcade’s Fire: Inside Esri’s Scripting Language” Webinar Q&A – Part 2

We continue to climb mountains beyond mountains to answer more of your Arcade questions

Welcome back to the “Arcade’s Fire: Inside Esri’s Scripting Language” questions and answers blog!

In the first part, Emilie Rabeau replied to your general Arcade questions along with your queries about the Visualization and Attribute Rules profiles. She has tossed the baton to me, where I will attempt to respond to your comments around my demonstrations of the Labeling and Popup profiles.

Before I begin, here’s my Arcade Fire concert photo:

Mark’s view of the Arcade Fire concert in Las Vegas in 2017 (with a weird banner blocking the way)

Labeling

Bored with your typical map labels? Arcade elevates your labeling to the next level. Labels from multiple fields! Labels on multiple lines! Manipulate text and do mathematics without affecting your source data! With a few lines of Arcade code, you can add pizazz to your feature labels that can be used throughout the ArcGIS system.

Demo example of using the Labeling profile to create multi-line labels with formatted text, on-the-fly calculations and conditional statements [view demo web map]

Q: ­Can you add a newline in the labels yet?­ /  ­Is there a way to create multi-line labels in an ArcGIS Online web map? I’ve tried “TextFormatting.NewLine” but it doesn't seem to display properly on the map?­

A: As you can see in the demo screenshot above, multi-line labels are obtainable through Arcade by adding the TextFormatting.NewLine constant to your expression. However, they are only supported with ArcGIS API for JavaScript 4.x applications, which includes the New Map Viewer (currently in beta at time of publishing) in ArcGIS Online and ArcGIS Enterprise. The “classic” version of the Map Viewer was not built on the latest generation of the API. Try adding your multi-line labels in a web map using the New Map Viewer and they should work like a charm.

Q: ­Does ArcGIS Pro also support multiple line labels via Arcade?­

A: Yes! You can use the TextFormatting.NewLine constant in your Arcade expressions in ArcGIS Pro to create stacked labels. The trick is that you will need to manually type in that constant when writing a label expression in ArcGIS Pro. Constants are not listed in this ArcGIS Pro dialog.

Q: ­Does adding multiple expressions for a label cause the labels to render much slower for large datasets? ­

A: Arcade is designed to be lightweight and agile. As the return value for the labeling profile is text (which is light by nature), adding a multipart label expression to create that text should not have a significant impact on rendering performance. As with anything, it depends on how complex the expression is; the more lines of code you write will likely add to the computation time to create the label. For example, if your code contains many loops that iterates through large datasets, there will likely be an impact on speed. General rule of thumb: keep your code as simple as possible and test the results.

Q: ­Why there is a single quote ' for text and double quote " for a space?­

A: A very observant viewer noticed I used single quotes around some text but double quotes to concatenate a space character in one of my expressions.

Code snippet showing both single and double quotes to represent text objects.

This speaks to the concept that Arcade is “forgiving”. You can wrap strings around single quotes or double quotes – there are no hard syntax rules in that regards.

Q: ­Can you use Arcade to change the colour of part of a label?­

A: Good news: you can use the ArcGIS API for JavaScript 4.x to create Arcade expressions to define colour properties in your feature layer or scene layer labels. But you will need to build an application from scratch. Bad news: this functionality is currently not exposed in the Labeling profile. This enhancement has been requested in the ArcGIS Ideas site. Fingers crossed; this could hopefully be implemented soon.

Q: ­Would you be able to show labelling with data from a related table?­

A: Arcade is able to interact with data from related tables through the FeatureSet object. However, this function is only available for the Attribute Rules, Popup and Field Calculate profiles, and not for the Labeling profile. Scroll down to the Popup section to learn more about how you can access related tables through popups.

Q: How about tying label data to real-time updates exposed through GeoEvent feeds or other hosted feature service layers to create real-time visuals for weather, traffic, wind speeds, river water velocities, air traffic, etc.?

A: As Arcade recalculates values on the browser and on-the-fly, labels will update as live feed data changes. For example, labeling demo used a feature layer of weather stations posting up-to-date conditions every hour. In addition, ArcGIS Velocity, a real-time and big data processing and analysis capability of ArcGIS Online, also supports Arcade expressions. The Velocity profile enables expressions to be used within several tools exclusive to ArcGIS Velocity.

Popup and Field Calculate

Arcade enables you to jazz up your popup content. You can create expressions that access sets of features from many layers and display those return values in the popup. You can even generate feature geometries on-the-fly to incorporate spatial relationships into your expressions. And you can use these expressions to update field values within your data source.

Demo example of using the Popup profile that generated values on-the-fly based on the attributes and geometry of local area polygons and graffiti points [view demo web map]

Q: Can you build the popups in ArcGIS Pro with Attribute Expressions and then share that layer to ArcGIS Online and have it all work?­ / Are you able to carry the popup from ArcGIS Pro to ArcGIS Online?

A: Yes! Yes! Yes! That’s the beauty of Arcade – it’s portable. I could have built the popup with Arcade expressions within an ArcGIS Pro map and shared that map in ArcGIS Online.  The resulting web map would have the same popup expressions. As always, you should test the popup in ArcGIS Online to verify it looks and behaves the way you’d expect.

Q: ­Are there any performance considerations when using Arcade to do on-the-fly functions with geometries (i.e. points in a polygon)­? / ­You mention Arcade can be intense in ArcGIS Online.  Is it strictly a matter of speed, or credit consumption? ­

A: First off, Arcade DOES NOT consume credits! Credits are only consumed under specific circumstances (e.g. online data storage, running certain analytics, using premium content). Arcade does not apply to any of these.

When I mentioned the “intensity” of Arcade, I was referring specifically to accessing information from FeatureSet objects. The FeatureSet function allows you to access attributes from any layer in your map, including spatial data. Then you can use Geometry functions to determine spatial relationships between layers. As you saw in the demo, that is powerful. You can create a popup with expressions that use the geometries of multiple layers to generate values.

This is where you must be careful. Normally, when you click on a feature, the popup will appear promptly. In the graffiti demo that included geometric functions applied to feature sets, there is a tiny pause from when you click the feature to the popup displaying. It’s barely noticeable, but it’s there. There’s a lot going on behind the scenes to calculate these values in real time. Imagine if I had done the same demo using larger datasets or more complex geometries. Speed would likely be impacted. Bottom line: be smart when using FeatureSets in your popups; balancing performance and the user experience.

Want to learn more FeatureSets? This blog is a great place to start.

Q: ­Can you pull data from related tables into popups using Arcade?­ / ­If there's a filter on a related table, will Arcade respect that filter or will it only perform the analysis on the entire related table?­

A: As discussed above, FeatureSet allows you to bring in information from another layer in your map. FeatureSet also enables you to access data from a related table. And yes, filters will be respected in Arcade. Take advantage of filters to carry only the data you need from the related table. This is a pretty big topic for this space, so this blog walks you through how to show related data in popups with Arcade FeatureSets.

Q: Is it easy to select something by a buffer or distance? For example, the closest road segment to a point.

A: “Easy” is a suggestive word, but it is possible with some scripting. Arcade provides a bunch of Geometry functions to accomplish tasks like this. One theoretical (but untested) approach:

  • Create a Buffer around the point you clicked on for the popup (aka, $feature) within a certain distance
  • From the returned polygon, use Intersects to get a FeatureSet of the streets that fall inside the buffer
  • Using a For loop, iterate through each feature in the FeatureSet and calculate the Distance between street and point
  • Evaluate the distances to find the lowest number (perhaps using an array, dictionary or code to compare values as they are iterating through the loop) to determine the nearest feature
  • Obtain values from that nearest feature to display in your popup

This entry in the Esri Community site also accomplishes something similar.

Q: ­Why do you multiply by 100,1 to have % instead of 100­?

A: Someone with a very keen eye noticed this in the demo. Let’s break it down.

Code snippet showing an expression calculating a percentage value.

This expression divides the sum of the graffiti incidents per local area by the total graffiti incidents in all local areas (the entire city) to derive a ratio. And since I wanted to display this value as a percentage (0-100) versus a decimal value (0-1), I multiplied the result by 100. The 1 after the 100 is a parameter for the Round function that sets the number of decimal places to round the number to.

Q: ­For "Transfer Attributes" field mapping, is there a way to use Python or SQL instead of Arcade for expressions?­

A: In ArcGIS Pro, Transfer Attributes allows you to copy feature attributes from selected features on a source layer to selected features of a target layer. To set the conditions of the transfer, you can configure the field mapping. Arcade includes a Field Mapping profile to define the field map between source and target layers. Currently, Arcade is the only option to script logic expressions within the Transfer Attributes tool. If SQL or Python are required for you to execute this tool, please post this to the ArcGIS Ideas site – software developers are monitoring.

Q: ­Would calculated fields be automatically applied to the new entire database?

A: In the demo, I quickly showed how you can use the FeatureSet object to calculate field values. Unfortunately, time was our enemy, so I didn’t run the expression to see the results. In a perfect scenario, you would have seen that the field calculations would have applied to all the records in my table. However, if I had a selection or filter, the calculations would have applied to only that subset of records.  Conversely, you can modify your Arcade expression to add logic to determine which records you want to apply the return values.

Q: ­Are there plans to make the attachments feature available for Arcade in the popups? Right now, it is only available under field calculate.  ­

A: You are correct in stating the Attachments function is currently only available for the Field Calculate and Attribute Rules profiles, and not for the Popup profile. I have not heard of any specific plans to add this function to the Popup profile (this would be a perfect suggestion for the ArcGIS Ideas site). In the meantime, if you do want to display the attachment image in the popup instead of just a hyperlink to view the image, this awesome document outlines how to Show Attachments in Popups with Arcade Expressions.


There you have it; a very long two-part blog to answer your probing Arcade questions. Thanks again for reading through our blogs and attending the “Arcade’s Fire: Inside Esri’s Scripting Language” webinar on February 11, 2021. If you want to relive the magic, the webinar recording is available online along with the PDF of the presentation slides.

One final shameless plug! You can access the webinar’s ArcGIS Online group where you can explore our demonstrations, code snippets, and other cool resources (with more to come). All that content is available at: bit.ly/arcadesfirewebinar (all lower case)

This ArcGIS Online group includes additional resources from this Arcade webinar.

That’s it! Emilie and I thank you again for playing along in our version of an Arcade game. It was fun for us – hope it was fun for you. Until me meet again, GAME ON!

This post was translated to French and can be viewed here

About the Author

Mark Ho is a Technical Solutions Specialist in Vancouver. His mission statement is simple: to share his serious love of mapping (without being too serious). Mark received a civil engineering degree from the University of British Columbia before getting his GIS diploma from the British Columbia Institute of Technology. He then spent 13+ years as an instructor with Esri, teaching everything ArcGIS. In 2011, he returned north to join Esri Canada, where you may have seen him presenting at user conferences, webinars, videos and podcasts. When he's not creating digital content, you can find him collecting maps, travelling around, listening to Dua Lipa—and collecting more maps (and hockey jerseys too).

Profile Photo of Mark Ho