RouteExample.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using Breda_Tour.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using Windows.Devices.Geolocation;
  6. using Windows.Services.Maps;
  7. using Windows.UI;
  8. using Windows.UI.Core;
  9. using Windows.UI.Xaml;
  10. using Windows.UI.Xaml.Controls;
  11. using Windows.UI.Xaml.Controls.Maps;
  12. using Windows.UI.Xaml.Navigation;
  13. using Breda_Tour.MapScreen;
  14. namespace Breda_Tour.RouteSelectScreen
  15. {
  16. public sealed partial class RouteExample : Page
  17. {
  18. Route route;
  19. public string WaypointsText { get; set; }
  20. public string RouteTijdText { get; set; }
  21. public string LoopafstandText { get; set; }
  22. public static bool fromRouteExamp;
  23. public static MapRouteView routeView;
  24. public RouteExample()
  25. {
  26. MapService.ServiceToken =
  27. "P4P2fAwXuk7ndsVIsaaV~uYjur55RgwmLsiwFwd72bQ~ApDRixf1L-0o_kMY8EtBBDm8xe7G2oz1k2-u0HQIATvSp-iiKr5KLNkYc1HF5D5e";
  28. InitializeComponent();
  29. }
  30. protected override void OnNavigatedTo(NavigationEventArgs e)
  31. {
  32. route = e.Parameter as Route;
  33. ShowRouteInfo();
  34. //Setting the back button functionality
  35. SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
  36. SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested;
  37. }
  38. private void BackRequested(object sender, BackRequestedEventArgs e)
  39. {
  40. e.Handled = true;
  41. SystemNavigationManager.GetForCurrentView().BackRequested -= BackRequested;
  42. MainPage.RootFrame.Navigate(typeof(RouteSelectPage));
  43. }
  44. private void Button_Click(object sender, RoutedEventArgs e)
  45. {
  46. fromRouteExamp = true;
  47. MainPage.RootFrame.Navigate(typeof(MapPage), route);
  48. }
  49. private async void ShowRouteInfo()
  50. {
  51. //Setting the x amount of waypoints text
  52. WaypointsText = "Aantal waypoints: " + 0;
  53. if (route.Waypoints.Count != 0)
  54. {
  55. WaypointsText = "Aantal waypoints: " + route.Waypoints.Count;
  56. }
  57. //Setting the Route distance and time text
  58. List<Geopoint> geopoints = new List<Geopoint>();
  59. foreach (Waypoint wayPoint in route.Waypoints)
  60. {
  61. geopoints.Add(wayPoint.Position);
  62. }
  63. MapRouteFinderResult finder = await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(geopoints);
  64. Debug.Write("Finder status: " + finder.Status);
  65. if (finder.Status == MapRouteFinderStatus.Success)
  66. {
  67. //Create route for mapPage
  68. routeView = new MapRouteView(finder.Route);
  69. routeView.RouteColor = Colors.Firebrick;
  70. routeView.OutlineColor = Colors.Black;
  71. //route duration
  72. int tijd = ((int) finder.Route.EstimatedDuration.TotalMinutes);
  73. RouteTijdText = $"Tijdsduur: {tijd} min";
  74. RouteBlok.Text = RouteTijdText;
  75. //Route distance
  76. LoopafstandText = $"Loopafstand: {(Convert.ToInt32(finder.Route.LengthInMeters/1000))} km";
  77. Loopblok.Text = LoopafstandText;
  78. //Waypoint text
  79. WaypointsBlok.Text = WaypointsText;
  80. ProgressRing.Visibility = Visibility.Collapsed;
  81. StartButton.Visibility = Visibility.Visible;
  82. }
  83. }
  84. private void Waypoints_OnItemClick(object sender, ItemClickEventArgs e)
  85. {
  86. Waypoint wp = e.ClickedItem as Waypoint;
  87. wp.FromPreview = true;
  88. Tuple<Waypoint, Route> t = new Tuple<Waypoint, Route>(wp, route);
  89. MainPage.RootFrame.Navigate(typeof(WpDetailPage),t);
  90. }
  91. }
  92. }