RouteExample.xaml.cs 4.4 KB

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