Browse Source

Added walk history line
Added map clear when route is started
Changed km double to int

Jeroen 10 years ago
parent
commit
2c9c419e96

+ 14 - 7
Breda-Tour/Data/Gps.cs

@@ -17,11 +17,9 @@ namespace Breda_Tour.Data
         {
             get { return _position; }
         }
-        private List<Geoposition> _history;
-        public List<Geoposition> History
-        {
-            get { return _history; }
-        }
+
+        public List<BasicGeoposition> History { get; set; }
+
 
         private PositionStatus _status;
         public PositionStatus Status
@@ -31,7 +29,7 @@ namespace Breda_Tour.Data
 
         public Gps(MapPage mapPage)
         {
-            _history = new List<Geoposition>();
+            History = new List<BasicGeoposition>();
             this.mapPage = mapPage;
         }
 
@@ -51,7 +49,9 @@ namespace Breda_Tour.Data
                     break;
                 case GeolocationAccessStatus.Denied:
                     _status = PositionStatus.NotAvailable;
+                    geolocator = null;
                     bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
+                    Refresh();
                     break;
                 case GeolocationAccessStatus.Unspecified:
                     _status = PositionStatus.NotAvailable;
@@ -61,8 +61,15 @@ namespace Breda_Tour.Data
 
         private void OnPositionChanged(Geolocator sender, PositionChangedEventArgs args)
         {
-            mapPage.ShowLocaton(args.Position.Coordinate.Point);
             _position = args.Position;
+            mapPage.ShowLocaton(_position.Coordinate.Point);
+            //For route history line
+            BasicGeoposition BasicG = _position.Coordinate.Point.Position;
+            History.Add(BasicG);
+            if (History.Count >= 2)
+            {
+                mapPage.DrawWalkingPath(History);
+            }
         }
 
         private void OnStatusChanged(Geolocator sender, StatusChangedEventArgs args)

+ 16 - 0
Breda-Tour/MapScreen/MapPage.xaml.cs

@@ -23,6 +23,7 @@ using Windows.UI.Xaml.Controls.Maps;
 using Windows.UI.Xaml.Shapes;
 using Breda_Tour.CustomControls;
 using System.Diagnostics;
+using Windows.UI.Xaml.Automation.Peers;
 using Breda_Tour.Data;
 using Breda_Tour.RouteSelectScreen;
 
@@ -59,6 +60,9 @@ namespace Breda_Tour.MapScreen
             {
                 RouteExample.fromRouteExamp = false;
                 route = e.Parameter as Route;
+                Map.MapElements.Clear();
+                gps.History.Clear();
+                ShowLocaton(gps.Position.Coordinate.Point);
                 ShowWaypoints(route);
                 ShowRoute();
             }
@@ -145,5 +149,17 @@ namespace Breda_Tour.MapScreen
             //    }
             //}
         }
+
+        public async void DrawWalkingPath(List<BasicGeoposition> positions)
+        {
+            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
+            {
+                MapPolyline mapPolyline = new MapPolyline();
+                mapPolyline.StrokeColor = Colors.Blue;
+                mapPolyline.StrokeThickness = 3;
+                mapPolyline.Path = new Geopath(positions);
+                Map.MapElements.Add(mapPolyline);
+            });
+        }
     }
 }

+ 9 - 2
Breda-Tour/RouteSelectScreen/RouteExample.xaml.cs

@@ -39,6 +39,8 @@ namespace Breda_Tour.RouteSelectScreen
 
         public RouteExample()
         {
+            MapService.ServiceToken =
+                "P4P2fAwXuk7ndsVIsaaV~uYjur55RgwmLsiwFwd72bQ~ApDRixf1L-0o_kMY8EtBBDm8xe7G2oz1k2-u0HQIATvSp-iiKr5KLNkYc1HF5D5e";
             InitializeComponent();
             NavigationCacheMode = NavigationCacheMode.Enabled;
         }
@@ -84,6 +86,7 @@ namespace Breda_Tour.RouteSelectScreen
                 geopoints.Add(wayPoint.Position);
             }
             MapRouteFinderResult finder = await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(geopoints);
+            Debug.Write("Finder status: " + finder.Status);
             if (finder.Status == MapRouteFinderStatus.Success)
             {
                 //Create route for mapPage
@@ -91,17 +94,21 @@ namespace Breda_Tour.RouteSelectScreen
                 routeView.RouteColor = Colors.Firebrick;
                 routeView.OutlineColor = Colors.Black;
                 //route duration
-                int tijd = ((int)finder.Route.EstimatedDuration.TotalMinutes);
+                int tijd = ((int) finder.Route.EstimatedDuration.TotalMinutes);
                 RouteTijdText = $"Tijdsduur: {tijd} min";
                 RouteBlok.Text = RouteTijdText;
                 //Route distance
-                LoopafstandText = $"Loopafstand: {(finder.Route.LengthInMeters/1000)} km";
+                LoopafstandText = $"Loopafstand: {(Convert.ToInt32(finder.Route.LengthInMeters/1000))} km";
                 Loopblok.Text = LoopafstandText;
                 //Waypoint text
                 WaypointsBlok.Text = WaypointsText;
                 ProgressRing.Visibility = Visibility.Collapsed;
                 StartButton.Visibility = Visibility.Visible;
             }
+            else
+            {
+                ShowRouteInfo();
+            }
         }
 
         private void Waypoints_OnItemClick(object sender, ItemClickEventArgs e)