Browse Source

Completed json integration with map code

Jeroen 10 năm trước cách đây
mục cha
commit
5e96edd172

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

@@ -102,6 +102,7 @@
     <Compile Include="App.xaml.cs">
       <DependentUpon>App.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Data\Picture.cs" />
     <Compile Include="Data\Route.cs" />
     <Compile Include="Data\RouteDatabase.cs" />
     <Compile Include="Data\Waypoint.cs" />
@@ -111,11 +112,7 @@
     <Compile Include="CustomControls\DefaultTopBar.xaml.cs">
       <DependentUpon>DefaultTopBar.xaml</DependentUpon>
     </Compile>
-    <Compile Include="Data_\Gps.cs" />
-    <Compile Include="Data_\Image.cs" />
-    <Compile Include="Data_\Route.cs" />
-    <Compile Include="Data_\RouteDatabase.cs" />
-    <Compile Include="Data_\WayPoint.cs" />
+    <Compile Include="Data\Gps.cs" />
     <Compile Include="HelpScreen\HelpItem.cs" />
     <Compile Include="HelpScreen\HelpPage.xaml.cs">
       <DependentUpon>HelpPage.xaml</DependentUpon>

+ 1 - 1
Breda-Tour/Data_/Gps.cs → Breda-Tour/Data/Gps.cs

@@ -6,7 +6,7 @@ using Windows.System;
 using Windows.UI.Xaml;
 using Breda_Tour.MapScreen;
 
