Routing with Barriers Online

This sample demonstrates use of the RouteTask to calculate routes when barriers exist. To use the sample, select whether to add stops or add barriers from the dialog in the upper right of the application, then click points on the map. Each time you click, a barrier or stop will be added. When a new stop is added, the route between the new stop and the last stop will be calculated and shown on the map.

In the code-behind, a RouteTask is used to calculate the route between the stops. The barriers are maintained in a list of graphics and specified in the RouteTask's parameters when a route operation is executed. When route results are returned, the route geometry is added to the map.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.RoutingBarriers"
    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>
            <ControlTemplate x:Key="CompositeSymbol">
                <Grid>
                    <Ellipse Fill="{Binding Symbol.Color}" Width="{Binding Symbol.Size}" Height="{Binding Symbol.Size}" Stroke="Black" StrokeThickness="1" />
                    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
                  Text="{Binding Path=Attributes[StopNumber]}"
                  FontSize="9" Margin="0" FontWeight="Bold" Foreground="Black" />
                </Grid>
            </ControlTemplate>
            <esri:SimpleMarkerSymbol x:Key="StopSymbol" Size="20" Style="Circle" Color="Salmon" ControlTemplate="{StaticResource CompositeSymbol}" />
            <esri:SimpleMarkerSymbol x:Key="BarrierSymbol" Size="15" Style="Square" Color="Red"  />
            <esri:SimpleLineSymbol x:Key="RouteSymbol" Color="#990000FF" Width="5"/>
            <LinearGradientBrush x:Key="PanelGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                <LinearGradientBrush.RelativeTransform>
                    <TransformGroup>
                        <ScaleTransform CenterY="0.5" CenterX="0.5"/>
                        <SkewTransform CenterY="0.5" CenterX="0.5"/>
                        <RotateTransform Angle="176" CenterY="0.5" CenterX="0.5"/>
                        <TranslateTransform/>
                    </TransformGroup>
                </LinearGradientBrush.RelativeTransform>
                <GradientStop Color="#FF145787" Offset="0.16"/>
                <GradientStop Color="#FF3D7FAC" Offset="0.502"/>
                <GradientStop Color="#FF88C5EF" Offset="0.984"/>
            </LinearGradientBrush>
        </Grid.Resources>
        <esri:Map x:Name="MyMap" 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="MyRouteGraphicsLayer" />
                <esri:GraphicsLayer ID="MyStopsGraphicsLayer" />
                <esri:GraphicsLayer ID="MyBarriersGraphicsLayer" />
            </esri:Map.Layers>
        </esri:Map>

        <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10" >
            <Rectangle Fill="{StaticResource PanelGradient}" Stroke="Gray"  RadiusX="10" RadiusY="10" Margin="0" >
                <Rectangle.Effect>
                    <DropShadowEffect/>
                </Rectangle.Effect>
            </Rectangle>
            <StackPanel Orientation="Horizontal" Margin="5">
                <RadioButton Content="Add Stops" x:Name="StopsRadioButton" IsChecked="true"  
                        Foreground="White" GroupName="add" VerticalAlignment="Center" />
                <RadioButton Content="Add Barriers" x:Name="BarriersRadioButton" 
                        Foreground="White" GroupName="add" VerticalAlignment="Center" />
                <Button Content="Clear" Click="Button_Click" Margin="5,0,0,0"/>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014