Arcade has a full type system. Each type is described below.
Any
Represents any type described below. Some Arcade functions, such as Array, accept values of any type. A function may also return a value of any type depending on its inputs. In these cases, you may see function parameters and return types documented as Any
.
Array
An object representing a list of elements. Arrays are declared using square brackets.
var a = [];
// an empty array with no elements;
Count(a); // returns 0
a = [5,2,19];
Count(a); // returns 3
A single array can contain elements of various types, but they cannot have missing elements.
var z = [1,2,3];
var k = [1,2,"hello"];
return k[1]; // returns 2
z[0] = 23; // z = [23,2,3]
z[3] = 24; // Allowed as next sequential item
z[1000] = 23 // Not allowed
Arrays are zero-indexed, meaning the first element in the array is marked with an index of 0.
var a = [10, 20, 30];
return a[0];
// returns 10;
You may iterate through the elements of an array using a for loop.
for (var index in myArray){
// executes for each element in the array
}
Note that the variable index
represents the index of the array, not the value at that position.
var myArray = [10,20,30,40,50,60,70];
var total = 0;
for(var index in myArray){
total += myArray[index];
}
// total = 280
return total;
The following snippet sums the values of the array positions (or indexes):
var myArray = [10,20,30,40,50,60,70];
var total = 0;
for(var index in myArray){
total += index;
}
// total = 21
return total;
Attachment
Defines information about attachments returned from feature service queries. These are fetched using the Attachments() function.
Property | Type | Description |
---|---|---|
id | number | The ID of the attachment. |
name | text | The file name of the attachment, including the file extension. |
contentType | text | The content type of the attachment. The following are supported types: bmp, ecw, emf, eps, ps, gif, img, jp2, jpc, j2k, jpf, jpg, jpeg, jpe, png, psd, raw, sid, tif, tiff, wmf, wps, avi, mpg, mpe, mpeg, mov, wmv, aif, mid, rmi, mp2, mp3, mp4, pma, mpv2, qt, ra, ram, wav, wma, doc, docx, dot, xls, xlsx, xlt, pdf, ppt, pptx, txt, zip, 7z, gz, gtar, tar, tgz, vrml, gml, json, xml, mdb, geodatabase . |
size | number | The size of the attachment in bytes. |
exifInfo | Array | An array containing the Exif metadata of the attachment. |
keywords | text | The keywords of the attachment. |
Boolean
Boolean values evaluate to either true
or false
.
var x = true; // true
var y = false; // false
var z = x && y; // false
Date
Dates represent a moment in time. Dates are created with the Date() function and are stored as a Unix Epoch.
// Date only
var x = Date(2007,11,1); // December 1, 2007
// Date with time
var n = Date(2008,11,1,12,55); // December 1, 2008 at 12:55 p.m.
Use the date functions to work with date objects, including getting its properties and calculating new dates.
Dictionary
A collection of key/value pairs. The keys of the dictionary are case insensitive. Dictionaries may be created with the Dictionary function.
var d = Dictionary("field1", 1, "field2", 2);
You can also define dictionaries with curly brackets.
var d = {
field1: 1,
field2: 2,
"full name": "Fred Barker"
};
Dot notation
Dictionary properties can be of any type, including Dictionary. Properties can be accessed with dot notation. Dot notation allows you to access property values by typing the name of the dictionary, followed by a dot, and followed by the name of the dictionary property.
return d.field1 + d.field2; // returns 3
Dot notation is not supported if the property name contains spaces or non-Latin characters outside the Unicode BMP. In these scenarios you need square bracket notation.
Square bracket notation
Square bracket notation allows you to access dictionary properties by wrapping the property name as a text value inside of square brackets.
return d["field1"] + d["field2"]; // returns 3
Square bracket notation allows you to access unconventional property names.
d["full name"];
// returns "Fred Barker"
You can also use square brackets to reference dictionary keys using variable names.
var y = 2000;
d["Population_" + y];
// returns population in the year 2000
Auto-keys
You may access dictionary properties using auto-keys. Auto-keys assign dictionary key values to Arcade variables with names matching the dictionary's keys.
var { field1, field2 } = d;
return field1 + field2; // returns 3
Feature
Features represent geometries with a dictionary of attributes.
Property | Type | Description |
---|---|---|
attributes | Dictionary | A dictionary containing the attributes of the feature. |
geometry | Geometry | The geometry representing the location of the feature. This is optional. |
You may access feature attributes using dot or square bracket notation.
var d = Feature(myGeometry, "field1", 1, "field2", 2);
return d.field1 + d["field2"]; // returns 3
Many profiles contain a $feature
profile variable, which represents an input feature to the expression.
var population = $feature.Population;
You can reference values from joined tables using the square bracket syntax: $feature["join
// returns % change in votes from 2012 to 2016
Round(
(
($feature["COUNTY_ID.VOTED_DEM_2016"] - $feature["COUNTY_ID.VOTED_DEM_2012"])
/ $feature["COUNTY_ID.VOTED_DEM_2012"]
) * 100,
2 );
A feature's geometry cannot be accessed with dot notation. You must use the Geometry function to access a feature's geometry.
var geom = Geometry($feature);
if( TypeOf(geom) == "Polygon" ){
return firstVertex = geom.rings[0][0]; // The first vertex of the polygon
}
FeatureSet
A FeatureSet represents a connection to a layer in memory or in a server. FeatureSets are lazy, iterable, and chain-able. They allow you to access features from tables and layers within a map, feature service, or database using a FeatureSet function.
FeatureSets are typically provided to Arcade scripts via a profile variable, such as $layer
, or as part of a FeatureSetCollection like $map
or $datastore
.
// Returns the highest population among all features in the layer
// $layer is a FeatureSet
var maxValue = Max($layer, "Population");
// $feature is a Feature
var value = $feature.Population;
return maxValue - value;
See the FeatureSet guide guide to learn about creating and working with FeatureSets.
FeatureSetCollection
A FeatureSetCollection represents a collection of FeatureSets. This data type is only used when working with the $map
and $datastore
profile variables available in some profiles, like Popup. For example, the $map
profile variable represents a collection of layers (i.e. FeatureSets) in the map of the $feature
used in the execution of the Arcade expression. The $datastore
represents a collection of layers in the same feature service as the $feature
used in the execution of the Arcade expression.
// publicLandFeatures represents the features in a layer named "public lands" in the map
var publicLandFeatures = FeatureSetByName($map, "public lands", ["class"], true);
Geometry
Arcade includes five geometry types:
Spatial reference
All geometries have a spatial reference, which specifies the coordinate system and spatial properties for the coordinates defining the location of the geometry. This is defined as a dictionary with a wkid
property that indicates the Well-known ID of the geographic or projected coordinate system. Read more about spatial references here.
// General geometry creation. Will work out type from arguments.
var geom = Geometry({ x: 100, y: 100, spatialReference: { wkid: 102100 } })
return typeof(geom) // returns "point"
Geometries are immutable, meaning it is not possible to change a geometry after it has been created. Features have a geometry property, which can only be accessed with the Geometry() function.
// Assigns the feature's geometry to the line variable
var line = Geometry($feature);
LengthGeodetic(line, "meters"); // returns the length of the line in meters
The following tables describe the specification of each geometry type.
Point
A point is a zero-dimensional geometry representing a location with a pair of coordinates. This may be created by providing a Dictionary defined with the properties below to the Point() function or by passing a point feature to the Geometry() function.
Property | Type | Description |
---|---|---|
type | text | Indicates the geometry type. This value is always point . |
x | number | The x-coordinate of the point. |
y | number | The y-coordinate of the point. |
z | number | The z-coordinate of the point. This may be null . |
m | number | The m value of the point. This may be null . |
hasZ | boolean | Indicates if the geometry has a z-coordinate. |
hasM | boolean | Indicates if the geometry has an m-value. |
spatialReference | dictionary | The spatial reference of the geometry. This must match the spatial reference of the profile's execution context. |
var pt = Point({
x: 100,
y: 100,
spatialReference: { wkid: 102100 }
});
Multipoint
A multipoint is a zero-dimensional geometry, where multiple points represent one geometry. This may be created by providing a Dictionary defined with the properties below to the Multipoint() function or by passing a multipoint feature to the Geometry() function.
Property | Type | Description |
---|---|---|
type | text | Indicates the geometry type. This value is always multipoint . |
points | Point[] | An array of points making up the multipoint geometry. |
hasZ | boolean | Indicates if the geometry has z-coordinates. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | dictionary | The spatial reference of the geometry. This must match the spatial reference of the profile's execution context. |
The points
property of a Multipoint may be defined with an array of x,y,z,m coordinates.
var mp = Multipoint({
points: [
[-97.06138,32.837, 100],
[-97.06133,32.836, 50],
[-97.06124,32.834, 20],
[-97.06127,32.832, 0]
],
hasZ: true,
spatialReference: { wkid: 102100 }
});
Or with an array of Point objects.
var mp = Multipoint({
points: [
Point({ x: -97.06138, y: 32.837, z: 100, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06133, y: 32.836, z: 50, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06124, y: 32.834, z: 20, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06127, y: 32.832, z: 0, hasZ: true, spatialReference: { wkid: 102100 } })
],
hasZ: true,
spatialReference: { wkid: 102100 }
});
Individual points within a Multipoint are returned as Point objects.
// the x/y coordinates of the first point
var x = mp.points[0].x;
var y = mp.points[0].y;
Polyline
A polyline is a one-dimensional geometry containing a list of coordinates representing one or more paths. This may be created by providing a Dictionary defined with the properties below to the Polyline() function or by passing a polyline feature to the Geometry() function.
Property | Type | Description |
---|---|---|
type | text | Indicates the geometry type. This value is always polyline . |
paths | Point[][] | An array of segments (or paths) where each segment is an array of Point objects representing line vertices. You can create a Polyline by providing a 3-dimensional array of numbers where the inner-most array contains the coordinates of a single point (or vertex). This array must have at least 2 elements that represent x,y coordinates, but it may have up to 4 representing x,y,z,m values. The middle array contains additional points making up a line segment (or path). The outer-most array defines an array of segments to include in the polyline. |
hasZ | boolean | Indicates if the geometry has z-coordinates. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | dictionary | The spatial reference of the geometry. This must match the spatial reference of the profile's execution context. |
The paths
property of a Polyline may be defined with an array of x/y/z/m coordinates.
// polyline with one segment
var line = Polyline({
paths: [[
[-97.06138,32.837, 100], // third number is a z-value indicated by the hasZ property
[-97.06133,32.836, 50],
[-97.06124,32.834, 20],
[-97.06127,32.832, 0]
]],
hasZ: true,
spatialReference: { wkid: 102100 }
});
// polyline with two segments
var line = Polyline({
paths: [
[
[-97.06138,32.837, 100], // third number is an m-value indicated by the hasM property
[-97.06133,32.836, 50],
[-97.06124,32.834, 20],
[-97.06127,32.832, 0]
], [
[-101.06138,32.837, 100],
[-101.06133,32.836, 50],
[-101.06124,32.834, 20],
[-101.06127,32.832, 0]
]
],
hasM: true,
spatialReference: { wkid: 102100 }
});
Or with an array of Point objects.
// polyline with one segment
var line = Polyline({
paths: [[
Point({ x: -97.06138, y: 32.837, z: 100, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06133, y: 32.836, z: 50, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06124, y: 32.834, z: 20, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06127, y: 32.832, z: 0, hasZ: true, spatialReference: { wkid: 102100 } })
]],
hasZ: true,
spatialReference: { wkid: 102100 }
});
// polyline with two segments
var line = Polyline({
paths: [
[
Point({ x: -97.06138, y: 32.837, z: 100, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06133, y: 32.836, z: 50, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06124, y: 32.834, z: 20, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06127, y: 32.832, z: 0, hasZ: true, spatialReference: { wkid: 102100 } })
], [
Point({ x: -101.06138, y: 32.837, z: 100, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -101.06133, y: 32.836, z: 50, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -101.06124, y: 32.834, z: 20, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -101.06127, y: 32.832, z: 0, hasZ: true, spatialReference: { wkid: 102100 } })
]
],
hasZ: true,
spatialReference: { wkid: 102100 }
});
Individual vertices within a Polyline are returned as Point objects.
// the x/y coordinates of the first vertex in the polyline
var x = line.paths[0][0].x;
var y = line.paths[0][0].y;
Polygon
A polygon is a two-dimensional geometry containing a list of coordinates representing one or more rings (or boundaries) in a polygon. This may be created by providing a Dictionary defined with the properties below to the Polygon() function or by passing a polygon feature to the Geometry() function.
Property | Type | Description |
---|---|---|
type | text | Indicates the geometry type. This value is always polygon . |
rings | Point[][] | An array of rings where each ring is an array of Point objects representing polygon vertices. You can create a Polygon by providing a 3-dimensional array of numbers where the inner-most array contains the coordinates of a single point. This array must have at least 2 elements that represent x,y coordinates, but it may have up to 4 representing x,y,z,m values. The middle array contains additional points making up a ring whose first and last points must match. The outer-most array defines an array of rings to include in the polygon. |
hasZ | boolean | Indicates if the geometry has z-coordinates. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | dictionary | The spatial reference of the geometry. This must match the spatial reference of the profile's execution context. |
The rings
property of a Polygon may be defined with an array of x/y/z/m coordinates.
// polygon with one ring
var shape = Polygon({
rings: [[
[-97.06138,32.837, 100],
[-97.06133,32.836, 50],
[-97.06124,32.834, 20],
[-97.06127,32.832, 0]
]],
hasZ: true,
spatialReference: { wkid: 102100 }
});
// polygon with two rings
var shape = Polygon({
rings: [
[
[-97.06138,32.837, 100],
[-97.06133,32.836, 50],
[-97.06124,32.834, 20],
[-97.06127,32.832, 0]
], [
[-101.06138,32.837, 100],
[-101.06133,32.836, 50],
[-101.06124,32.834, 20],
[-101.06127,32.832, 0]
]
],
hasZ: true,
spatialReference: { wkid: 102100 }
});
Or with an array of Point objects.
// polygon with one ring
var shape = Polygon({
rings: [[
Point({ x: -97.06138, y: 32.837, z: 100, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06133, y: 32.836, z: 50, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06124, y: 32.834, z: 20, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06127, y: 32.832, z: 0, hasZ: true, spatialReference: { wkid: 102100 } })
]],
hasZ: true,
spatialReference: { wkid: 102100 }
});
// polygon with two rings
var shape = Polygon({
rings: [
[
Point({ x: -97.06138, y: 32.837, z: 100, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06133, y: 32.836, z: 50, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06124, y: 32.834, z: 20, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -97.06127, y: 32.832, z: 0, hasZ: true, spatialReference: { wkid: 102100 } })
], [
Point({ x: -101.06138, y: 32.837, z: 100, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -101.06133, y: 32.836, z: 50, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -101.06124, y: 32.834, z: 20, hasZ: true, spatialReference: { wkid: 102100 } }),
Point({ x: -101.06127, y: 32.832, z: 0, hasZ: true, spatialReference: { wkid: 102100 } })
]
],
hasZ: true,
spatialReference: { wkid: 102100 }
});
Individual vertices within a Polygon are returned as Point objects.
// the x/y coordinates of the first ring in the polygon
var x = shape.rings[0][0].x;
var y = shape.rings[0][0].y;
Polygons with holes must be defined with an outer ring whose points are listed in clockwise order. The hole, or inner ring, must define its points in counter-clockwise order.
Extent
An extent is a bounding box describing the minimum and maximum coordinates of a polygon, polyline, multipoint. This may be created by providing a Dictionary defined with the properties below to the Extent() function or by passing an extent feature to the Geometry() function.
Property | Type | Description |
---|---|---|
type | text | Indicates the geometry type. This value is always extent . |
xMax | number | The upper bound, or highest possible x-coordinate of the geometry. |
xMin | number | The lower bound, or lowest possible x-coordinate of the geometry. |
yMax | number | The upper bound, or highest possible y-coordinate of the geometry. |
yMin | number | The lower bound, or lowest possible y-coordinate of the geometry. |
zMax | number | The upper bound, or highest possible z-coordinate of the geometry. This value may be null . |
zMin | number | The lower bound, or lowest possible z-coordinate of the geometry. This value may be null . |
mMax | number | The upper bound, or highest possible m-value of the geometry. This value may be null . |
mMin | number | The lower bound, or lowest possible m-value of the geometry. This value may be null . |
hasZ | boolean | Indicates if the geometry has z-coordinates. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | dictionary | The spatial reference of the geometry. This must match the spatial reference of the profile's execution context. |
var envelope = Extent({
xmin: -109.55,
ymin: 25.76,
xmax: -86.39,
ymax: 49.94,
spatialReference: { wkid: 102100 }
});
Number
A number represents a count or amount that can be used used in computations and Math functions.
They can be integers.
var x = 10;
var y = 100;
Or floating point values.
var z = 1.2;
var aa = 0.0034;
Notation types
Numbers can be defined in several ways.
Decimal exponential
Decimal exponential notation defines a number as a decimal value, followed by a Latin letter E, followed by an exponent. This indicates to multiply the decimal number by 10^x power where the number x following e
represents the exponent.
var dd = 0.255e3; // 255
0.255e3 == 0.255 * Pow(10,3); // true
Binary
Binary numbers are always preceded with a zero followed by a Latin letter B (e.g. 0b
). Digits that follow these characters must be either 0
or 1
.
var cc = 0b11111111; // 255
Octal
Octal numbers are always preceded with a zero followed by a Latin letter O (e.g. 0o
). Digits that follow these characters must be a number between 0-7.
var ee = 0o755; // 493
Hexadecimal
Hexadecimal numbers are always preceded with a zero followed by a Latin letter X (e.g. 0x
). Digits that follow these characters must be in the range 0123456789ABCDEF
.
var bb = 0xff; // 255
The maximum possible number in Arcade is 2^1024
or 1.7976931348623157e+308
.
Arcade provides two number constants:
var circleArea = PI * Pow($feature.radius, 2);
Portal
The Portal type represents an instance of an ArcGIS Portal (e.g. ArcGIS Online or ArcGIS Enterprise portal). This type is created by passing the URL of the portal instance to the Portal() function.
This type only applies to the portal
parameter of the FeatureSetByPortalItem() function.
// Represents the ArcGIS Online portal instance
var agol = Portal("https://www.arcgis.com");
// references a layer with its ID from a specified portal instance
var layer = FeatureSetByPortalItem(agol, "7b1fb95ab77f40bf8aa09c8b59045449", 0, ["*"], false);
Text
A text value is a series of characters wrapped in single or double quotes. Any number, date, dictionary, or boolean value may be converted to a text value using the Text() function.
var x = "This is a Text variable";
var z = 'This is also a text variable';
// n = "100"
var n = Text(100);
Several text constants are available for your convenience. These allow you to insert special characters in text without needing to use escape characters. Click the links below to see the documentation for each.
- TextFormatting.BackwardSlash
- TextFormatting.DoubleQuote
- TextFormatting.ForwardSlash
- TextFormatting.NewLine
- TextFormatting.SingleQuote
As of version 1.11, you can embed expressions in text using template literals.