-namespace Breda_Tour.Data_
+namespace Breda_Tour.Data
 {
     public class Gps
     {

+ 3 - 3
Breda-Tour/Data_/Image.cs → Breda-Tour/Data/Picture.cs

@@ -1,8 +1,8 @@
 using Windows.UI.ViewManagement;
 
-namespace Breda_Tour.Data_
+namespace Breda_Tour.Data
 {
-    public class Image
+    public class Picture
     {
         private string _source;
 
@@ -16,7 +16,7 @@ namespace Breda_Tour.Data_
             get { return ApplicationView.GetForCurrentView().VisibleBounds.Width; }
         }
 
-        public Image(string source)
+        public Picture(string source)
         {
             _source = source;
         }

+ 17 - 4
Breda-Tour/Data/Route.cs

@@ -3,15 +3,28 @@ using System.Collections.Generic;
 
 namespace Breda_Tour.Data
 {
-    class Route
+    public class Route
     {
-        public String Title {  get; private set; }
-        public List<Waypoint> Waypoints { get; private set; }
+        public String Title { get; private set; }
+        private List<Waypoint> _waypoints;
+        public List<Waypoint> Waypoints
+        {
+            get { return _waypoints; }
+        }
 
         public Route(String Title, List<Waypoint> Waypoints)
         {
             this.Title = Title;
-            this.Waypoints = Waypoints;
+            this._waypoints = Waypoints;
         }
+
+        //public void CreateTestWaypoints()
+        //{
+        //    _waypoints.Add(new Waypoint(51.530805, 4.498676, "Test1", 1, new Image("ms-appx:///Assets/1.jpg"))); { description = "4. Als u de brug overgaat, ziet u aan uw linkerhand het Nassau-Baroniemonument. Bij de ingang van het stadspark, het Valkenberg, staat een monument dat u iets vertelt over de wordings- geschiedenis van de stad Breda, maar vooral over de Heren van de stad uit het Huis van Nassau en de 500-jarige band tussen Breda en het Huis van Nassau. Op 3 juli 1905 werd het Nassau-Baronie- monument, zoals het officieel heet, met  veel feestelijk vertoon door Koningin Wilhelmina onthuld. Het beeld herinnert aan het feit, dat in 1404 Graaf Engelbert, de eerste Bredase Nassau en zijn gemalin, Johanna van Polanen, werden ingehuldigd als Heer en Vrouwe van Breda. De ontwerper is de welbekende dr. P.J.H. Cuypers, die o.m. het Rijksmuseum en het Centraal Station in Amsterdam ontwierp. Op dit monument zijn niet alleen de wapenschilden van twintig gemeenten in en rond de Baronie aangebracht maar ook de Leeuw van Nassau die boven alles uittorent met koningskroon, zwaard en wapenschild. In de drie reliëfs is de 'blijde incomste' van Graaf Engelbert en zijn gemalin afgebeeld. De poortersbieden de sleutel van de stad aan." });
+        //    _waypoints.Add(new Waypoint(51.533461, 4.492711, "Test2", 2, null));
+        //    _waypoints.Add(new Waypoint(51.536998, 4.477862, "Test3", 3, null));
+        //    _waypoints.Add(new Waypoint(51.531285, 4.475394, "Test4", 4, null));
+        //    _waypoints.Add(new Waypoint(51.531566, 4.466747, "Test5", 5, null));
+        //}
     }
 }

+ 1 - 1
Breda-Tour/Data/RouteDatabase.cs

@@ -9,7 +9,7 @@ namespace Breda_Tour.Data
 {
     class RouteDatabase
     {
-        private List<Route> Routes;
+        public List<Route> Routes;
         
         public RouteDatabase()
         {

+ 14 - 18
Breda-Tour/Data/waypoint.cs

@@ -7,32 +7,28 @@ using Windows.Devices.Geolocation;
 
 namespace Breda_Tour.Data
 {
-    class Waypoint
+    public class Waypoint
     {
-        public Geopoint Position { get; private set; }
+        private Geopoint _position;
+        public Geopoint Position
+        {
+            get { return _position; }
+        }
+
         public String Title { get; private set; }
         public String Description { get; private set; }
-        public List<Image> Photos { get; private set; }
+        public List<Picture> Pictures { get; private set; }
 
-        public Waypoint(float Lat, float Long, String Title, String Description, List<string> pictures)
+        public Waypoint(double Lat, double Long, String Title, String Description, List<string> pictures)
         {
-            this.Position = new Geopoint(new BasicGeoposition() { Altitude = 0, Latitude = Lat, Longitude = Long });
+            this._position = new Geopoint(new BasicGeoposition() { Altitude = 0, Latitude = Lat, Longitude = Long });
             this.Title = Title;
             this.Description = Description;
-            this.Photos = new List<Image>();
-            if (pictures != null)
+            this.Pictures = new List<Picture>();
+            foreach (var imageSource in pictures)
             {
-                Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
-                {
-                    foreach (string source in pictures)
-                    {
-                        Photos.Add(new Image
-                        {
-                            Source = new BitmapImage(new Uri("file://Storages/images/" + source)),
-                            Name = source
-                        });
-                    }
-                });
+                string newSource = "ms-appx:///Assets/" + imageSource;
+                Pictures.Add(new Picture(newSource));
             }
         }
     }

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

@@ -1,47 +0,0 @@
-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, new Image("ms-appx:///Assets/1.jpg")) {description = "4. Als u de brug overgaat, ziet u aan uw linkerhand het Nassau-Baroniemonument. Bij de ingang van het stadspark, het Valkenberg, staat een monument dat u iets vertelt over de wordings- geschiedenis van de stad Breda, maar vooral over de Heren van de stad uit het Huis van Nassau en de 500-jarige band tussen Breda en het Huis van Nassau. Op 3 juli 1905 werd het Nassau-Baronie- monument, zoals het officieel heet, met  veel feestelijk vertoon door Koningin Wilhelmina onthuld. Het beeld herinnert aan het feit, dat in 1404 Graaf Engelbert, de eerste Bredase Nassau en zijn gemalin, Johanna van Polanen, werden ingehuldigd als Heer en Vrouwe van Breda. De ontwerper is de welbekende dr. P.J.H. Cuypers, die o.m. het Rijksmuseum en het Centraal Station in Amsterdam ontwierp. Op dit monument zijn niet alleen de wapenschilden van twintig gemeenten in en rond de Baronie aangebracht maar ook de Leeuw van Nassau die boven alles uittorent met koningskroon, zwaard en wapenschild. In de drie reliëfs is de 'blijde incomste' van Graaf Engelbert en zijn gemalin afgebeeld. De poortersbieden de sleutel van de stad aan."});
-            _wayPoints.Add(new WayPoint(51.533461, 4.492711, "Test2", 2, null));
-            _wayPoints.Add(new WayPoint(51.536998, 4.477862, "Test3", 3, null));
-            _wayPoints.Add(new WayPoint(51.531285, 4.475394, "Test4", 4, null));
-            _wayPoints.Add(new WayPoint(51.531566, 4.466747, "Test5", 5, null));
-        }
-    }
-}

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

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

+ 0 - 41
Breda-Tour/Data_/WayPoint.cs

@@ -1,41 +0,0 @@
-using Windows.Devices.Geolocation;
-using Windows.UI.Xaml.Controls;
-
-namespace Breda_Tour.Data_
-{
-    public class WayPoint
-    {
-        private Geopoint _position;
-        public Geopoint Position
-        {
-            get { return _position; }
-        }
-
-        private string title;
-        public string description { get; set; }
-        public int number;
-        private Image image;
-
-        public Image Image
-        {
-            get { return image; }
-        }
-
-        public WayPoint(Geopoint position, string title, int number, Image image)
-        {
-            this._position = position;
-            this.title = title;
-            this.number = number;
-            this.image = image;
-        }
-
-        public WayPoint(double latitude, double longitude, string title, int number, Image image)
-        {
-            _position = new Geopoint(new BasicGeoposition() { Altitude = 0, Latitude = latitude, Longitude = longitude });
-            this.title = title;
-            this.number = number;
-            this.image = image;
-        }
-
-    }
-}

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

@@ -22,8 +22,8 @@ using Windows.UI.Xaml.Automation;
 using Windows.UI.Xaml.Controls.Maps;
 using Windows.UI.Xaml.Shapes;
 using Breda_Tour.CustomControls;
-using Breda_Tour.Data_;
 using System.Diagnostics;
+using Breda_Tour.Data;
 
 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
 
@@ -47,15 +47,16 @@ 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();
+            RouteDatabase routeDB = new RouteDatabase();
+            Debug.Write(routeDB.Routes.Count);
+            //route = routeDB.Routes.ElementAt(1);
             this.InitializeComponent();
             Debug.Write("New Map generated");
         }
 
         protected override void OnNavigatedTo(NavigationEventArgs e)
         {
-           SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
+            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
             DefaultPivot.SetCheckedButton(DefaultPivotControl.Tab.Map);
         }
 
