Type System
- Array
- Attachment
- Boolean
- Date
- Dictionary
- Feature
- FeatureSet
- FeatureSetCollection
- Geometry
- Number
- Portal
- Text
Arcade has a full type system. It implicitly casts between types where appropriate, using a predefined set of rules.
Each type is described below.
Array
An object representing a list of elements. 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 as would leave blanks;
You may iterate through the elements of an array using a for
loop using the following syntax:
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 of the element. So the following evaluates to 280
:
var myArray = [10,20,30,40,50,60,70];
var sum = 0;
for(var k in myArray){
sum += myArray[k];
}
// sum = 280
return sum;
Whereas the following slightly different code evaluates to 21
:
var myArray = [10,20,30,40,50,60,70];
var sum = 0;
for(var k in myArray){
sum += k;
}
// sum = 21
return sum;
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 | string | The file name of the attachment including the file extension. |
contentType | string | 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. |
Boolean
Boolean values evaluate to either true
or false
.
var x = true;
var y = false;
String values resembling a boolean may be cast using the Boolean() function.
// z = true
var z = boolean('true');
Date
Dates describe a moment in time at various resolutions.
// Date only (no timestamp)
var x = Date(2007,11,1); // December 1, 2007
// Date with timestamp
var n = Date(2008,11,1,12,55); // December 1, 2008 at 12:55 a.m.
Dictionary
A collection of key/value pairs. The keys of the dictionary are case insensitive.
var d = Dictionary("field1", 1, "field2",2);
return d.field1 + d["field2"]; // Can access elements with either notation
// Can also declare dictionaries using object notation.
var c = {
"field1": 1,
"field2": 2
}
Feature
Features have attributes and optionally a geometry.
var d = Feature(myGeometry, "field1", 1, "field2",2);
return d.field1 + d["field2"]; // Can access elements with either notation
return Geometry(d); // Can get the geometry of the feature using the geometry function.
The Feature constructor is overloaded.
// Creating a Feature using a Dictionary
var feature = Feature(geom, { "field1": 1, "field2": "myField2value" });
// You can also specify named parameters
var feature = Feature({ geometry: geom, attributes: { "field1": 1, "field2": "myField2value" } });
FeatureSet
A FeatureSet represents a connection to a set of Features in memory or in a server. FeatureSets are lazy, iterable, and chainable. FeatureSets allow you to access features from feature service layers within the map or feature service.
FeatureSets can be created from JSON with the FeatureSet() function, or referenced using the $layer
global, which is a FeatureSet of all features in the same layer as the feature executing the Arcade.
// Returns the highest population among all features in the layer
Max($layer, "Population");
Or you can create a FeatureSet using one of the functions below, which takes the $map
or $datastore
as a global variable and returns one if its layers based on its title, layer ID, or portal item ID.
// returns true if the feature intersects sensitive land features from another layer in the map
var publicLandFeatures = FeatureSetByName($map, "public lands", ["class"], true);
var sensitiveAreas = Filter(publicLandFeatures, "class = 'sensitive'");
Count( Intersects( sensitiveAreas, $feature ) );
FeatureSetCollection
A collection of FeatureSets. This data type is only used when working with the $map
and $datastore
globals available in the Popup, Field Calculate, and Attribute Rule profiles. The $map
represents a collection of layers (or FeatureSets) in the map of the feature executing the Arcade expression. The $datastore
represents a collection of layers in the same feature service as the feature executing the Arcade expression.
For example, the FeatureSetByName()
function returns the layer with the given name in the $map
FeatureSetCollection.
var publicLandFeatures = FeatureSetByName($map, "public lands", ["class"], true);
Geometry
Arcade includes five geometry types: Point, Multipoint, Polyline, Polygon, Extent. Geometry is immutable, meaning it is not possible to change the geometry after it is created.
Features contain geometry, which may be returned from the Geometry() function.
// returns the feature's geometry
Geometry($feature)
// Geometry Types have overloaded functions.
var pt = Point({ 'x': 100, 'y': 100, 'spatialReference':{'wkid':102100} });
var polyline = Polyline({ 'paths' : [ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ], [ [-97.06326,32.759], [-97.06298,32.755] ] ] , 'spatialReference':{'wkid':102100}});
var poly = Polygon(Polygon({'rings' : [ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832], [-97.06138,32.837] ], [ [-97.06326,32.759], [-97.06298,32.755], [-97.06153,32.749], [-97.06326,32.759] ] ], 'spatialReference':{'wkid':102100}}));
var env = Extent({ 'xmin' : -109.55, 'ymin' : 25.76, 'xmax' : -86.39, 'ymax' : 49.94, 'spatialReference':{'wkid':102100} });
var mp = Multipoint({ 'points' : [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ], 'spatialReference':{'wkid':102100} });
// General geometry creation. Will work out type from arguments.
var geom = Geometry({ 'x': 100, 'y': 100, 'spatialReference':{'wkid':102100} })
The following tables describe the specification of each geometry type.
Point
A point is a zero-dimensional geometry. This may be created by passing JSON in the format described 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. |
hasZ | boolean | Indicates if the geometry has a z-coordinate or elevation. |
hasM | boolean | Indicates if the geometry has an m-value. |
spatialReference | Object | The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry. |
Multipoint
A multipoint is a zero-dimensional geometry. This may be created by passing JSON in the format described 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 or elevation values. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | Object | The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry. |
Polyline
A polyline is a one-dimensional geometry. This may be created by passing JSON in the format described 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 | number[][][] | A three-dimensional array of numbers. The inner-most array contains the x,y,z,m coordinates of a single point. The second dimension contains additional points making up a line segment. The third dimension allows the polyline to have multiple segments. |
hasZ | boolean | Indicates if the geometry has z-coordinates or elevation values. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | Object | The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry. |
Polygon
A polygon is a two-dimensional geometry. This may be created by passing JSON in the format described 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 | number[][][] | A three-dimensional array of numbers. The inner-most array contains the x,y,z,m coordinates of a single point. The second dimension contains additional points making up a ring, or line segment whose first point and last point match. The third dimension allows the polygon to have multiple rings. |
hasZ | boolean | Indicates if the geometry has z-coordinates or elevation values. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | Object | The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry. |
Extent
An extent is a bounding box describing an area of interest. This may be created by passing JSON in the format described below to the Geometry().
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 extent. |
xMin | number | The lower bound, or lowest possible x-coordinate of the extent. |
yMax | number | The upper bound, or highest possible y-coordinate of the extent. |
yMin | number | The lower bound, or lowest possible y-coordinate of the extent. |
zMax | number | The upper bound, or highest possible z-coordinate of the extent. This value may be null . |
zMin | number | The lower bound, or lowest possible z-coordinate of the extent. This value may be null . |
mMax | number | The upper bound, or highest possible m-value of the extent. This value may be null . |
mMin | number | The lower bound, or lowest possible m-value of the extent. This value may be null . |
hasZ | boolean | Indicates if the geometry has z-coordinates or elevation values. |
hasM | boolean | Indicates if the geometry has m-values. |
spatialReference | Object | The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry. |
Number
Numbers are a single data type that are 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 n = Number("1.2");
String values resembling numbers may be cast using the Number() function.
// n = 1.2
var n = number("1.2");
Two number constants are also available for your convenience. Click the links below to see the documentation for each.
Portal
The Portal type represents an instance of an ArcGIS Portal (e.g. ArcGIS Online). This type is created by passing the URL to the portal instance to the Portal() function.
This type only applies to the portal
parameter of the FeatureSetByPortalItem() function.
// This represents ArcGIS Online. You would place your portal url here
var myPortal = Portal("https://www.arcgis.com");
// references a layer with its ID from a specified portal instance
var fs = new FeatureSetByPortalItem(myPortal, "7b1fb95ab77f40bf8aa09c8b59045449", 0, ["*"], false);
Text
The text type, also known as string, is a series of characters wrapped in single or double quotes. Any number or boolean 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 also 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.
Feedback on this topic?