<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Label features using Arcade expressions | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
camera-position="-98.186102, 43.953738, 126663"
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-compass slot="top-left"></arcgis-compass>
Arcade expression that determines the compass direction wind
is blowing based on a field indicating the compass degrees
of the wind direction. This is appended to the wind speed
<script type="text/plain" id="wind-direction">
var DEG = $feature.WIND_DIRECT;
var SPEED = $feature.WIND_SPEED;
var DIR = When( SPEED == 0, "",
(DEG < 22.5 && DEG >= 0) || DEG > 337.5, "N",
DEG >= 22.5 && DEG < 67.5, "NE",
DEG >= 67.5 && DEG < 112.5, "E",
DEG >= 112.5 && DEG < 157.5, "SE",
DEG >= 157.5 && DEG < 202.5, "S",
DEG >= 202.5 && DEG < 247.5, "SW",
DEG >= 247.5 && DEG < 292.5, "W",
DEG >= 292.5 && DEG < 337.5, "NW", "" );
return SPEED + " mph " + DIR;
const [FeatureLayer] = await $arcgis.import(["@arcgis/core/layers/FeatureLayer.js"]);
/*****************************************************************
* Setup the Scene component
*****************************************************************/
const viewElement = document.querySelector("arcgis-scene");
viewElement.constraints = {
//////////////////////////
//// wind label class ////
//////////////////////////
// get Arcade expression as string from script element
const windArcade = document.getElementById("wind-direction").text;
// store colors for the label classes in this array
{ min: 0, max: 67.5, color: "#4c82c4" },
{ min: 67.5, max: 157.5, color: "#6c4cc4" },
{ min: 157.5, max: 247.5, color: "#ae4cc4" },
{ min: 247.5, max: 337.5, color: "#c44c88" },
{ min: 337.5, max: 360, color: "#4c82c4" },
// create the array of classes that will be used for the labelingInfo
const windLabelClasses = windClasses.map((windClass) => {
// set the Arcade expression in this property
where: `WIND_DIRECT > ${windClass.min} AND WIND_DIRECT <= ${windClass.max}`,
labelPlacement: "above-center",
material: { color: "white" },
// create the layer and add it to the Scene component
const layer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/weather_stations_010417/FeatureServer/0",
mode: "relative-to-ground",
material: { color: "#a38a8a" },
resource: { primitive: "tetrahedron" },
// the tetrahedron points south by default, so we need to subtract 180 degrees
valueExpression: "$feature.WIND_DIRECT - 180",
// labelingInfo can contain multiple classes to symbolize features differently in the same layer,
// but you can't use multiple labels on the same feature. Each feature will always have a single
// label that satisfies the where query in the label class
labelingInfo: windLabelClasses,
await viewElement.viewOnReady();
viewElement.map.add(layer);