Jelajahi Sumber

Added route & waypoint draw

Jeroen 10 tahun lalu
induk
melakukan
fdfc8267fd

+ 2 - 0
Breda-Tour/Breda-Tour.csproj

@@ -106,6 +106,8 @@
       <DependentUpon>DefaultTopBar.xaml</DependentUpon>
     </Compile>
     <Compile Include="Data_\Gps.cs" />
+    <Compile Include="Data_\Route.cs" />
+    <Compile Include="Data_\RouteDatabase.cs" />
     <Compile Include="Data_\WayPoint.cs" />
     <Compile Include="HelpScreen\HelpItem.cs" />
     <Compile Include="HelpScreen\HelpPage.xaml.cs">

+ 47 - 0
Breda-Tour/Data_/Route.cs

@@ -0,0 +1,47 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Breda_Tour.Data_
+{
+    public class Route
+    {
+        private string _name;
+        private string description;
+        private List<WayPoint> _wayPoints;
+        public List<WayPoint> WayPoints
+        {
+            get { return _wayPoints; }
+        }
+
+        public Route(string name, string description)
+        {
+            _name = name;
+            this.description = description;
+            _wayPoints = new List<WayPoint>();
+        }
+
+        public void Add(WayPoint waypoint)
+        {
+            _wayPoints.Add(waypoint);
+        }
+
+        public WayPoint Get(int index)
+        {
+            return _wayPoints.ElementAt(index);
+        }
+
+        public void Remove(WayPoint waypoint)
+        {
+            _wayPoints.Remove(waypoint);
+        }
+
+        public void CreateTestWaypoints()
+        {
+            _wayPoints.Add(new WayPoint(51.530805, 4.498676, "Test1", 1));
+            _wayPoints.Add(new WayPoint(51.533461, 4.492711, "Test2", 2));
+            _wayPoints.Add(new WayPoint(51.536998, 4.477862, "Test3", 3));
+            _wayPoints.Add(new WayPoint(51.531285, 4.475394, "Test4", 4));
+            _wayPoints.Add(new WayPoint(51.531566, 4.466747, "Test5", 5));
+        }
+    }
+}

+ 16 - 0
Breda-Tour/Data_/RouteDatabase.cs

@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+using Windows.Services.Maps;
+using Windows.UI.Xaml.Controls;
+
+namespace Breda_Tour.Data_
+{
+    public class RouteDatabase
+    {
+        public RouteDatabase()
+        {
+            
+        }
+
+       
+    }
+}

+ 8 - 3
Breda-Tour/Data_/WayPoint.cs

@@ -4,21 +4,26 @@ namespace Breda_Tour.Data_
 {
     public class WayPoint
     {
-        private Geopoint position;
+        private Geopoint _position;
+        public Geopoint Position
+        {
+            get { return _position; }
+        }
+
         private string title;
         public string description { get; set; }
         public int number;
 
         public WayPoint(Geopoint position, string title, int number)
         {
-            this.position = position;
+            this._position = position;
             this.title = title;
             this.number = number;
         }
 
         public WayPoint(double latitude, double longitude, string title, int number)
         {
-            position = new Geopoint(new BasicGeoposition() { Altitude = 0, Latitude = latitude, Longitude = longitude });
+            _position = new Geopoint(new BasicGeoposition() { Altitude = 0, Latitude = latitude, Longitude = longitude });
             this.title = title;
             this.number = number;
         }

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

@@ -14,6 +14,7 @@ using Windows.UI.Xaml.Input;
 using Windows.UI.Xaml.Media;
 using Windows.UI.Xaml.Navigation;
 using Windows.Devices.Geolocation;
+using Windows.Services.Maps;
 using Windows.Storage.Streams;
 using Windows.UI;
 using Windows.UI.Core;
@@ -34,6 +35,7 @@ namespace Breda_Tour.MapScreen
         private MapIcon marker;
         private Geopoint point;
         private Gps gps;
+        private Route route;
 
         public MapPage()
         {
@@ -42,6 +44,8 @@ namespace Breda_Tour.MapScreen
             marker.NormalizedAnchorPoint = new Point(0.5, 0.5);
             gps = new Gps(this);
             gps.Start();
+            route = new Route("TestRoute","Test Description");
+            route.CreateTestWaypoints();
             this.InitializeComponent();
         }
 
@@ -63,6 +67,40 @@ namespace Breda_Tour.MapScreen
                marker.Location = point;
            });
             await Map.TrySetViewAsync(point, 15);
+            ShowWaypoints(route);
+            ShowRoute(route);
+        }
+
+        public async void ShowRoute(Route route)
+        {
+            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
+            {
+                List<Geopoint> geopoints = new List<Geopoint>();
+            foreach(WayPoint wayPoint in route.WayPoints)
+            {
+                geopoints.Add(wayPoint.Position);
+            }
+            MapRouteFinderResult finder = await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(geopoints);
+            if (finder.Status == MapRouteFinderStatus.Success)
+            {
+                MapRouteView routeView = new MapRouteView(finder.Route);
+                routeView.RouteColor = Colors.Firebrick;
+                routeView.OutlineColor = Colors.Black;
+                Map.Routes.Add(routeView);
+            }
+            });
+        }
+
+        public async void ShowWaypoints(Route route)
+        {
+            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
+            {
+                foreach (var waypoint in route.WayPoints)
+                {
+                    MapIcon wp = new MapIcon() {Location = waypoint.Position};
+                    Map.MapElements.Add(wp);
+                }
+            });
         }
     }
 }