RouteExample.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using Breda_Tour.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices.WindowsRuntime;
  8. using Windows.Devices.Geolocation;
  9. using Windows.Foundation;
  10. using Windows.Foundation.Collections;
  11. using Windows.Services.Maps;
  12. using Windows.UI;
  13. using Windows.UI.Core;
  14. using Windows.UI.Xaml;
  15. using Windows.UI.Xaml.Controls;
  16. using Windows.UI.Xaml.Controls.Maps;
  17. using Windows.UI.Xaml.Controls.Primitives;
  18. using Windows.UI.Xaml.Data;
  19. using Windows.UI.Xaml.Input;
  20. using Windows.UI.Xaml.Media;
  21. using Windows.UI.Xaml.Navigation;
  22. using Breda_Tour.MapScreen;
  23. // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
  24. namespace Breda_Tour.RouteSelectScreen
  25. {
  26. /// <summary>
  27. /// An empty page that can be used on its own or navigated to within a Frame.
  28. /// </summary>
  29. public sealed partial class RouteExample : Page
  30. {
  31. Route route;
  32. public string WaypointsText { get; set; }
  33. public string RouteTijdText { get; set; }
  34. public string LoopafstandText { get; set; }
  35. public RouteExample()
  36. {
  37. InitializeComponent();
  38. NavigationCacheMode = NavigationCacheMode.Enabled;
  39. }
  40. protected override void OnNavigatedTo(NavigationEventArgs e)
  41. {
  42. if (route == null)
  43. {
  44. route = e.Parameter as Route;
  45. ShowRouteInfo();
  46. }
  47. //Setting the back button functionality
  48. SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
  49. SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested;
  50. }
  51. private void BackRequested(object sender, BackRequestedEventArgs e)
  52. {
  53. e.Handled = true;
  54. SystemNavigationManager.GetForCurrentView().BackRequested -= BackRequested;
  55. MainPage.RootFrame.Navigate(typeof(RouteSelectPage));
  56. }
  57. private void Button_Click(object sender, RoutedEventArgs e)
  58. {
  59. MainPage.RootFrame.Navigate(typeof(MapPage), route);
  60. }
  61. private async void ShowRouteInfo()
  62. {
  63. //Setting the x amount of waypoints text
  64. WaypointsText = "Aantal waypoints: " + 0;
  65. if (route.Waypoints.Count != 0)
  66. {
  67. WaypointsText = "Aantal waypoints: " + route.Waypoints.Count;
  68. }
  69. //Setting the Route distance and time text
  70. List<Geopoint> geopoints = new List<Geopoint>();
  71. foreach (Waypoint wayPoint in route.Waypoints)
  72. {
  73. geopoints.Add(wayPoint.Position);
  74. }
  75. MapRouteFinderResult finder = await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(geopoints);
  76. if (finder.Status == MapRouteFinderStatus.Success)
  77. {
  78. //route duration
  79. int tijd = ((int)finder.Route.EstimatedDuration.TotalMinutes);
  80. RouteTijdText = $"Tijdsduur: {tijd} min";
  81. RouteBlok.Text = RouteTijdText;
  82. //Route distance
  83. LoopafstandText = $"Loopafstand: {(finder.Route.LengthInMeters/1000)} km";
  84. Loopblok.Text = LoopafstandText;
  85. //Waypoint text
  86. WaypointsBlok.Text = WaypointsText;
  87. ProgressRing.Visibility = Visibility.Collapsed;
  88. StartButton.Visibility = Visibility.Visible;
  89. }
  90. }
  91. private void Waypoints_OnItemClick(object sender, ItemClickEventArgs e)
  92. {
  93. Waypoint wp = e.ClickedItem as Waypoint;
  94. wp.FromPreview = true;
  95. MainPage.RootFrame.Navigate(typeof(WpDetailPage),wp);
  96. }
  97. }
  98. }