Feature layers, graphics overlays, and map image layer sublayers in your app can be labeled using a combination of attribute values, text strings, and values calculated with an expression. You can determine how labels are positioned and prioritized, and how conflicts between overlapping labels are automatically and dynamically resolved.
NoteAll available labeling properties are provided as classes and members in the API. You do not need to build raw JSON definitions to work with them.
Support is provided, however, to allow you to serialize and deserialize these JSON label definitions to work with labeling in your app. You can create JSON label definition strings according to the Web map specification for labels.
For feature layers, graphics overlays, and map image sublayers, labeling is implemented using a collection of LabelDefinition
objects to define things like:
If you want to label everything in your layer or overlay the same way, you can define a single label definition. If you want to display different labels for different attribute values, you can add as many label definitions as you need to define distinct sets of geoelements for labeling.
TopicFor a list of all supported ArcGIS Maps SDKs for Native Apps labeling properties, their values and ArcGIS Pro export interpretations, see the Labeling properties manual.
Define labelsLabel definitions establish the label text and how labels are rendered for a specified group of geoelements using attributes, which provide the label text as well as determine which label is applied to each geoelement. The map in the following image uses three label definitions: one with a large blue label for cities with populations over 1.5 million, smaller black labels for cities between 0.5 and 1.5 million, and a small gray label for cities under 0.5 million. For the label text, each definition uses the value from the name
attribute.
Expand
Use dark colors for code blocks Copy1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Creates a label definition with the appropriate symbol for small cities.
let smallExpression = ArcadeLabelExpression(arcadeString: "return $feature.name;")
let labelDefSmall = LabelDefinition(labelExpression: smallExpression, textSymbol: textSymbolSmallCities)
labelDefSmall.whereClause = "[POPULATION] < 500000"
labelDefSmall.placement = .pointBelowCenter
// Adds the label definitions to the city layerâs label definitions collection.
citiesLayer.addLabelDefinition(labelDefSmall)
// Enables labels for the layer so they appear.
citiesLayer.labelsAreEnabled = true
Each label's symbol, text, placement, overlap rules, and so on is represented with a LabelDefinition
and is constructed to conform to label properties defined in the Web map specification for labels. In order to provide a more accurate representation of labels created using ArcGIS Pro (for a mobile map package, for example), additional label properties are defined that are not included in the web map specification. These properties provide additional control for things like the layout, orientation, and stacking of label text and label overlap behavior. See the LabelDefinition
class for details.
ArcGIS Pro uses the same concept of label definitions, called label classes. Label classes on feature layers in ArcGIS Pro are used to generate dynamic labels (which resize and move with changes in the map view). Should the position and size of text need to be fixed, you can convert labels to static annotation features in an annotation layer using ArcGIS Pro.
Most properties for a label definition are optional and will use a default value if not assigned explicitly. At a minimum, you must provide an expression that defines the label text and a symbol (with at least color, font size, and type) to display labels for a layer. Refer to the label properties section for a description of some common properties available for label definitions.
Label propertiesThe following list describes some common aspects of label display and behavior that you can control in a label definition. Relevant classes and members are shown in parentheses.
Which geoelements to label (LabelDefinition.whereClause
)âThe geoelements labeled with the label definition are determined by evaluating an attribute expression. This expression is defined using SQL syntax, Arcade expressions are not supported for defining a label definition's where clause. If this expression is not defined, all elements are included in the definition. When using multiple label definitions, it's important that expressions uniquely assign geoelements for each definition. Creating multiple label definitions for a single layer is useful when you want to distinguish labels for certain types of elements. When labeling a cities layer, for example, you may want to distinguish capital cities from the others by using a larger font or different color.
Label text (LabelDefinition.expression
, SimpleLabelExpression
, ArcadeLabelExpression
, WebmapLabelExpression
)âA label expression can be used to determine the text to display for each geoelement in the label definition. The label text can come from a combination of available attributes, text strings, and expressions. A label showing length in meters from values in feet from an attribute named length_ft
, for example, may use an Arcade expression like this: ($feature.length_ft * 0.3048) + ' meters'
. A feature with a length_ft
value of 343
would display a label of 104.546 meters
. See the Label expressions section for more details and examples.
Text symbol (LabelDefinition.textSymbol
, TextSymbol
)âThe font, size, color, angle, and so on, used to display labels in the definition. You can also provide a background color or halo for the text symbol.
Display scale range (LabelDefinition.minScale
, LabelDefinition.maxScale
)âThe scale range, defined with a minimum and maximum scale denominator, at which labels in the definition will be displayed. A value of 0
for one of the range values means that the end of the range is not restricted.
Placement (LabelDefinition.placement
, LabelingInfo.LabelPlacement
)âLabels can be placed at a specified position relative to the elements they describe. There are different options for placement depending upon the geometry of the geoelements being labeled. Line features, for example, may have labels placed above the center of the line, below the center of the line, above the end point, and so on. The default is automatic. Depending upon the type of geometry, this means:
Priority (LabelDefinition.priority
)âA label definition can be given a priority relative to other definitions in the layer. If labels from different definitions conflict in their placement, the label from the highest-priority definition will be displayed. Values indicate priority relative to other label definitions, with lower values indicating higher priority. If priority is not specified, a default prioritization is used based on geometry type: points (top priority), followed by lines, and then polygons.
Label overlap (LabelDefinition.deconflictionStrategy
, LabelDefinition.labelOverlapStrategy
, LabelDefinition.DeconflictionStrategy
, LabelDefinition.LabelOverlapStrategy
)âControl label overlap with geoelements and other labels.
Duplicate or repeating labels (LabelDefinition.removeDuplicatesStrategy
, LabelDefinition.repeatStrategy
, LabelDefinition.multipartStrategy
)âYou can define preferences for removing duplicate labels within a specified radius as well as for repeating labels along lines at a constant interval. You can also control how geoelements with multipart geometry should be labeled.
Label display can also be affected by applying a reference scale to the map. Reference scale is the scale at which symbols and labels appear at their intended, true size. As you zoom in and out beyond the reference scale, symbols and text will increase or decrease in size relative to the reference scale to keep a consistent size on the map. If no reference scale is set, symbols remain a constant size on the screen and do not change size as you zoom in or out. Individual layers in a map can opt in or out of honoring the map's reference scale.
Label expressionsDepending upon your use case, you can define text for your labels using one of the following types of label expression classes:
ArcadeLabelExpression
âAn expression that uses the ArcGIS Arcade expression language to define label text.SimpleLabelExpression
âA simple label expression that uses the ArcGIS REST API labeling syntax.WebmapLabelExpression
âA web map script to be read and evaluated by a web map expression interpreter.Arcade is a simple, lightweight scripting language that can evaluate expressions at runtime. It was designed specifically for creating custom visualizations and labeling expressions in ArcGIS. Users can write, share, and execute custom expressions in ArcGIS Pro, ArcGIS Online, ArcGIS Maps SDK for JavaScript, and ArcGIS Maps SDKs for Native Apps.
NoteLabel definitions for a map image layer must use simple expressions based on the ArcGIS Server REST API for label expressions. Arcade expressions are not supported for labels rendered by ArcGIS Server.
You can access feature attributes using Arcade's $feature
global variable. For example, to label roads with a STREET_NAME
field, you can refer to the value in that attribute with this syntax: $feature.STREET_NAME
. Arcade also provides built-in functions for mathematical calculations, logical operations, and formatting that you can use in your expression. Consult the Arcade guide for details and usage examples.
When defining a label, the final line of the expression must evaluate to a string or a number.
The following Arcade expression reads the attribute values for wind speed and direction. It then uses conditional logic (When
function) to assign a cardinal direction based on azimuth. Another conditional function (IIf
) is used to return an empty string for wind speeds of 0
and a formatted label for all other values.
Use dark colors for code blocks Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
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 IIf(SPEED > 0, SPEED + ' mph ' + DIR, '');
Simple expressions
Simple expressions use ArcGIS REST API syntax. You can use functions in the expression to provide basic formatting of values, such as ROUND()
, CONCAT
, and FORMATDATETIME()
. See JSON labeling objects for more information.
The simple expression below creates a label that combines static text, city name, and population. Note that the static text must be inside quotes.
Use dark colors for code blocks Copy
1
[NAME] CONCAT NEWLINE CONCAT \"(Pop=\" CONCAT [POPULATION] CONCAT \")\"
Web map expressions
A WebmapLabelExpression
expression provides a legal web map script to be read and evaluated by a web map expression interpreter.
A web map label expression that combines static text with an attribute value will look like this: State {State_Name}
.
Note that unlike a simple or Arcade expression, quotes are not needed around the literal text.
Use text formatting tagsText used for labels can contain some of the same formatting tags used by ArcGIS Pro. These tags are similar to HTML tags and are used to modify the appearance of the text. The following tags are supported:
<FNT>
âFont name, size, and scaling.<CLR>
âColor (defined with RGB or CMYK values).<BOL>
, <_BOL>
âBold / un-bold.<ITA>
, <_ITA>
âItalic / un-italic.<UND>
, <_UND>
âUnderline / un-underline.These tags allow you to format parts of the text differently than what has been defined for the label's text symbol. The following expression, for example, displays the name
attribute with bold, underlined text. The rest of the text uses the unaltered text symbol previously defined for the label definition.
Use dark colors for code blocks Copy
1
2
"return \"<BOL><UND>\" + $feature.name + \"</UND></BOL>\" + TextFormatting.NewLine +
\"(Population=\" + $feature.population + \")\";"
See the Text formatting tags topic in the ArcGIS Pro documentation for more information about these formatting tags and how they can be used with your labels.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4