private void Route_Complete(object sender, CalculateRouteCompletedEventArgs args)
{
myDrawObject.IsEnabled = true;
routeResultsGraphicsLayer.ClearGraphics();
waypointGraphicsLayer.ClearGraphics();
StringBuilder directions = new StringBuilder();
ObservableCollection<RouteLeg> routeLegs = args.Result.Result.Legs;
int numLegs = routeLegs.Count;
int instructionCount = 0;
for (int n = 0; n < numLegs; n++)
{
if ((n % 2) == 0)
{
AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualStart.Longitude, routeLegs[n].ActualStart.Latitude)));
AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
}
else if (n == (numLegs - 1))
{
AddStopPoint(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(routeLegs[n].ActualEnd.Longitude, routeLegs[n].ActualEnd.Latitude)));
}
directions.Append(string.Format("--Leg #{0}--\n", n + 1));
foreach (ItineraryItem item in routeLegs[n].Itinerary)
{
instructionCount++;
directions.Append(string.Format("{0}. {1}\n", instructionCount, item.Text));
}
}
Regex regex = new Regex("<[/a-zA-Z:]*>",
RegexOptions.IgnoreCase | RegexOptions.Multiline);
DirectionsContentTextBlock.Text = regex.Replace(directions.ToString(), string.Empty);
DirectionsGrid.Visibility = Visibility.Visible;
RoutePath routePath = args.Result.Result.RoutePath;
Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline();
line.Paths.Add(new ESRI.ArcGIS.Client.Geometry.PointCollection());
foreach (ESRI.ArcGIS.Client.Bing.RouteService.Location location in routePath.Points)
line.Paths[0].Add(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(location.Longitude, location.Latitude)));
Graphic graphic = new Graphic()
{
Geometry = line,
Symbol = LayoutRoot.Resources["RoutePathSymbol"] as Symbol
};
routeResultsGraphicsLayer.Graphics.Add(graphic);
}