Service Areas Online

This sample demonstrates how to solve the routing problem of finding service areas for one or more facilities. Barriers in the form of points, lines, and polygons, can be placed across the line network to provide alternative optimal service areas. A variety of input parameters to modify the service area problem can be adjusted.

This is a fairly complex sample that has extensive use of XAML and code-behind to demonstrate the closet facility problem. Some of the main classes used in the sample are SimpleFillSymbol, SimpleLineSymbol, SimpleMarkerSymbol, Editor, GraphicsLayer, RouteTask, and RouteClosesFacilityParameters. To use this sample, click on a button to add facilities and barriers. Modify input properties to define the service areas parameters. Click the Solve button to generate results and display them in the map.

Download Sample Application
XAML C# VB.NET
<UserControl x:Class="ArcGISWPFSDK.ServiceAreas"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>
            <ControlTemplate x:Key="FacilityCompositeSymbol">
                <Grid>
                    <Rectangle RenderTransformOrigin="0.5,0.5" Fill="LightGreen" Width="20" Height="20" Stroke="Black" StrokeThickness="1" />
                    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
                  Text="{Binding Attributes[FacilityNumber]}"
                  FontSize="9" Margin="0" FontWeight="Bold" Foreground="Black" />
                </Grid>
            </ControlTemplate>
            <esri:SimpleMarkerSymbol x:Key="MyFacilitySymbol" Style="Square" 
                                     ControlTemplate="{StaticResource FacilityCompositeSymbol}" />
            <esri:SimpleFillSymbol x:Key="RedFillSymbol" Fill="#44FF0000" BorderBrush="#99000000" BorderThickness="1" />
            <esri:SimpleLineSymbol x:Key="RedLineSymbol" Color="Red" Width="2" Style="Solid" />
            <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
            <esri:SimpleFillSymbol x:Key="FillSymbol1" Fill="#77FF9999" BorderBrush="#FFFF9999" BorderThickness="2"  />
            <esri:SimpleFillSymbol x:Key="FillSymbol2" Fill="#77FFFF99" BorderBrush="#FFFFFF99" BorderThickness="2"  />
            <esri:SimpleFillSymbol x:Key="FillSymbol3" Fill="#779999FF" BorderBrush="#FF9999FF" BorderThickness="2"  />
            <esri:Editor x:Key="MyBarrierEditor" LayerIDs="MyBarrierGraphicsLayer"  />
            <esri:Editor x:Key="MyFacilityEditor" LayerIDs="MyFacilityGraphicsLayer" SelectionMode="Point" 
                          ContinuousMode="True" EditCompleted="Editor_EditCompleted" />
            <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.23,34.03,-117.16,34.08" Loaded="MyMap_Loaded" >
            <esri:Map.Layers>
                <esri:ArcGISTiledMapServiceLayer
                      Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
                <esri:GraphicsLayer ID="MyServiceAreasGraphicsLayer" />
                <esri:GraphicsLayer ID="MyBarrierGraphicsLayer" />
                <esri:GraphicsLayer ID="MyFacilityGraphicsLayer" />
            </esri:Map.Layers>
        </esri:Map>

        <Border Background="{StaticResource PanelGradient}" BorderThickness="1" CornerRadius="5"
                HorizontalAlignment="Right"  VerticalAlignment="Top"
                Margin="20,20,20,30" Padding="10" BorderBrush="Black">
            <Border.Effect>
                <DropShadowEffect/>
            </Border.Effect>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition MinHeight="80" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="150" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Background="Transparent" Margin="5" 
                            Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" >
                    <Button x:Name="AddFacButton" Margin="2" DataContext="{StaticResource MyFacilityEditor}"
                            Content="Add Facility" FontSize="12" Command="{Binding Add}"
                            CommandParameter="{StaticResource MyFacilitySymbol}"/>


                    <Border BorderBrush="White" BorderThickness="1" CornerRadius="5" Margin="5">
                        <StackPanel Orientation="Vertical" Margin="5">
                            <TextBlock x:Name="BarriersRadioButton" 
                                Margin="5,0,0,0" Foreground="White" 
                                FontSize="12" Text="Add Barrier:"/>
                            <StackPanel x:Name="DrawTools" Orientation="Horizontal"
                            DataContext="{StaticResource MyBarrierEditor}">
                                <Button x:Name="SelectButton" Margin="2" 
                            Content="Point" 
                            Command="{Binding Add}" 
                            CommandParameter="{StaticResource RedMarkerSymbol}">
                                </Button>
                                <Button x:Name="AddSelectButton" Margin="2" 
                            Content="Line" 
                            Command="{Binding Add}" 
                            CommandParameter="{StaticResource RedLineSymbol}">
                                </Button>
                                <Button x:Name="RemoveSelectButton" Margin="2" 
                            Content="Polygon"
                            Command="{Binding Add}"
                            CommandParameter="{StaticResource RedFillSymbol}">
                                </Button>
                            </StackPanel>
                        </StackPanel>
                    </Border>
                </StackPanel>
                <Button x:Name="SolveButton" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" 
                        Width="120" Height="40" Click="SolveButton_Click" Content="Solve" IsEnabled="False"  
                        FontSize="14" FontWeight="Bold" />
                <Border BorderBrush="White" Grid.Row="1" Grid.ColumnSpan="2" BorderThickness="1" CornerRadius="3" >
                    <ScrollViewer MinHeight="150" BorderThickness="0">
                        <Grid Background="Transparent" Width="328" Margin="12" VerticalAlignment="Center">
                            <Grid.Resources>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Foreground" Value="White"/>
                                    <Setter Property="VerticalAlignment" Value="Center" />
                                </Style>
                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="200"/>
                                <ColumnDefinition Width="125" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <TextBlock Text="Default Breaks:" Grid.Row="0" Grid.Column="0" Foreground="White"/>
                            <TextBox x:Name="DefaultBreaks" Text="1,2,3" Grid.Row="0" Grid.Column="1" />
                            <TextBlock Text="Exclude Sources From Polygons:" Grid.Row="1" Grid.Column="0" Foreground="White"/>
                            <TextBox x:Name="ExculdeSourcesFromPolygons" Grid.Row="1" Grid.Column="1" />
                            <CheckBox x:Name="MergeSimilarPolygonRanges" Grid.Row="2" Grid.ColumnSpan="2" Foreground="White"
                                                    Content="Merge Similar Polygon Ranges" />
                            <CheckBox x:Name="OverlapLines3" Grid.Row="3" Grid.ColumnSpan="2" Content="Overlap Lines" Foreground="White"
                                                    IsChecked="True"/>
                            <CheckBox x:Name="OverlapPolygons3" Grid.Row="4" Grid.ColumnSpan="2" Content="Overlap Polygons" Foreground="White"
                                                    IsChecked="True"/>
                            <CheckBox x:Name="SplitLinesAtBreaks" Grid.Row="5" Grid.ColumnSpan="2" Content="Split Lines At Breaks" Foreground="White" />
                            <CheckBox x:Name="SplitPolygonsAtBreaks" Grid.Row="6" Grid.ColumnSpan="2" Content="Split Polygons At Breaks" Foreground="White"
                                                    IsChecked="True"/>
                            <CheckBox x:Name="TrimOuterPolygons" Grid.Row="7" Grid.ColumnSpan="2" Foreground="White" Content="Trim Outer Polygons"  
                                                    IsChecked="True"/>
                            <TextBlock Text="Trim Polygon Distance:" Grid.Row="8" Grid.Column="0" Foreground="White"/>
                            <TextBox x:Name="TrimPolygonDistance" Text="100" Grid.Row="8" Grid.Column="1" />
                            <TextBlock Text="Trim Polygon Distance Units:" Grid.Row="9" Grid.Column="0" Foreground="White" />
                            <TextBlock Text="Trim Polygon Distance Units:" Grid.Row="9" Grid.Column="0" Foreground="White" />
                            <ComboBox x:Name="TrimPolygonDistanceUnits" Grid.Row="9" Grid.Column="1">
                                <ComboBoxItem Content="Unknown" IsSelected="True" />
                                <ComboBoxItem Content="Decimal Degrees" />
                                <ComboBoxItem Content="Kilometers" />
                                <ComboBoxItem Content="Meters" />
                                <ComboBoxItem Content="Miles" />
                                <ComboBoxItem Content="Nautical Miles" />
                                <ComboBoxItem Content="Inches" />
                                <ComboBoxItem Content="Points" />
                                <ComboBoxItem Content="Feet" />
                                <ComboBoxItem Content="Yards" />
                                <ComboBoxItem Content="Millimeters" />
                                <ComboBoxItem Content="Centimeters" />
                                <ComboBoxItem Content="Decimeters" />
                            </ComboBox>
                            <TextBlock Text="Output Spatial Reference:" Grid.Row="10" Grid.Column="0" Foreground="White"/>
                            <TextBox x:Name="OutputSpatialReference3" Text="4326" Grid.Row="10" Grid.Column="1" />
                            <TextBlock Text="Accumulate Attribute Names:" Grid.Row="11" Grid.Column="0" Foreground="White" />
                            <TextBox x:Name="AccumulateAttributeNames3" Grid.Row="11" Grid.Column="1" />
                            <TextBlock Text="Impedance Attribute Name:" Grid.Row="12" Grid.Column="0" Foreground="White" />
                            <TextBox x:Name="ImpedanceAttributeName3" Text="Time" Grid.Row="12" Grid.Column="1" />
                            <TextBlock Text="Restriction Attribute Names:" Grid.Row="13" Grid.Column="0" Foreground="White" />
                            <TextBox x:Name="RestrictionAttributeNames3" 
                                                  Text="Non-routeable segments,Avoid passenger ferries,TurnRestriction,OneWay"
                                                  Grid.Row="13" Grid.Column="1" />
                            <TextBlock Text="Attribute Parameter Values:" Grid.Row="14" Grid.Column="0" Foreground="White"/>
                            <ComboBox x:Name="AttributeParameterValues3" Grid.Row="14" Grid.Column="1">
                                <ComboBoxItem Content="None" IsSelected="True" />
                                <ComboBoxItem Content="15 MPH" />
                                <ComboBoxItem Content="20 MPH" />
                                <ComboBoxItem Content="25 MPH" />
                                <ComboBoxItem Content="35 MPH" />
                                <ComboBoxItem Content="45 MPH" />
                                <ComboBoxItem Content="50 MPH" />
                                <ComboBoxItem Content="55 MPH" />
                                <ComboBoxItem Content="65 MPH" />
                                <ComboBoxItem Content="Other Roads" />
                            </ComboBox>
                            <TextBlock Text="Restrict U-Turns:" Grid.Row="15" Grid.Column="0" Foreground="White"/>
                            <ComboBox x:Name="RestrictUTurns3" Grid.Row="15" Grid.Column="1">
                                <ComboBoxItem Content="Allow Backtrack" IsSelected="True" />
                                <ComboBoxItem Content="At Dead Ends Only" />
                                <ComboBoxItem Content="No Backtrack" />
                            </ComboBox>
                            <CheckBox x:Name="ReturnFacilities3" Foreground="White"
                                                    Grid.Row="16" Grid.ColumnSpan="2" Content="Return Facilities" />
                            <CheckBox x:Name="ReturnBarriers3" Foreground="White"
                                                    Grid.Row="17" Grid.ColumnSpan="2" Content="Return Barriers" />
                            <CheckBox x:Name="ReturnPolylineBarriers3" Foreground="White"
                                                    Grid.Row="18" Grid.ColumnSpan="2" Content="Return Polyline Barriers" />
                            <CheckBox x:Name="ReturnPolygonBarriers3" Foreground="White"
                                                    Grid.Row="19" Grid.ColumnSpan="2" Content="Return Polygon Barriers" />
                            <TextBlock Text="Output Lines:" Grid.Row="20" Grid.Column="0" Foreground="White" />
                            <ComboBox x:Name="OutputLines3" Grid.Row="20" Grid.Column="1">
                                <ComboBoxItem Content="None" IsSelected="True" />
                                <ComboBoxItem Content="True Shape" />
                            </ComboBox>
                            <TextBlock Text="Output Polygons:" Grid.Row="21" Grid.Column="0" Foreground="White"  />
                            <ComboBox x:Name="OutputPolygons" Grid.Row="21" Grid.Column="1">
                                <ComboBoxItem Content="None"/>
                                <ComboBoxItem Content="Simplified" IsSelected="True" />
                                <ComboBoxItem Content="Detailed" />
                            </ComboBox>
                            <TextBlock Text="Travel Direction:" Grid.Row="22" Grid.Column="0" Foreground="White"/>
                            <ComboBox x:Name="TravelDirections3" Grid.Row="22" Grid.Column="1">
                                <ComboBoxItem Content="From Facility" IsSelected="True" />
                                <ComboBoxItem Content="To Facility" />
                            </ComboBox>
                            <TextBlock Text="Output Geometry Precision:" Grid.Row="23" Grid.Column="0" Foreground="White"/>
                            <TextBox x:Name="OutputGeometryPrecision3" Grid.Row="23" Grid.Column="1" />
                            <TextBlock Text="Output Geometry Precision Units:" Grid.Row="24" Grid.Column="0" Foreground="White"/>
                            <ComboBox x:Name="OutputGeometryPrecisionUnits3" Grid.Row="24" Grid.Column="1">
                                <ComboBoxItem Content="Unknown" IsSelected="True" />
                                <ComboBoxItem Content="Decimal Degrees" />
                                <ComboBoxItem Content="Kilometers" />
                                <ComboBoxItem Content="Meters" />
                                <ComboBoxItem Content="Miles" />
                                <ComboBoxItem Content="Nautical Miles" />
                                <ComboBoxItem Content="Inches" />
                                <ComboBoxItem Content="Points" />
                                <ComboBoxItem Content="Feet" />
                                <ComboBoxItem Content="Yards" />
                                <ComboBoxItem Content="Millimeters" />
                                <ComboBoxItem Content="Centimeters" />
                                <ComboBoxItem Content="Decimeters" />
                            </ComboBox>
                        </Grid>
                    </ScrollViewer>
                </Border>
            </Grid>
        </Border>

    </Grid>
</UserControl>

Sample code usage restrictions
5/16/2014