Просмотр исходного кода

Added mapview and gps location marker

Jeroen 10 лет назад
Родитель
Сommit
421ee40b6d

BIN
Breda-Tour/Assets/Marker.png


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

@@ -105,6 +105,8 @@
     <Compile Include="CustomControls\DefaultTopBar.xaml.cs">
       <DependentUpon>DefaultTopBar.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Data_\Gps.cs" />
+    <Compile Include="Data_\WayPoint.cs" />
     <Compile Include="HelpScreen\HelpItem.cs" />
     <Compile Include="HelpScreen\HelpPage.xaml.cs">
       <DependentUpon>HelpPage.xaml</DependentUpon>
@@ -112,6 +114,9 @@
     <Compile Include="MainPage.xaml.cs">
       <DependentUpon>MainPage.xaml</DependentUpon>
     </Compile>
+    <Compile Include="MapScreen\MapPage.xaml.cs">
+      <DependentUpon>MapPage.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="RouteSelectScreen\RouteSelectPage.xaml.cs">
       <DependentUpon>RouteSelectPage.xaml</DependentUpon>
@@ -131,6 +136,7 @@
   </ItemGroup>
   <ItemGroup>
     <Content Include="Assets\Ags_Logo.png" />
+    <Content Include="Assets\Marker.png" />
     <Content Include="Properties\Default.rd.xml" />
     <Content Include="Assets\LockScreenLogo.scale-200.png" />
     <Content Include="Assets\SplashScreen.scale-200.png" />
@@ -161,6 +167,10 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="MapScreen\MapPage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="RouteSelectScreen\RouteSelectPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 1 - 1
Breda-Tour/CustomControls/DefaultPivotControl.xaml.cs

@@ -59,7 +59,7 @@ namespace Breda_Tour.CustomControls
 
         private void MapRadioButton_Checked(object sender, RoutedEventArgs e)
         {
-
+            MainPage.RootFrame.Navigate(typeof (MapScreen.MapPage));
         }
 
         private void SettingsRadioButton_Checked(object sender, RoutedEventArgs e)

+ 88 - 0
Breda-Tour/Data_/Gps.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using Windows.Devices.AllJoyn;
+using Windows.Devices.Geolocation;
+using Windows.System;
+using Windows.UI.Xaml;
+using Breda_Tour.MapScreen;
+
+namespace Breda_Tour.Data_
+{
+    public class Gps
+    {
+        private MapPage mapPage;
+        private Geolocator geolocator;
+        private Geoposition _position;
+        public Geoposition Position
+        {
+            get { return _position; }
+        }
+        private List<Geoposition> _history;
+        public List<Geoposition> History
+        {
+            get { return _history; }
+        }
+
+        private PositionStatus _status;
+        public PositionStatus Status
+        {
+            get { return _status; }
+        }
+
+        public Gps(MapPage mapPage)
+        {
+            _history = new List<Geoposition>();
+            this.mapPage = mapPage;
+        }
+
+        public async void Start()
+        {
+            var accessStatus = await Geolocator.RequestAccessAsync();
+
+            switch (accessStatus)
+            {
+                case GeolocationAccessStatus.Allowed:
+                    Geolocator geolocator = new Geolocator { DesiredAccuracyInMeters = 1, MovementThreshold = 2 };
+                    // Subscribe events
+                    geolocator.StatusChanged += OnStatusChanged;
+                    geolocator.PositionChanged += OnPositionChanged;
+                    // Get position
+                    _position = await geolocator.GetGeopositionAsync();
+                    break;
+                case GeolocationAccessStatus.Denied:
+                    _status = PositionStatus.NotAvailable;
+                    bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
+                    break;
+                case GeolocationAccessStatus.Unspecified:
+                    _status = PositionStatus.NotAvailable;
+                    break;
+            }
+        }
+
+        private void OnPositionChanged(Geolocator sender, PositionChangedEventArgs args)
+        {
+            mapPage.ShowLocaton(args.Position.Coordinate.Point);
+            _position = args.Position;
+        }
+
+        private void OnStatusChanged(Geolocator sender, StatusChangedEventArgs args)
+        {
+            if (args.Status == PositionStatus.Disabled)
+            {
+                _position = null;
+            }
+        }
+
+        public async void Refresh()
+        {
+            if (geolocator == null)
+            {
+                Start();
+            }
+            else
+            {
+                _position = await geolocator.GetGeopositionAsync();
+            }
+        }
+    }
+}

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

@@ -0,0 +1,27 @@
+using Windows.Devices.Geolocation;
+
+namespace Breda_Tour.Data_
+{
+    public class WayPoint
+    {
+        private Geopoint position;
+        private string title;
+        public string description { get; set; }
+        public int number;
+
+        public WayPoint(Geopoint position, string title, int number)
+        {
+            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 });
+            this.title = title;
+            this.number = number;
+        }
+
+    }
+}

+ 2 - 1
Breda-Tour/MainPage.xaml.cs

@@ -13,6 +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.RouteSelectScreen;
 
 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
 
