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

Display a route layer and its directions using a feature collection.

Display route layer

Use case

Routes can be stored as feature collection layers. These layers can store useful information such as directions, estimated trip time, and more.

You can create a route layer in ArcGIS Pro and store a route layer as a portal item, making it easy to access, share, or display.

How to use the sample

Pan and zoom to view the route displayed by the feature collection layer. Toggle to view or hide the turn-by-turn directions.

How it works

  1. Create a
    with the default portal and item ID.
  2. Create and load a
    with the item.
  3. After loading, get the
    containing turn-by-turn directions.
  4. Set the
    of the collection displaying directions to the
    .
  5. Create a
    with the feature collection and set it to the map’s
    .

Relevant API

  • AGSFeatureCollection
  • AGSFeatureCollectionLayer
  • AGSFeatureCollectionTable

Tags

directions, feature collection, route layer

Sample Code

DisplayRouteLayer.xaml DisplayRouteLayer.xaml DisplayRouteLayer.xaml.cs
<UserControl x:Class="ArcGIS.WinUI.Samples.DisplayRouteLayer.DisplayRouteLayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:ArcGIS.WinUI.Viewer.Converters"
xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
<UserControl.Resources>
<converters:DirectionPointTypeToIconConverter x:Key="Converter" />
</UserControl.Resources>
<Grid>
<esriUI:MapView x:Name="MyMapView" />
<Border Height="300" Style="{StaticResource BorderStyle}">
<ScrollViewer Height="250" VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock FontWeight="Bold" Text="Directions:" />
<ItemsControl x:Name="DirectionsList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="2" />
<ColumnDefinition Width="25" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Right" Text="{Binding Attributes[Sequence]}" />
<TextBlock Grid.Column="1" Text="." />
<TextBlock Grid.Column="2"
Margin="0,0,0,10"
FontFamily="{StaticResource CalciteUIIconsMediumFontFamily}"
FontSize="24"
Text="{Binding Attributes[DirectionPointType], Converter={StaticResource Converter}}" />
<TextBlock Grid.Column="3"
Text="{Binding Attributes[DisplayText]}"
TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</Border>
</Grid>
</UserControl>