/// <summary> /// Finish initializations after setting the viewmodel /// </summary> /// <returns></returns> private async Task InitializeFromViewModel() { this.DataContext = this.ViewModel; ProgressIndicatorHelper.Instance.Push(LoadingEnum.Stops); //PIHelper.Push("Getting stops..."); //var ls = await TransitInfo.GetStopsOfRoute(this.ViewModel.Context); if (!ViewModel.Context.Stop_Ids.Any(id => !AppSettings.KnownStops.Value.ContainsKey(id)) || TransitLoader.InternetAvailable()) { await ViewModel.GetStopsOfRoute(); } ProgressIndicatorHelper.Instance.Remove(LoadingEnum.Stops); // Center the map if (this.ViewModel.Stops.Count > 0) { this.MapItems.ItemsSource = this.ViewModel.Stops; this.startup = false; this.ResultsMap.SetView(LocationRectangle.CreateBoundingRectangle(this.ViewModel.Stops.Select(s => s.Location))); } else { this.startup = false; } }
/// <summary> /// Search the text in the route box /// </summary> /// <returns></returns> private async Task SearchRoutes() { this.Focus(); // Blank route if (this.RouteSearchBox.Text == EmptyTextBox || string.IsNullOrWhiteSpace(this.RouteSearchBox.Text)) { MessageBox.Show("Please enter the number of a bus route in your area.", "No input", MessageBoxButton.OK); return; } ProgressIndicatorHelper.Instance.Push(LoadingEnum.Routes); BusRoute br = await TransitInfo.SearchForRoute(this.RouteSearchBox.Text); if (br == null && !AppSettings.LocationConsent.Value && LocationTracker.GetPermission()) { br = await TransitInfo.SearchForRoute(this.RouteSearchBox.Text); } ProgressIndicatorHelper.Instance.Remove(LoadingEnum.Routes); if (br == null) { TransitLoader.InternetAvailable(); MessageBox.Show(string.Format("Could not find route {0}.", this.RouteSearchBox.Text), "No matches", MessageBoxButton.OK); return; } this.RouteSearchBox.Text = ""; if (this.SpacingPanel.Height == spacerMaxHeight) { this.SetSearchBarVisibility(Visibility.Collapsed); } NavigationService.Navigate(new Uri( string.Format("/Pages/StopResultPage.xaml?route_id={0}", br.Id), UriKind.Relative)); //NavigationService.Navigate(new Uri("/Pages/StopResultPage.xaml", UriKind.Relative)); }