View in MAUI UWP WPF WinUI View on GitHub
import InlineCode from "@esri-dx/starship-doc-components/components/InlineCode.astro";

Display custom labels on a feature layer.

Image of show labels on layers

Use case

Labeling features is useful to visually display a key piece of information or attribute of a feature on a map. For example, you may want to label rivers or streets with their names.

How to use the sample

Pan and zoom around the United States. Labels for congressional districts will be shown in red for Republican districts and blue for Democrat districts. Notice how labels pop into view as you zoom in.

How it works

  1. Create a
    using a feature service URL.
  2. Create a
    from the service feature table.
  3. Create a
    to use for displaying the label text.
  4. Create an
    for the label definition.
    • You can use fields of the feature by using
      in the expression.
  5. Create a new
    from the arcade label expression and text symbol.
  6. Add the definition to the feature layer with
    .
  7. Lastly, enable labels on the layer using
    .

Relevant API

  • ArcadeLabelExpression
  • FeatureLayer
  • LabelDefinition
  • TextSymbol

About the data

This sample uses the USA 116th Congressional Districts feature layer hosted on ArcGIS Online.

Additional information

Help regarding the Arcade label expression script for defining a label definition can be found on the ArcGIS Developers site.

Tags

arcade, attribute, deconfliction, label, labeling, string, symbol, text, visualization

Sample Code

ShowLabelsOnLayer.xaml ShowLabelsOnLayer.xaml ShowLabelsOnLayer.xaml.cs
<UserControl x:Name="_this"
x:Class="ArcGIS.WinUI.Samples.ShowLabelsOnLayer.ShowLabelsOnLayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<Grid>
<esriUI:MapView x:Name="MyMapView" />
</Grid>
</UserControl>