ArcGIS Blog

Mapping

ArcGIS Online

Introducing new Arcade functions and an enhanced playground

By Anne Fitz and Omar Kawach

The latest release (v1.23) of Arcade introduces three powerful new functions, an updated playground for prototyping and testing your Arcade expressions, and more! Let’s dive in.

New Functions

GetEnvironment

The GetEnvironment function is a game-changer when it comes to accessing contextual information within your Arcade expressions. It provides valuable metadata about the execution context of the expression, allowing you to write dynamic and responsive scripts. Whether you need to extract the Arcade runtime engine, spatial reference, locale, or other important details, GetEnvironment has got you covered.

var env = GetEnvironment();
// returns the following when executed in the Map Viewer
// {
//  "version":"1.23",
//  "engine":"web",
//  "engineVersion":"4.27",
//  "application":"ArcGISMapViewer",
//  "locale":"en-US",
//  "spatialReference": { "wkid": 3857 }
// }
var locale = IIF(HasValue(env, "locale"), env.locale, "");
// returns the locale if it exists, otherwise returns an empty text value
return locale;

NearestCoordinate

The NearestCoordinate function allows you to determine the closest coordinate to a given point within a geometry or feature. Whether you need to identify the nearest point, line, or polygon from a given reference, this function makes it possible. By employing NearestCoordinate, you can calculate distances, identify closest facilities, and determine proximity-based relationships.

The following expression uses NearestCoordinate to find the minimum distance between the current feature and the closest building.

// find all buildings within a 50ft buffer of the current feature
var bldgDistance = 50;
var bufferedDistance = Buffer($feature, bldgDistance, "feet");
var buildings = FeatureSetByName($map, "Boston buildings");
var buildings_filtered = Intersects(buildings, bufferedDistance);

var min_dist = bldgDistance;
if (Count(buildings_filtered) > 0) {
    for (var building in buildings_filtered) {
        // find the nearest coordinate between the feature and building
        var dict = NearestCoordinate(building, $feature);
        // distance is in meters
        if (dict.distance <= min_dist) {
            min_dist = dict.distance;
        }
    }
}
// convert to feet & round
return Round(min_dist * 3.281, 2);

NearestVertex

Similar to the NearestCoordinate function, NearestVertex enables you to identify the closest vertex on a geometry to a given location. NearestVertex can be used to determine the nearest point on a path or route, proximity of certain features to a point of interest, and more.

This function proves particularly valuable in the utility space, as all features on lines within utility networks are required to have vertices. By calling NearestVertex, we can effectively obtain the precise location and distance to the nearest feature, making it an indispensable tool for utility network analysis.

Updated Playground

The original Arcade playground was developed as a standalone environment for users to test their Arcade expressions and try out the latest features of Arcade.

The old Arcade playground as seen in the Developer doc site
The old Arcade playground

As part of our ongoing effort to enhance the Arcade documentation site, we have updated the playground to use the new and improved Arcade editor. The new editor was introduced in the November 2022 release of ArcGIS Online and brought many powerful new features to enhance your experience with writing Arcade expressions. In the June 2023 release of ArcGIS Online, we’re bringing a new accessible color palette for better overall syntax highlighting / code colorization, meeting Web Content Accessibility Guidelines (WCAG 2.0).

Experience these enhanced capabilities firsthand in the new Arcade playground. With its user-friendly interface, along with advanced functionalities like syntax highlighting, auto-completion, and improved error messages, you’ll enjoy a seamless debugging and testing experience for your new functions. Witness instant results as you test and debug, empowering you to explore the full potential of Arcade in real-time.

The new Arcade playground as seen in the Developer documentation site
The new Arcade playground

Updated functions

In addition to the new functions mentioned earlier, the recent release of Arcade also introduces updated functions that streamline the process of copying or converting data types within Arcade expressions.

The Array and Dictionary functions have new signatures with an optional deep parameter, which allows you to create a shallow or deep copy of the Dictionary or Array. When deep: true, the functions create a deep copy of each element in the input array/dictionary, meaning elements in the output array/dictionary will not share the same references as the elements of the input array/dictionary. Creating a deep copy allows you to make changes to the copied array/dictionary without impacting the original data.

