RouteExample.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 static bool fromRouteExamp;
  36. public static MapRouteView routeView;
  37. public RouteExample()
  38. {
  39. MapService.ServiceToken =
  40. "P4P2fAwXuk7ndsVIsaaV~uYjur55RgwmLsiwFwd72bQ~ApDRixf1L-0o_kMY8EtBBDm8xe7G2oz1k2-u0HQIATvSp-iiKr5KLNkYc1HF5D5e";
  41. InitializeComponent();
  42. }
  43. protected override void OnNavigatedTo(NavigationEventArgs e)
  44. {
  45. route = e.Parameter as Route;
  46. ShowRouteInfo();
  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. fromRouteExamp = true;
  60. MainPage.RootFrame.Navigate(typeof(MapPage), route);
  61. }
  62. private async void ShowRouteInfo()
  63. {
  64. //Setting the x amount of waypoints text
  65. WaypointsText = "Aantal waypoints: " + 0;
  66. if (route.Waypoints.Count != 0)
  67. {
  68. WaypointsText = "Aantal waypoints: " + route.Waypoints.Count;
  69. }
  70. //Setting the Route distance and time text
  71. List<Geopoint> geopoints = new List<Geopoint>();
  72. foreach (Waypoint wayPoint in route.Waypoints)
  73. {
  74. geopoints.Add(wayPoint.Position);
  75. }
  76. MapRouteFinderResult finder = await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(geopoints);
  77. Debug.Write("Finder status: " + finder.Status);
  78. if (finder.Status == MapRouteFinderStatus.Success)
  79. {
  80. //Create route for mapPage
  81. routeView = new MapRouteView(finder.Route);
  82. routeView.RouteColor = Colors.Firebrick;
  83. routeView.OutlineColor = Colors.Black;
  84. //route duration
  85. int tijd = ((int) finder.Route.EstimatedDuration.TotalMinutes);
  86. RouteTijdText = $"Tijdsduur: {tijd} min";
  87. RouteBlok.Text = RouteTijdText;
  88. //Route distance
  89. LoopafstandText = $"Loopafstand: {(Convert.ToInt32(finder.Route.LengthInMeters/1000))} km";
  90. Loopblok.Text = LoopafstandText;
  91. //Waypoint text
  92. WaypointsBlok.Text = WaypointsText;
  93. ProgressRing.Visibility = Visibility.Collapsed;
  94. StartButton.Visibility = Visibility.Visible;
  95. }
  96. StartButton.Visibility = Visibility.Visible;
  97. }
  98. private void Waypoints_OnItemClick(object sender, ItemClickEventArgs e)
  99. {
  100. Waypoint wp = e.ClickedItem as Waypoint;
  101. wp.FromPreview = true;
  102. Tuple<Waypoint, Route> t = new Tuple<Waypoint, Route>(wp, route);
  103. MainPage.RootFrame.Navigate(typeof(WpDetailPage),t);
  104. }
  105. }
  106. }