View in MAUI WPF WinUI View on GitHub

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 PortalItem with the default portal and item ID.
  2. Create and load a FeatureCollection with the item.
  3. After loading, get the FeatureCollectionTable containing turn-by-turn directions.
  4. Set the ItemSource of the collection displaying directions to the FeatureCollectionTable.
  5. Create a FeatureCollectionLayer with the feature collection and set it to the map’s OperationalLayers.

Relevant API

  • AGSFeatureCollection
  • AGSFeatureCollectionLayer
  • AGSFeatureCollectionTable

Tags

directions, feature collection, route layer

Sample Code

DisplayRouteLayer.xaml DisplayRouteLayer.xaml DisplayRouteLayer.xaml.cs
<UserControl x:Class="ArcGIS.WPF.Samples.DisplayRouteLayer.DisplayRouteLayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:ArcGIS.WPF.Viewer.Converters"
xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
<UserControl.Resources>
<converters:DirectionPointTypeToIconConverter x:Key="Converter" />
</UserControl.Resources>
<Grid>
<esri: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="22" />
<ColumnDefinition Width="25" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Margin="0,0,5,5"
HorizontalAlignment="Right"
Text="{Binding Attributes[Sequence], StringFormat={}{0}.}" />
<TextBlock Grid.Column="1"
Margin="0,0,5,5"
FontFamily="{StaticResource CalciteUIIconsMediumFontFamily}"
FontSize="24"
Text="{Binding Attributes[DirectionPointType], Converter={StaticResource Converter}}" />
<TextBlock Grid.Column="2"
Text="{Binding Attributes[DisplayText]}"
TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</Border>
</Grid>
</UserControl>