@@ -83,18 +84,18 @@ namespace Breda_Tour.MapScreen
             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);
-            }
+                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);
+                }
             });
         }
 
@@ -102,27 +103,43 @@ namespace Breda_Tour.MapScreen
         {
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
-                foreach (var waypoint in route.WayPoints)
+                for (int x = 0; x < route.Waypoints.Count; x++)
                 {
-                    MapIcon wp = new MapIcon() {Location = waypoint.Position, Title = waypoint.number.ToString()};
+                    Waypoint wayp = route.Waypoints.ElementAt(x);
+                    MapIcon wp = new MapIcon { Location = wayp.Position, Title = x + 1.ToString() };
                     Map.MapElements.Add(wp);
                 }
+                //foreach (var waypoint in route.WayPoints)
+                //{
+                //    MapIcon wp = new MapIcon() {Location = waypoint.Position, Title = waypoint.number.ToString()};
+                //    Map.MapElements.Add(wp);
+                //}
             });
         }
 
         private void Map_OnMapElementClick(MapControl sender, MapElementClickEventArgs args)
         {
             MapIcon Icon = args.MapElements.FirstOrDefault(x => x is MapIcon) as MapIcon;
-            foreach (var waypoint in route.WayPoints)
+            for (int x = 0; x < route.Waypoints.Count; x++)
             {
                 if (Icon.Title != "")
                 {
-                    if (waypoint.number == int.Parse(Icon.Title))
+                    if (x + 1 == int.Parse(Icon.Title))
                     {
-                        MainPage.RootFrame.Navigate(typeof(WpDetailPage), waypoint);
+                        MainPage.RootFrame.Navigate(typeof (WpDetailPage), route.Waypoints.ElementAt(x));
                     }
                 }
             }
+            //foreach (var waypoint in route.WayPoints)
+            //{
+            //    if (Icon.Title != "")
+            //    {
+            //        if (waypoint.number == int.Parse(Icon.Title))
+            //        {
+            //            MainPage.RootFrame.Navigate(typeof(WpDetailPage), waypoint);
+            //        }
+            //    }
+            //}
         }
     }
 }

