RouteExample.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. InitializeComponent();
  40. NavigationCacheMode = NavigationCacheMode.Enabled;
  41. }
  42. protected override void OnNavigatedTo(NavigationEventArgs e)
  43. {
  44. if (route == null)
  45. {
  46. route = e.Parameter as Route;
  47. ShowRouteInfo();
  48. }
  49. //Setting the back button functionality
  50. SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
  51. SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested;
  52. }
  53. private void BackRequested(object sender, BackRequestedEventArgs e)
  54. {
  55. e.Handled = true;
  56. SystemNavigationManager.GetForCurrentView().BackRequested -= BackRequested;
  57. MainPage.RootFrame.Navigate(typeof(RouteSelectPage));
  58. }
  59. private void Button_Click(object sender, RoutedEventArgs e)
  60. {
  61. fromRouteExamp = true;
  62. MainPage.RootFrame.Navigate(typeof(MapPage), route);
  63. }
  64. private async void ShowRouteInfo()
  65. {
  66. //Setting the x amount of waypoints text
  67. WaypointsText = "Aantal waypoints: " + 0;
  68. if (route.Waypoints.Count != 0)
  69. {
  70. WaypointsText = "Aantal waypoints: " + route.Waypoints.Count;
  71. }
  72. //Setting the Route distance and time text
  73. List<Geopoint> geopoints = new List<Geopoint>();
  74. foreach (Waypoint wayPoint in route.Waypoints)
  75. {
  76. geopoints.Add(wayPoint.Position);
  77. }
  78. MapRouteFinderResult finder = await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(geopoints);
  79. if (finder.Status == MapRouteFinderStatus.Success)
  80. {
  81. //Create route for mapPage
  82. routeView = new MapRouteView(finder.Route);
  83. routeView.RouteColor = Colors.Firebrick;
  84. routeView.OutlineColor = Colors.Black;
  85. //route duration
  86. int tijd = ((int)finder.Route.EstimatedDuration.TotalMinutes);
  87. RouteTijdText = $"Tijdsduur: {tijd} min";
  88. RouteBlok.Text = RouteTijdText;
  89. //Route distance
  90. LoopafstandText = $"Loopafstand: {(finder.Route.LengthInMeters/1000)} km";
  91. Loopblok.Text = LoopafstandText;
  92. //Waypoint text
  93. WaypointsBlok.Text = WaypointsText;
  94. ProgressRing.Visibility = Visibility.Collapsed;
  95. StartButton.Visibility = Visibility.Visible;
  96. }
  97. }
  98. private void Waypoints_OnItemClick(object sender, ItemClickEventArgs e)
  99. {
  100. Waypoint wp = e.ClickedItem as Waypoint;
  101. wp.FromPreview = true;
  102. MainPage.RootFrame.Navigate(typeof(WpDetailPage),wp);
  103. }
  104. }
  105. }