We’ve also added new signatures to Dictionary and Feature that allow for easier conversion between data types without first having to convert to JSON text.

Updated data types

We’re listening to your feedback! At this release, the Attachment data type was updated to include keywords. Also, Number data values can now be represented as binaryoctal, and hexadecimal values.


📝 For more information about the latest release of Arcade, check out the release notes.

💬 Have feedback on the release? Any new functions you’d like to see? Let us know in the comments below!

Share this article

Subscribe
Notify of
4 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Markus Schenardi(@markusschenardi)
March 4, 2020 2:38 am

These approach might be working for the recovery scenario.

But what is the official way to duplicate an environment side by side? A common scenario is to “downgrade” a production system to a testsystem to later approve the update procedure or to simulate other updates e.g. of third party tools.

What’s your recommendation?

Jon Quinn(@jquinn)
March 5, 2020 10:59 am

This would be an approach you can take to set up a duplicate environment. By creating the environment where etc\hosts entries are in place, you’re isolating the traffic to the standby environment to machines that have the entries. Read-only mode discussed in the blog is a way that you don’t need to downgrade the production environment. Set up your new environment, put the production environment to read-only so no updates can be performed, then you can test your patches/updates/upgrades on the new environment without impacting production or dealing with data differences.

Thomas Mathew(@t-mathew)
March 5, 2020 3:53 am

It looks like this method is not possible when migrating to a machine in Microsoft Azure using ArcGIS Enterprise Cloud Builder 10.8. This is because AE Cloud Builder does not provide an option to update the etc\hosts file between creating the machine and installing the software. The AE Cloud Builder does the creation of the Azure server machine and installing of ArcGIS Enterprise, in one step, without a configuration to edit the etc\hosts file.

Let me know if there’s a step I could be missing.

Jon Quinn(@jquinn)
March 5, 2020 11:02 am
Reply to  Thomas Mathew

Right, standing up a duplicate environment is challenging when you don’t have the ability to modify the etc\hosts files in between when the machines are provisioned and the software installed and configured. In this case, you’ll need to either update the public DNS entry to resolve to the standby while it’s getting configured, or investigate whether the standby can be in a separate subnet that resolves the public DNS differently, (doesn’t resolve to the production environment), so the standby can be created. We’re updating the blog to indicate other ways to achieve hostname resolution outside of the etc\hosts file.

Lisa King(@e039755-2)
September 19, 2022 6:14 am

Can this approach be used if I am moving my enterprise to a newer windows server operating system? Also, can I use this approach if I want to use and newer version of enterprise?

Nicholas Willette(@eulessonline)
January 18, 2023 7:02 am
Reply to  Lisa King

Did Lisa’s question get an answer? I’m moving to a new OS and want to upgrade the Enterprise Server software version as well. Or do I need to upgrade Enterprise Server on the existing machine BEFORE I try movingto the new machine?

Thiago dos Santos Nascimento(@thiago-nascimento)
October 1, 2024 10:33 am

I had the same question, and according to support, the following strategy is recommended:

  1. Install the new version of the OS on a new machine(s);
  2. Install the same version of the ArcGIS Enterprise on your new machine(s), with the OS already upgraded;
  3. Use webgisdr tool to migrate the content from the old ArcGIS Enterprise to the one in your new machine(s);
  4. Upgrade the ArcGIS Enterprise on the new machine(s).
Lisa King(@e039755-2)
June 25, 2024 1:45 pm
Reply to  Lisa King

I still seek this information.

Mike Schonlau(@mschonlau2-2)
August 17, 2023 10:08 am

I’m trying to restore a webgisdr backup (11.1) to a new CloudBuilder deployment (11.1), then switch my DNS/AWS load balancer, etc to point to the new environment. Having trouble with the hosts file entry. I’m not exactly sure what to use there. Do you have any more specific examples you could give?