+ 17 - 5
Breda-Tour/MapScreen/WpDetailPage.xaml

@@ -6,6 +6,7 @@
     xmlns:c ="using:Breda_Tour.CustomControls"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    xmlns:data="using:Breda_Tour.Data"
     mc:Ignorable="d">
 
     <Grid>
@@ -16,16 +17,27 @@
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
 
-        <c:DefaultTopBar x:Name="NameBar" Grid.Row="0" Header="Bezienswaardigheid"/>
-        <RelativePanel x:Name="ImagePanel" Grid.Row="1">
-            <Image Source="{x:Bind wp.Image.Source}" Height="{x:Bind wp.Image.Width}" Width="{x:Bind wp.Image.Width}" Stretch="UniformToFill" />
-        </RelativePanel>
+        <c:DefaultTopBar x:Name="NameBar" Grid.Row="0" Header="{x:Bind wp.Title}"/>
+        <ListView Grid.Row="1" ItemsSource="{x:Bind wp.Pictures}">
+            <ListView.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <StackPanel Orientation="Horizontal"/>
+                </ItemsPanelTemplate>
+            </ListView.ItemsPanel>
+            <ListView.ItemTemplate >
+                <DataTemplate x:DataType="data:Picture">
+                    <ListViewItem>
+                        <Image Source="{x:Bind Source}" Height="{x:Bind Width}" Width="{x:Bind Width}" Stretch="UniformToFill" />
+                    </ListViewItem>
+                </DataTemplate>
+            </ListView.ItemTemplate>
+        </ListView>
         <RelativePanel Grid.Row="2">
             <TextBlock Text="Beschrijving" FontSize="20" Margin="15,15,0,15" />
         </RelativePanel>
         <RelativePanel Grid.Row="3">
            <ScrollViewer Margin="15,0,0,0" VerticalScrollBarVisibility="Auto" >
-                <TextBlock HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" TextWrapping="Wrap" Text="{x:Bind wp.description }"/>
+                <TextBlock HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" TextWrapping="Wrap" Text="{x:Bind wp.Description}"/>
            </ScrollViewer>
         </RelativePanel>
     </Grid>

+ 3 - 3
Breda-Tour/MapScreen/WpDetailPage.xaml.cs

@@ -13,7 +13,7 @@ using Windows.UI.Xaml.Data;
 using Windows.UI.Xaml.Input;
 using Windows.UI.Xaml.Media;
 using Windows.UI.Xaml.Navigation;
-using Breda_Tour.Data_;
+using Breda_Tour.Data;
 
 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
 
@@ -24,7 +24,7 @@ namespace Breda_Tour.MapScreen
     /// </summary>
     public sealed partial class WpDetailPage : Page
     {
-        private WayPoint wp;
+        private Waypoint wp;
 
         public WpDetailPage()
         {
@@ -33,7 +33,7 @@ namespace Breda_Tour.MapScreen
 
         protected override void OnNavigatedTo(NavigationEventArgs e)
         {
-            wp = e.Parameter as WayPoint;
+            wp = e.Parameter as Waypoint;
             this.DataContext = wp;
 
             SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;

+ 1 - 1
Breda-Tour/project.lock.json

@@ -11523,7 +11523,7 @@
       ]
     },
     "Microsoft.ApplicationInsights.WindowsApps/1.0.0": {
-      "sha512": "NvBQnFeiFd0O1QdBz06UGApD7zn7ztVi7qO18IsM3EjiXRNgfrEBXB+azNm8XqLY8xGFAqh3HAuSd/wHZMe0XA==",
+      "sha512": "fNCAjIwvbTV+G0dT14bgM5tptsqeSaKQaCrlq7QknOq1Xdm8ZmgsDYddMgXkvykyKLjWyU6fKuOpj6fsQJy+wQ==",
       "type": "Package",
       "files": [
         "[Content_Types].xml",