Module 12 - Labels
Level 2 · Layers & Data · 🟡 · 2 hours · Prereq: Module 11
What you'll build
A scale-dependent label hierarchy: state names at small scales, county names in the middle, and city names with population at large scales - each with a halo, deconfliction, and a label class that only applies to a filtered subset.
Why this matters
Labels are the fastest way to make a map readable and the fastest way to make it unreadable.
They are also the part of the SDK with the most non-obvious properties - labelPlacement
values differ by geometry type, where clauses on label classes are a hidden superpower, and
deconfliction silently drops labels you thought you'd configured.
Two hours here saves a lot of "why isn't my label showing" later.
Concepts
1. The shape of labelingInfo
layer.labelingInfo = [
{
labelExpressionInfo: { expression: "$feature.NAME" },
symbol: {
type: "text",
color: "#1a1a1a",
haloColor: "white",
haloSize: 1.5,
font: { size: 11, family: "Noto Sans", weight: "bold" },
},
labelPlacement: "above-center",
minScale: 2500000,
maxScale: 0,
where: "POPULATION > 100000",
deconflictionStrategy: "static",
},
];
layer.labelsVisible = true;
It is an array. Each element is a label class - a rule that applies to a subset of features with its own expression, symbol and scale range. That is how you build a hierarchy.
2. labelExpressionInfo - always Arcade
// Simple field
labelExpressionInfo: { expression: "$feature.NAME" }
// Concatenation
labelExpressionInfo: { expression: "$feature.NAME + ', ' + $feature.STATE_ABBR" }
// Multi-line - \n works in text symbols
labelExpressionInfo: {
expression: `$feature.NAME + TextFormatting.NewLine + Text($feature.POPULATION, '#,###')`
}
// Conditional
labelExpressionInfo: {
expression: `
var p = $feature.POPULATION;
if (IsEmpty(p)) { return $feature.NAME; }
if (p > 1000000) { return Upper($feature.NAME); }
return $feature.NAME;
`
}
// Rounded / formatted numbers
labelExpressionInfo: {
expression: `Round($feature.AREA_SQKM, 1) + " km²"`
}
labelExpression(noInfo) is the old 3.x syntax -"[NAME]"with square brackets. It still parses in some paths but is deprecated. Always uselabelExpressionInfowith Arcade.
TextFormatting.NewLine is the Arcade constant for a line break. A literal "\n" inside
an Arcade string also works; the constant is clearer.
3. labelPlacement - and it depends on geometry
| Geometry | Valid values |
|---|---|
| Point | above-center, above-left, above-right, below-center, below-left, below-right, center-center, center-left, center-right |
| Polyline | above-along, below-along, center-along, above-start, above-end, center-start, center-end, below-start, below-end |
| Polygon | always-horizontal (2D), center-center |
Using a point value on a polyline layer silently produces no labels. This is the most
common "my labels don't show" cause after labelsVisible.
Conventions worth following: above-center for cities (leaves the symbol clear),
center-along for roads (labels follow the line), always-horizontal for polygons.
4. TextSymbol properties that matter
symbol: {
type: "text",
color: "#2b2b2b",
haloColor: "#ffffff",
haloSize: 1.5, // ← the single most important label property
font: {
size: 11,
family: "Noto Sans", // must be a font the SDK serves; see §8
weight: "bold", // "normal" | "bold" | "bolder" | "lighter"
style: "normal", // "normal" | "italic"
decoration: "none",
},
horizontalAlignment: "center",
verticalAlignment: "baseline",
xoffset: 0,
yoffset: 0,
angle: 0,
lineWidth: 192, // px before wrapping
lineHeight: 1.1,
backgroundColor: null, // a filled box behind the text
borderLineColor: null,
borderLineSize: 0,
}
haloSize is non-negotiable. Without a halo, dark text over a dark polygon or a busy
basemap is unreadable. 1-2 px of a contrasting halo makes a label legible over anything.
Rule of thumb: haloColor white for dark text, #000 or the panel background for light text,
haloSize between 1 and 2.
5. Scale ranges - building a hierarchy
layer.labelingInfo = [
{
// Big cities: visible from country view down
labelExpressionInfo: { expression: "$feature.NAME" },
where: "POPULATION > 1000000",
minScale: 20000000,
maxScale: 1500000,
symbol: textSymbol({ size: 13, weight: "bold" }),
labelPlacement: "above-center",
},
{
// Mid cities: appear when you zoom in
labelExpressionInfo: { expression: "$feature.NAME" },
where: "POPULATION > 100000 AND POPULATION <= 1000000",
minScale: 4000000,
maxScale: 300000,
symbol: textSymbol({ size: 11 }),
labelPlacement: "above-center",
},
{
// Everything else, with population, close in
labelExpressionInfo: {
expression: `$feature.NAME + TextFormatting.NewLine + Text($feature.POPULATION, '#,###')`,
},
where: "POPULATION <= 100000",
minScale: 300000,
maxScale: 0,
symbol: textSymbol({ size: 10, weight: "normal" }),
labelPlacement: "above-center",
},
];
This is the whole technique. Three classes, non-overlapping where clauses, staggered
scale ranges. The map goes from "a few important names" to "everything with detail" as the user
zooms, and never shows 4,000 labels at once.
where on a label class does not filter the layer. The features still draw; only the
labels are restricted. That is exactly what you want.
6. Deconfliction
deconflictionStrategy: "static" // default: hide labels that would overlap
deconflictionStrategy: "none" // draw all labels, overlaps and all
Default is "static": the SDK ranks labels and drops the ones that collide.
Set "none" only when you know every label can fit - cluster counts, for instance, where
one label per cluster is guaranteed non-overlapping. (You saw this in Module 10's clustering
config, and that's why it was there.)
When labels vanish and you can't work out why, it is usually deconfliction. Test by
temporarily setting "none"; if they appear, it's a collision problem, and the fix is a
smaller font, a tighter where, or a narrower scale range - not "none" in production.
7. Label priority
Within one layer, later label classes lose to earlier ones. Across layers, the layer higher in
map.layers wins.
If your city labels are being eaten by a polygon layer's labels, reorder the layers or narrow the polygon labels' scale range.
8. Fonts
The SDK serves a fixed set of fonts as glyph atlases. Common safe choices:
Arial, Arial Bold, Arial Italic
Noto Sans, Noto Sans Bold, Noto Sans Italic
Avenir Next, Avenir Next Bold, Avenir Next Demi
Josefin Slab, Merriweather, Montserrat, Orbitron, Oswald,
Playfair Display, Roboto, Ubuntu, Alegreya, Atomic Age
An unavailable font falls back silently, usually to Arial. If your carefully-chosen type isn't rendering, that's why. Full list: https://developers.arcgis.com/javascript/latest/labeling/#fonts
In a SceneView, fonts behave the same but labels are also affected by elevationInfo and can
be occluded by 3D geometry. Module 29.
Build it
Two layers: US states (polygons) and US major cities (points).
Step 1 - Basic labels
import FeatureLayer from "@arcgis/core/layers/FeatureLayer.js";
const textSymbol = ({ size = 11, color = "#2b2b2b", weight = "normal", halo = "white" } = {}) => ({
type: "text",
color,
haloColor: halo,
haloSize: 1.5,
font: { size, family: "Noto Sans", weight },
});
const cities = new FeatureLayer({
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Major_Cities/FeatureServer/0",
title: "US Major Cities",
outFields: ["NAME", "POPULATION", "ST"],
labelsVisible: true,
labelingInfo: [
{
labelExpressionInfo: { expression: "$feature.NAME" },
symbol: textSymbol(),
labelPlacement: "above-center",
},
],
});
Load it and zoom out to the whole country. Most labels disappear - deconfliction is dropping thousands of collisions. That is the problem the rest of this module solves.
Step 2 - The hierarchy
cities.labelingInfo = [
// Tier 1 - metros, visible from the national view
{
labelExpressionInfo: { expression: "Upper($feature.NAME)" },
where: "POPULATION > 1000000",
minScale: 25000000,
maxScale: 2000000,
symbol: textSymbol({ size: 13, weight: "bold" }),
labelPlacement: "above-center",
},
// Tier 2 - large cities
{
labelExpressionInfo: { expression: "$feature.NAME" },
where: "POPULATION > 250000 AND POPULATION <= 1000000",
minScale: 8000000,
maxScale: 500000,
symbol: textSymbol({ size: 12, weight: "bold" }),
labelPlacement: "above-center",
},
// Tier 3 - medium
{
labelExpressionInfo: { expression: "$feature.NAME" },
where: "POPULATION > 100000 AND POPULATION <= 250000",
minScale: 3000000,
maxScale: 200000,
symbol: textSymbol({ size: 11 }),
labelPlacement: "above-center",
},
// Tier 4 - everything, with numbers, close in
{
labelExpressionInfo: {
expression: `$feature.NAME + TextFormatting.NewLine + Text($feature.POPULATION, '#,###')`,
},
where: "POPULATION <= 100000",
minScale: 800000,
maxScale: 0,
symbol: textSymbol({ size: 10, color: "#444" }),
labelPlacement: "above-center",
},
];
Zoom from the whole country to a single city. Watch labels appear in tiers. That progressive disclosure is what makes a professional basemap feel professional, and it is 40 lines.
Step 3 - Polygon labels
const states = new FeatureLayer({
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_States_Generalized/FeatureServer/0",
title: "US States",
outFields: ["STATE_NAME", "STATE_ABBR", "POPULATION"],
opacity: 0.5,
labelsVisible: true,
labelingInfo: [
{
// Abbreviation when zoomed out, full name when zoomed in
labelExpressionInfo: { expression: "$feature.STATE_ABBR" },
minScale: 50000000,
maxScale: 12000000,
symbol: textSymbol({ size: 12, weight: "bold", color: "#666" }),
labelPlacement: "always-horizontal",
},
{
labelExpressionInfo: { expression: "Upper($feature.STATE_NAME)" },
minScale: 12000000,
maxScale: 3000000,
symbol: {
...textSymbol({ size: 14, weight: "bold", color: "#555" }),
// Letter-spacing isn't a TextSymbol property; simulate it in the expression
},
labelPlacement: "always-horizontal",
},
],
});
map.addMany([states, cities]); // states first = drawn underneath
A polygon's label is placed at a point inside it - roughly the pole of inaccessibility, not the centroid, so a crescent-shaped polygon gets its label inside the shape rather than in the gap. You don't control this directly in 2D; if you need exact placement, compute a point and label a separate point layer.
Letter-spacing note in the code is honest: TextSymbol has no tracking property. If you
need spaced-out state names, insert spaces in the Arcade expression:
Concatenate(Split(Upper($feature.STATE_NAME), ""), " ").
Step 4 - Line labels
const highways = new FeatureLayer({
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_Freeway_System/FeatureServer/2",
title: "Freeways",
outFields: ["ROUTE_NUM"],
labelsVisible: true,
labelingInfo: [
{
labelExpressionInfo: { expression: "$feature.ROUTE_NUM" },
symbol: {
type: "text",
color: "white",
haloColor: "#2b5797",
haloSize: 2,
font: { size: 10, family: "Noto Sans", weight: "bold" },
// A filled box makes a shield-like route marker
backgroundColor: [43, 87, 151, 0.9],
borderLineColor: "white",
borderLineSize: 1,
},
labelPlacement: "center-along", // ← polyline-only value
repeatLabel: true,
repeatLabelDistance: 250, // px between repeats along the line
minScale: 2000000,
maxScale: 0,
},
],
});
repeatLabel is line-specific and important. A 400 km highway labelled once is useless -
the user pans and loses the reference. Repeating every 250 px keeps it visible.
Step 5 - Toggle and debug
document.getElementById("labelsOn").addEventListener("change", (event) => {
cities.labelsVisible = event.target.checked;
states.labelsVisible = event.target.checked;
});
document.getElementById("deconflict").addEventListener("change", (event) => {
const strategy = event.target.checked ? "static" : "none";
// labelingInfo elements must be replaced, not mutated in place - the layer
// watches the property, not the objects inside it.
cities.labelingInfo = cities.labelingInfo.map((cls) => ({
...cls.toJSON(),
deconflictionStrategy: strategy,
}));
});
The comment is the lesson. cities.labelingInfo[0].deconflictionStrategy = "none" does
nothing - the SDK watches the labelingInfo property for assignment, not for deep mutation.
Same rule as renderers in Module 01. Build a new array.
Toggle deconfliction off at the national view and watch the map become an unreadable mess. That is what deconfliction is saving you from, and it's worth seeing once.
How it works
How deconfliction decides what to drop
Roughly: each candidate label gets a bounding box in screen space. The engine sorts candidates by priority - earlier label classes and higher layers first - and places them greedily, skipping any whose box intersects an already-placed one.
Two consequences:
- It is screen-space, so it changes with zoom and pan. A label visible at one position may vanish when you pan by 50 px. That's not a bug.
- Priority is your control. You can't tell it "always show this one," but you can put that label class first, or in a layer above.
Why labels re-render on every view change
Placement depends on screen position, which changes continuously. The label engine re-runs placement on pan and zoom.
That is why labels are a real performance cost at high feature counts. 50,000 labelled
points is much heavier than 50,000 unlabelled points. Scale ranges and where clauses aren't
just cartography - they're the performance fix. (Module 40.)
Why label classes and renderer classes are independent
A label class's where and a renderer's breaks are separate systems. You can label only the
top 10% of features while symbolising all of them, or symbolise by one field and label by
another.
This is more useful than it first sounds: "colour by land use, label only the parcels over 1 hectare" is one line in each system.
Labels in 3D
SceneView labels are drawn as screen-space billboards anchored to a 3D position. They:
- respect
elevationInfo- a label on anon-the-groundlayer sits on terrain - can be occluded by buildings unless the layer draws on top
- do not rotate with the camera (they stay upright and readable)
The API is the same. The pitfalls are Module 29's.
Common mistakes
labelsVisible left false.
It defaults to true on most layers, but a WebMap can carry false. Check it first.
A point labelPlacement on a polyline layer.
Silently no labels. center-along for lines.
No halo. Unreadable over anything but a flat pale background.
One label class for everything. Deconfliction eats most of them and you can't control which survive.
Mutating labelingInfo in place.
No redraw. Reassign the array.
labelExpression (3.x, "[FIELD]") instead of labelExpressionInfo.
Deprecated, and inconsistently supported.
Using a font the SDK doesn't serve. Silent fallback to Arial.
Labelling 100,000 features at every scale.
Frame rate collapses on pan. Scale ranges and where are the fix.
Exercises
Exercise 12.1 - Four-tier hierarchy
Take a layer with 5,000+ features from your local open data portal. Build a four-tier label hierarchy so that at every zoom level between country and street:
- No more than ~30 labels are on screen
- No labels overlap
- The most important features are always labelled
Screenshot at four zoom levels. This is a portfolio piece.
Exercise 12.2 - Multi-line and formatted
Build a label showing:
CITY NAME
Pop. 1,234,567
▲ 3.2% since 2010
using TextFormatting.NewLine, Text() for number formatting, and a conditional arrow
character based on whether growth is positive.
Handle nulls: a city with no 2010 figure should show only the first two lines.
Exercise 12.3 - Line labels done properly
Label a road network with:
- Route shields (background box, border) for numbered routes
- Plain text for named streets
- Repeating along long lines
- Nothing at all above 1:100,000
Two label classes with different where clauses on the same layer.
Exercise 12.4 - The deconfliction experiment
With a dense point layer, measure frame rate while panning under three configurations:
- No labels
- Labels on all features,
deconflictionStrategy: "static" - Labels on all features,
deconflictionStrategy: "none"
Use Chrome DevTools → Rendering → Frame Rendering Stats. Record the numbers and explain the ordering you observe.
Checkpoint
- Why is
labelingInfoan array? - What's
labelPlacementfor a polyline, and what happens if you useabove-center? - What does
whereon a label class do thatdefinitionExpressiondoesn't? - Your labels disappeared when you zoomed out. Two likely causes?
- Why does
layer.labelingInfo[0].symbol.color = "red"do nothing? - Why do labels cost more than symbols at high feature counts?
- What does
repeatLabeldo and when do you need it?
- Each element is a label class with its own expression, symbol, scale range and
where. The array is how you build a scale-and-importance hierarchy. - Polylines use
*-alongand*-start/*-endvalues -center-alongis the usual choice. A point placement value produces no labels at all, silently. whererestricts only which features are labelled; the features still draw.definitionExpressionremoves them from the layer entirely.- Deconfliction dropped them because of collisions, or the current scale is outside the label
class's
minScale/maxScalerange. - The SDK watches the
labelingInfoproperty for assignment, not for deep mutation. Build a new array and assign it. - Placement is computed in screen space and must be re-run on every pan and zoom, including collision detection between candidates.
- It draws the label repeatedly along a long line at
repeatLabelDistancepx intervals. You need it whenever a line is longer than a screen, or the label scrolls out of view and the user loses the reference.
Further reading
- https://developers.arcgis.com/javascript/latest/labeling/ - the labelling guide, including the full font list and every placement value
- https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-LabelClass.html
- https://developers.arcgis.com/javascript/latest/sample-code/labels-multiple-classes/
Level 2 complete. Take the L2 challenge and start Capstone 1 - City Explorer, then move on to Module 13 - Symbols.