private async void CalculateRoute() { Overlays[0].Graphics.Clear(); HasRoute = false; OnPropertyChanged(nameof(HasRoute)); if (Overlays[1].Graphics[0].Geometry == null || Overlays[1].Graphics[1].Geometry == null) { return; //We don't have both to and from destination, so return } var t1 = RouteHelper.RouteAsync(Overlays[1].Graphics[0].Geometry as MapPoint, Overlays[1].Graphics[1].Geometry as MapPoint, false); var t2 = RouteHelper.RouteAsync(Overlays[1].Graphics[0].Geometry as MapPoint, Overlays[1].Graphics[1].Geometry as MapPoint, true); var route1 = await t1; if (route1 != null) { Overlays[0].Graphics.Add(new Graphic(route1.RouteGeometry)); WalkTime = route1.TotalTime.ToString("m\\:ss"); WalkDistance = route1.TotalLength.ToString("0") + " m"; OnPropertyChanged(nameof(WalkTime)); OnPropertyChanged(nameof(WalkDistance)); } var route2 = await t2; if (route2 != null) { Overlays[0].Graphics.Insert(0, new Graphic(route2.RouteGeometry) { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, Color.Black, 2) }); WalkTimeAlt = route2.TotalTime.ToString("m\\:ss"); WalkDistanceAlt = route1.TotalLength.ToString("0") + " m"; OnPropertyChanged(nameof(WalkTimeAlt)); OnPropertyChanged(nameof(WalkDistanceAlt)); } HasRoute = route1 != null; OnPropertyChanged(nameof(HasRoute)); OnPropertyChanged(nameof(NoRoute)); if (HasRoute) { ZoomToData(); } RouteUpdated?.Invoke(this, EventArgs.Empty); if (route1 == null && route2 == null) { MapViewModel.RaiseErrorMessage("No possible route found"); } }
public virtual void OnRouteUpdated(EventArgs e) { RouteUpdated?.Invoke(this, e); }