arcgis api for javascript: using arcade with your …...implicit and explicit type casting implicit...
TRANSCRIPT
![Page 1: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/1.jpg)
Kristian Ekenes
ArcGIS API for JavaScript: Using Arcade
with your apps
![Page 2: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/2.jpg)
Session Goals
• Overview of Arcade
• Using Arcade in the ArcGIS JS API
• Take your apps to the next level
![Page 3: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/3.jpg)
Arcade Purpose
Arcade is NOT intended to be a full programming / scripting language
Arcade is NOT JavaScript
• Goal – lightweight and simple
• Equivalent to a spreadsheet cell calculation
• Designed for web maps and web scenes (ArcGIS Pro/JS API/Runtime)
Not a replacement for Python for geoprocessing and automation
Input ValuesArcade
ExpressionResult Value
![Page 4: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/4.jpg)
Unit Conversion
![Page 5: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/5.jpg)
Why another
language?
![Page 6: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/6.jpg)
ArcGIS: Make, Share, Anywhere
![Page 7: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/7.jpg)
ArcGIS: Make, Share, Anywhere - Challenges
Mobile and
Native Apps
Browser
based Apps
• Size of Executable• Security
• Native Access
• Page Size• Security
• XSS• No Binaries
Traditional Development /
Scripting Languages
![Page 8: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/8.jpg)
Arcade Goals
Portable
• Write an expression in Pro, have it run in a browser, or on a device
Secure
• Ensure that expressions or scripting do not compromise security
Lightweight
• Most requirements for scripts and expressions are lightweight. The
language should be small, and fast
Geospatial
• Scripts should treat geospatial as first class Members
![Page 9: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/9.jpg)
Language Overview
![Page 10: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/10.jpg)
Arcade: Language Features
Designed for simple expressions
• Single line - implicit returns
• Case insensitive language
• Dictionary syntax for field access
Has language features to support more complex scripts
• Type system
• Implicit and explicit type casting
• Flow control statements: IF, FOR
• Variable declaration and assignments
• User defined functions
Arcade Scripts run and return a value. They are self contained and cannot
alter their environment.
![Page 11: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/11.jpg)
Implicit Returns
Implicit returns
• Last executable statement that is a value will automatically be
considered the return value.
• Enables very simple single line expressions
(10 + 100) * 30
Equivalent to:
return (10 + 100) * 30;
![Page 12: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/12.jpg)
Case Insensitive
Language is case insensitive
• Quicker to author
• Simpler for working with data, and field names
UpPeR(“Hello”)
$FeAtUrE.FiElD1
![Page 13: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/13.jpg)
Type System
Simple Types
Numbers
Booleans
Dates
Strings
Object Types
Dictionary
Feature
Array
Point
Line
Polygon
Multipoint
var myNumber = 10;
var myText = “Hello”;
var myDate = Date(2015,1,1);
var myBool = true;
var myDictionary = { “key1”: 10 };
var myFeature = { “geometry”: {…}, “attributes” {“key1”: 10 }};
var myArray = [1,2,3];
var myPoint = Point({….});
Dates, Dictionary, Feature, Point, Line… all have
overloaded constructors.
![Page 14: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/14.jpg)
Implicit and Explicit Type Casting
Implicit casting
• For function parameters
• For expressions
Explicit casting
• Functions cast between types
• Number, text, date, boolean
Implicit Casting
return 10 + “Hello”
Explicit Casting:
return text(10) + “Hello”
![Page 15: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/15.jpg)
If Statement
• Traditional if statements
are supported
• For simple single line
expressions, consider
using functions
• IIF
• Decode
• When
if (myvalue==true) {
return 1;
}
else {
return 2;
}
Equivalent to:
IIF(myvalue==true, 1, 2)
![Page 16: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/16.jpg)
For Statement
For statements
• Same syntax as
JavaScript
For in statements
• Iterates over indices of an
array, or field names of a
Dictionary or Feature
Break, continue and return
statements supported inside
block
for (var z=1; z<100; z++ ) {
k+=z;
}
for(var k in myArray) {
n+=myArray[k];
}
![Page 17: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/17.jpg)
User Defined Functions
Function keyword used to declare functions• Must be declared ahead of use
• Variables defined inside of function, have local scope
• Functions cannot be declared inside of functions.
function MultiplyNumber(thenumber) {
return thenumber*10;
}
MultiplyNumber(10);
![Page 18: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/18.jpg)
Variable Assignment
Variables can have their values reassigned.• Objects types maybe immutable, if passed into Arcade.
• Arrays are not sparse. They must be sequential.
• Geometry types are immutable inside. You cannot change the points in a path of a
line.
++myNumber
i=i+1;
myArray[10]=11;
myFeature.Field1 = “ddd”;
![Page 19: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/19.jpg)
Profiles
![Page 20: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/20.jpg)
Global Variables and Profiles
Popup
LabelingFeature Z
Visualization
Attribute Rule
Constraint
Attribute Rule
Validation
Attribute Rule
Calculation
Field Calculate
Not implemented in the JS API
Constraint Field Mapping
GeoAnalytics
Measure
Visualization
![Page 21: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/21.jpg)
Exploring Profiles
and Functions in
the Playground
![Page 22: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/22.jpg)
Arcade and the
ArcGIS JS API
ESRI JS APIVersion 3.31
ESRI JS APIVersion 4.14
![Page 23: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/23.jpg)
ESRI JS API: Arcade Expressions
Expression properties are set as literal strings
Arcade interpreter will execute valueExpression for every feature
var renderer = {
type: “class-breaks”,
valueExpression: "( $feature.TOT_VOTES / $feature.REG_VOTERS ) * 100",
valueExpressionTitle: "Voter turnout"
classBreakInfos: [ ... ],
};
![Page 24: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/24.jpg)
var labelClass = new LabelClass({
labelExpressionInfo: {
expression: "$feature.STATION_NAME"
},
labelPlacement: "below-right",
minScale: 2500000
});
nameClass.symbol = new TextSymbol();
// set the label class to the feature layer
featureLayer.labelingInfo = [ labelClass ];
Arcade Expressions can be used for Labeling
![Page 25: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/25.jpg)
Practicalities: Scripts in Script
Scripts within Scripts• Lots of string escaping.
• Embed Script in HTML using MIME type text/plain
<script type="text/plain" id="myScript">
Proper($feature.CityName)
</script>
...
const arcadescript = document.getElementById(“myScript").text;
![Page 26: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/26.jpg)
FeatureSets
![Page 27: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/27.jpg)
FeatureSet Functions
• Represents a connection to a set of Features in memory or in a server.
• Lazy, iterable, and chainable
var publicLandFeatures = FeatureSetByName($map, "public lands", ["class"], true);
var sensitiveAreas = Filter(publicLandFeatures, "class = 'sensitive'");
Count( Intersects( sensitiveAreas, $feature ) );
![Page 28: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/28.jpg)
Demos
![Page 29: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/29.jpg)
Take your apps to the next level
Generate Arcade for your users
![Page 30: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/30.jpg)
Generate Arcade for your users
![Page 31: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/31.jpg)
Generate Arcade for your users
![Page 32: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/32.jpg)
![Page 33: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/33.jpg)
Debugging expressionsConsole(“message”, value)
![Page 34: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/34.jpg)
Expression sharing
![Page 35: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/35.jpg)
Future
![Page 36: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/36.jpg)
Adding functions, profiles, and new syntax
Identifying common
operations and use
cases
• Let us know what you
need!
What’s being
considered?
• Import
• String template literals
![Page 37: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/37.jpg)
Finding Arcade
Resources
![Page 38: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/38.jpg)
ResourcesFor Arcade Documentation https://developers.arcgis.com/arcade
Playground
https://developers.arcgis.com/arcade/playground/
Using Arcade with JS API
https://developers.arcgis.com/javascript/latest/guide/arcade/index.html
Blogs and Postshttps://www.esri.com/arcgis-blog/?s=#&tag=arcade-expressions
Arcade Expression sharing repo
https://github.com/Esri/arcade-expressions/
![Page 39: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/39.jpg)
Download the Esri
Events app and find
your event
Select the session
you attended
Scroll down to
“Survey”
Log in to access the
survey
Complete the survey
and select “Submit”
Please Share Your Feedback in the App
![Page 40: ArcGIS API for JavaScript: Using Arcade with your …...Implicit and Explicit Type Casting Implicit casting • For function parameters • For expressions Explicit casting • Functions](https://reader030.vdocuments.net/reader030/viewer/2022013023/5fd6672ed26a12198112320b/html5/thumbnails/40.jpg)