Routing Online

This sample demonstrates simple use of the RouteTask. To use the sample, click points on the map. As new points are added, routes between the new point and the last point are calculated and displayed on the map.

In the code-behind, a RouteTask is used to calculate the route between the clicked points. The route geometry contained in the task results is then simply added to a GraphicsLayer in the map.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.Routing"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <esri:SimpleMarkerSymbol x:Key="StopSymbol" Size="15" Style="Triangle" Color="Green" />
            <esri:SimpleLineSymbol x:Key="RouteSymbol" Color="#990000FF" Width="5"/>
            <esri:RouteTask 
                x:Key="MyRouteTask"
                Failed="MyRouteTask_Failed"
                SolveCompleted="MyRouteTask_SolveCompleted"
                Url="http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route" />
        </Grid.Resources>
        <esri:Map x:Name="MyMap" WrapAround="True" Background="White" Extent="-117.22,34.04,-117.17,34.07"
                  MouseClick="MyMap_MouseClick">
            <esri:Map.Layers>
                <esri:ArcGISTiledMapServiceLayer
                      Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
                <esri:GraphicsLayer ID="MyStopsGraphicsLayer" />
                <esri:GraphicsLayer ID="MyRouteGraphicsLayer" >
                    <esri:GraphicsLayer.MapTip>
                        <Grid>
                            <Rectangle RadiusX="10" RadiusY="10" Fill="#22000000" Margin="5,5,-5,-5" />
                            <Rectangle RadiusX="5" RadiusY="5" Margin="3" >
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint="1.038,1.136" StartPoint="0.015,0.188">
                                        <GradientStop Color="#FFD1DFF2"/>
                                        <GradientStop Color="#FF092959" Offset="0.946"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Border CornerRadius="10" BorderBrush="#FF222957" BorderThickness="3" />
                            <StackPanel Orientation="Vertical" Margin="15,10,15,10">
                                <TextBlock Text="Total Time:" Foreground="#FFFFFFFF" FontSize="10"  />
                                <TextBlock Text="{Binding [TIP]}" Foreground="#FFFFFFFF" FontSize="10" />
                            </StackPanel>
                        </Grid>
                    </esri:GraphicsLayer.MapTip>
                </esri:GraphicsLayer>
            </esri:Map.Layers>
        </esri:Map>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014