A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.arcgis.com/swift/styles-and-data-visualization/add-labels/ below:

Add labels | ArcGIS Maps SDK for Swift

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.

Note

All 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.

Topic

For 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 labels

Label 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 Copy
1
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.

Note

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 properties

The 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.

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 expressions

Depending upon your use case, you can define text for your labels using one of the following types of label expression classes:

Arcade expressions

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.

Note

Label 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 tags

Text 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:

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