Bugfixes and start to route navigation
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Data;
|
||||
|
||||
namespace NavCityBreda.Helpers
|
||||
{
|
||||
class BoolToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if ((bool)value)
|
||||
return Visibility.Visible;
|
||||
else
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (((Visibility)value) == Visibility.Visible)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ namespace NavCityBreda
|
||||
{
|
||||
while (App.RouteManager.LoadingElement != "Done")
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(500));
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(150));
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
splashProgressText.Text = App.RouteManager.LoadingElement;
|
||||
@@ -97,7 +97,7 @@ namespace NavCityBreda
|
||||
|
||||
while (App.Geo.Connected == null)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(250));
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(150));
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
splashProgressText.Text = "Waiting on GPS...";
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Geolocation;
|
||||
|
||||
namespace NavCityBreda.Model
|
||||
{
|
||||
@@ -18,11 +19,31 @@ namespace NavCityBreda.Model
|
||||
|
||||
public string LoadingElement;
|
||||
|
||||
public enum State { STOPPED, STARTED }
|
||||
public State RouteState;
|
||||
|
||||
private List<Geoposition> _history;
|
||||
public List<Geoposition> History
|
||||
{
|
||||
get
|
||||
{
|
||||
return _history;
|
||||
}
|
||||
}
|
||||
|
||||
public RouteManager()
|
||||
{
|
||||
_routes = new List<Route>();
|
||||
LoadingElement = "Initializing...";
|
||||
RouteState = State.STOPPED;
|
||||
LoadRoutes();
|
||||
App.Geo.PositionChanged += Geo_PositionChanged;
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
{
|
||||
if (RouteState == State.STARTED)
|
||||
_history.Add(args.Position);
|
||||
}
|
||||
|
||||
private async void LoadRoutes()
|
||||
@@ -37,20 +58,26 @@ namespace NavCityBreda.Model
|
||||
LoadingElement = "Loading " + r.Name + "...";
|
||||
await r.CalculateRoute();
|
||||
_routes.Add(r);
|
||||
await Task.Delay(TimeSpan.FromMilliseconds(250));
|
||||
}
|
||||
|
||||
LoadingElement = "Done";
|
||||
}
|
||||
|
||||
public void SetCurrentRoute(int index)
|
||||
{
|
||||
_currentroute = _routes.ElementAt(index);
|
||||
}
|
||||
|
||||
public void SetCurrentRoute(Route r)
|
||||
public void StartRoute(Route r)
|
||||
{
|
||||
_currentroute = r;
|
||||
RouteState = State.STARTED;
|
||||
}
|
||||
|
||||
public void StopRoute()
|
||||
{
|
||||
if (RouteState == State.STARTED)
|
||||
{
|
||||
_currentroute = null;
|
||||
RouteState = State.STOPPED;
|
||||
}
|
||||
|
||||
_history.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
<Compile Include="Helpers\Extensions.cs" />
|
||||
<Compile Include="Helpers\JSONParser.cs" />
|
||||
<Compile Include="Helpers\Settings.cs" />
|
||||
<Compile Include="Helpers\BoolToVisibilityConverter.cs" />
|
||||
<Compile Include="Helpers\Util.cs" />
|
||||
<Compile Include="InitPage.xaml.cs">
|
||||
<DependentUpon>InitPage.xaml</DependentUpon>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<mp:PhoneIdentity PhoneProductId="4786ea01-1db5-4c7a-a158-af0ee49306fa" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
|
||||
<Properties>
|
||||
<DisplayName>NavCityBreda</DisplayName>
|
||||
<PublisherDisplayName>kenny</PublisherDisplayName>
|
||||
<PublisherDisplayName>Nav City Breda A4</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
<Dependencies>
|
||||
@@ -15,10 +15,13 @@
|
||||
</Resources>
|
||||
<Applications>
|
||||
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="NavCityBreda.App">
|
||||
<uap:VisualElements DisplayName="NavCityBreda" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="NavCityBreda" BackgroundColor="transparent">
|
||||
<uap:VisualElements DisplayName="Nav City Breda" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="Tourist navigation app for the cirty Breda." BackgroundColor="transparent">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" ShortName="ags_logo">
|
||||
</uap:DefaultTile>
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" BackgroundColor="white" />
|
||||
<uap:InitialRotationPreference>
|
||||
<uap:Rotation Preference="portrait" />
|
||||
</uap:InitialRotationPreference>
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using NavCityBreda.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,7 +11,7 @@ using Windows.UI.Xaml;
|
||||
|
||||
namespace NavCityBreda.ViewModel
|
||||
{
|
||||
public class RouteDetailVM
|
||||
public class RouteDetailVM : INotifyPropertyChanged
|
||||
{
|
||||
Route route;
|
||||
|
||||
@@ -31,10 +32,13 @@ namespace NavCityBreda.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
int hours = route.Minutes / 60;
|
||||
int minutes = route.Minutes % 60;
|
||||
TimeSpan length = route.RouteObject.EstimatedDuration;
|
||||
return length.Hours + "h " + length.Minutes + "m";
|
||||
|
||||
return hours + "h " + minutes + "m";
|
||||
//int hours = route.Minutes / 60;
|
||||
//int minutes = route.Minutes % 60;
|
||||
|
||||
//return hours + "h " + minutes + "m";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,5 +68,35 @@ namespace NavCityBreda.ViewModel
|
||||
return route.Waypoints.Where(p => p is Landmark).Cast<Landmark>().ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return App.RouteManager.CurrentRoute != route;
|
||||
}
|
||||
}
|
||||
|
||||
public bool StopEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return !StartEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRoute()
|
||||
{
|
||||
NotifyPropertyChanged(nameof(StartEnabled));
|
||||
NotifyPropertyChanged(nameof(StopEnabled));
|
||||
}
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,16 @@
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<map:MapControl Grid.Row="0" Name="Map" MapElementClick="Map_MapElementClick" ZoomInteractionMode="GestureAndControl" PedestrianFeaturesVisible="True" PanInteractionMode="Auto" TiltInteractionMode="ControlOnly" RotateInteractionMode="GestureAndControl" MapServiceToken="74Y70e71HVjjN7lnx4Eh~3wugTlBDe2DbPGuR_AM2aA~AjMbg-pU2qn4gYf97oH0GZI1oY9Jc4vH-4WyIRyoYQM0Q71CnfbWalEN37bdSgms" />
|
||||
<map:MapControl Grid.Row="0" Name="Map" MapElementClick="Map_MapElementClick" ZoomInteractionMode="GestureAndControl" PedestrianFeaturesVisible="True" PanInteractionMode="Auto" TiltInteractionMode="ControlOnly" RotateInteractionMode="GestureAndControl" MapServiceToken="74Y70e71HVjjN7lnx4Eh~3wugTlBDe2DbPGuR_AM2aA~AjMbg-pU2qn4gYf97oH0GZI1oY9Jc4vH-4WyIRyoYQM0Q71CnfbWalEN37bdSgms">
|
||||
<!-- <map:MapItemsControl x:Name="MapItems">
|
||||
<Button x:Name="MapItemButton" Background="Transparent">
|
||||
<StackPanel>
|
||||
<Border Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" />
|
||||
<Ellipse Margin="4" Width="40" Height="20" Fill="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
</Ellipse>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</map:MapItemsControl> -->
|
||||
</map:MapControl>
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
@@ -53,6 +53,11 @@ namespace NavCityBreda.Views
|
||||
{
|
||||
if (App.RouteManager.CurrentRoute != null)
|
||||
DrawRoute();
|
||||
else
|
||||
{
|
||||
Map.MapElements.Clear();
|
||||
Map.MapElements.Add(CurrentPosition);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRoute()
|
||||
@@ -91,15 +96,14 @@ namespace NavCityBreda.Views
|
||||
Map.MapElements.Add(CurrentPosition);
|
||||
|
||||
CurrentPosition.Location = p;
|
||||
if ((bool)Settings.LOCAL_SETTINGS.Values["track"]) ;
|
||||
if ((bool)Settings.LOCAL_SETTINGS.Values["track"])
|
||||
Zoom();
|
||||
}
|
||||
|
||||
private async void Zoom()
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
await Map.TrySetViewAsync(CurrentPosition.Location);
|
||||
Map.ZoomLevel = 14;
|
||||
await Map.TrySetViewAsync(CurrentPosition.Location, 15, 0, 0, MapAnimationKind.Linear);
|
||||
}
|
||||
|
||||
private async void ZoomRoute()
|
||||
@@ -113,7 +117,7 @@ namespace NavCityBreda.Views
|
||||
MapIcon i = args.MapElements.Where(p => p is MapIcon).Cast<MapIcon>().First();
|
||||
|
||||
Waypoint w = App.RouteManager.CurrentRoute.Get(i);
|
||||
if (!(w is Landmark))
|
||||
if (w == null || !(w is Landmark))
|
||||
return;
|
||||
|
||||
Landmark l = w as Landmark;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<Page.Resources>
|
||||
<convert:BoolToCheckmarkConverter x:Key="BoolConverter"/>
|
||||
<convert:BoolToVisibilityConverter x:Key="VisConverter"/>
|
||||
</Page.Resources>
|
||||
|
||||
<ScrollViewer>
|
||||
@@ -25,6 +26,9 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<map:MapControl Grid.Row="0" Name="Map" ZoomInteractionMode="Disabled" RotateInteractionMode="Disabled" TiltInteractionMode="Disabled" PanInteractionMode="Disabled" MapServiceToken="74Y70e71HVjjN7lnx4Eh~3wugTlBDe2DbPGuR_AM2aA~AjMbg-pU2qn4gYf97oH0GZI1oY9Jc4vH-4WyIRyoYQM0Q71CnfbWalEN37bdSgms"/>
|
||||
<StackPanel Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent">
|
||||
<!-- Nothing here -->
|
||||
</StackPanel>
|
||||
|
||||
<Grid Grid.Row="1" Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -42,9 +46,10 @@
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="2" Margin="10">
|
||||
<Button Name="StartRouteButton" Click="StartRouteButton_Click" Content="Start Route" Background="DarkGreen" Foreground="White" HorizontalAlignment="Stretch" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" Margin="10" Visibility="Visible">
|
||||
<Button Name="StartRouteButton" Click="StartRouteButton_Click" Content="Start Route" Background="DarkGreen" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StartEnabled, Converter={StaticResource VisConverter}}"/>
|
||||
<Button Name="StopRouteButton" Click="StopRouteButton_Click" Content="Stop Route" Background="DarkRed" Foreground="White" HorizontalAlignment="Stretch" Visibility="{Binding StopEnabled, Converter={StaticResource VisConverter}}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="3" Margin="10">
|
||||
<TextBlock Text="[WaypointDescription]" x:Uid="WaypointDescription" Style="{StaticResource Header}"/>
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace NavCityBreda.Views
|
||||
public sealed partial class RouteDetailView : Page
|
||||
{
|
||||
private Route route;
|
||||
private RouteDetailVM vm;
|
||||
|
||||
public RouteDetailView()
|
||||
{
|
||||
@@ -41,15 +42,17 @@ namespace NavCityBreda.Views
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Route r = e.Parameter as Route;
|
||||
|
||||
if (r == route)
|
||||
{
|
||||
vm.UpdateRoute();
|
||||
LandmarkList.SelectedIndex = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
route = r;
|
||||
|
||||
this.DataContext = new RouteDetailVM(route);
|
||||
vm = new RouteDetailVM(route);
|
||||
this.DataContext = vm;
|
||||
Util.MainPage.Title = route.Name;
|
||||
|
||||
Zoom();
|
||||
@@ -82,7 +85,13 @@ namespace NavCityBreda.Views
|
||||
|
||||
private void StartRouteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.RouteManager.SetCurrentRoute(route);
|
||||
App.RouteManager.StartRoute(route);
|
||||
Util.MainPage.Navigate(typeof(MapView));
|
||||
}
|
||||
|
||||
private void StopRouteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.RouteManager.StartRoute(null);
|
||||
Util.MainPage.Navigate(typeof(MapView));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user