@@ -29,7 +30,7 @@ namespace Breda_Tour
         {
             this.InitializeComponent();
             f = this.rootFrame;
-            f.Navigate(typeof(SettingsPage));
+            f.Navigate(typeof(RouteSelectPage));
         }
 
         public static Frame RootFrame {

+ 32 - 0
Breda-Tour/MapScreen/MapPage.xaml

@@ -0,0 +1,32 @@
+<Page
+    x:Class="Breda_Tour.MapScreen.MapPage"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:local="using:Breda_Tour.MapScreen"
+    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:Maps ="using:Windows.UI.Xaml.Controls.Maps"
+    xmlns:customControls="using:Breda_Tour.CustomControls"
+    mc:Ignorable="d">
+
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="Auto" />
+            <RowDefinition Height="Auto" />
+            <RowDefinition Height="*" />
+        </Grid.RowDefinitions>
+
+        <c:DefaultTopBar Header="Kaart" Grid.Row="0"/>
+        <c:DefaultPivotControl x:Name="DefaultPivot" Grid.Row="1"/>
+
+        <Maps:MapControl
+       x:Name="Map"
+        Grid.Row="3"
+       ZoomInteractionMode="GestureAndControl"
+       TiltInteractionMode="GestureAndControl"
+       RotateInteractionMode="GestureAndControl"
+       MapServiceToken="P4P2fAwXuk7ndsVIsaaV~uYjur55RgwmLsiwFwd72bQ~ApDRixf1L-0o_kMY8EtBBDm8xe7G2oz1k2-u0HQIATvSp-iiKr5KLNkYc1HF5D5e"/>
+   
+    </Grid>
+</Page>

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

@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices.WindowsRuntime;
+using Windows.Foundation;
+using Windows.Foundation.Collections;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Controls.Primitives;
+using Windows.UI.Xaml.Data;
+using Windows.UI.Xaml.Input;
+using Windows.UI.Xaml.Media;
+using Windows.UI.Xaml.Navigation;
+using Windows.Devices.Geolocation;
+using Windows.Storage.Streams;
+using Windows.UI;
+using Windows.UI.Core;
+using Windows.UI.Xaml.Automation;
+using Windows.UI.Xaml.Controls.Maps;
+using Windows.UI.Xaml.Shapes;
+using Breda_Tour.Data_;
+
+// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
+
+namespace Breda_Tour.MapScreen
+{
+    /// <summary>
+    /// An empty page that can be used on its own or navigated to within a Frame.
+    /// </summary>
+    public sealed partial class MapPage : Page
+    {
+        private MapIcon marker;
+        private Geopoint point;
+        private Gps gps;
+
+        public MapPage()
+        {
+            marker = new MapIcon();
+            marker.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Marker.png"));
+            marker.NormalizedAnchorPoint = new Point(0.5, 0.5);
+            gps = new Gps(this);
+            gps.Start();
+            this.InitializeComponent();
+        }
+
+        protected override void OnNavigatedTo(NavigationEventArgs e)
+        {
+            
+        }
+
+        public async void ShowLocaton(Geopoint point)
+        {
+            this.point = point;
+            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
+           {
+               Map.Center = point;
+               if (!Map.MapElements.Contains(marker))
+               {
+                   Map.MapElements.Add(marker);
+               }
+               marker.Location = point;
+           });
+            await Map.TrySetViewAsync(point, 15);
+        }
+    }
+}

+ 12 - 29
Breda-Tour/Package.appxmanifest

@@ -1,49 +1,32 @@
 <?xml version="1.0" encoding="utf-8"?>
-
-<Package
-  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
-  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
-  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
-  IgnorableNamespaces="uap mp">
-
-  <Identity
-    Name="322906c3-d44f-4dc7-9bb2-1f0e00fb09e8"
-    Publisher="CN=Paul de Mast"
-    Version="1.0.0.0" />
-
-  <mp:PhoneIdentity PhoneProductId="322906c3-d44f-4dc7-9bb2-1f0e00fb09e8" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
-
+<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
+  <Identity Name="322906c3-d44f-4dc7-9bb2-1f0e00fb09e8" Publisher="CN=Paul de Mast" Version="1.0.0.0" />
+  <mp:PhoneIdentity PhoneProductId="322906c3-d44f-4dc7-9bb2-1f0e00fb09e8" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
   <Properties>
     <DisplayName>Breda-Tour</DisplayName>
     <PublisherDisplayName>Paul de Mast</PublisherDisplayName>
     <Logo>Assets\StoreLogo.png</Logo>
   </Properties>
-
   <Dependencies>
     <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
   </Dependencies>
-
   <Resources>
-    <Resource Language="x-generate"/>
+    <Resource Language="x-generate" />
   </Resources>
-
   <Applications>
-    <Application Id="App"
-      Executable="$targetnametoken$.exe"
-      EntryPoint="Breda_Tour.App">
-      <uap:VisualElements
-        DisplayName="Breda-Tour"
-        Square150x150Logo="Assets\Square150x150Logo.png"
-        Square44x44Logo="Assets\Square44x44Logo.png"
-        Description="Breda-Tour"
-        BackgroundColor="transparent">
-        <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
+    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="Breda_Tour.App">
+      <uap:VisualElements DisplayName="Breda-Tour" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="Breda-Tour" BackgroundColor="transparent">
+        <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png">
+        </uap:DefaultTile>
         <uap:SplashScreen Image="Assets\SplashScreen.png" />
+        <uap:InitialRotationPreference>
+          <uap:Rotation Preference="portrait" />
+        </uap:InitialRotationPreference>
       </uap:VisualElements>
     </Application>
   </Applications>
-
   <Capabilities>
     <Capability Name="internetClient" />
+    <DeviceCapability Name="location" />
   </Capabilities>
 </Package>