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.
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.
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 binary, octal, 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!
Article Discussion: