mirror of
https://github.com/dotMorten/NmeaParser.git
synced 2026-01-20 15:40:16 +01:00
Sort ntrip sources by distance
This commit is contained in:
parent
43fedd2b3f
commit
52b402323a
|
|
@ -7,6 +7,9 @@
|
|||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid >
|
||||
<Grid.Resources>
|
||||
<local:DistanceConverter x:Key="DistanceConverter" />
|
||||
</Grid.Resources>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="80" />
|
||||
<ColumnDefinition />
|
||||
|
|
@ -66,6 +69,7 @@
|
|||
<TextBlock Text="{Binding Mountpoint, StringFormat='Mount point: {0}'}" />
|
||||
<TextBlock Text="{Binding Network, StringFormat='Network: {0}'}" />
|
||||
<TextBlock Text="{Binding SupportsNmea, StringFormat='Supports NMEA: {0}'}" />
|
||||
<TextBlock Text="{Binding Converter={StaticResource DistanceConverter}}" />
|
||||
<Button Content="Connect" Click="Connect_Click" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
|
@ -41,13 +42,28 @@ namespace SampleApp.WinDesktop
|
|||
try
|
||||
{
|
||||
sources = client.GetSourceTable().OfType<NtripStream>().ToList();
|
||||
if(sources.Count == 0)
|
||||
{
|
||||
MessageBox.Show($"No NTRIP data streams found at {host.Text}:{portNumber}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch(System.Exception ex)
|
||||
{
|
||||
MessageBox.Show("Failed to connect: " + ex.Message);
|
||||
return;
|
||||
}
|
||||
sourceList.ItemsSource = sources.OrderBy(s=>s.CountryCode);
|
||||
if (MainWindow.monitor != null && !double.IsNaN(MainWindow.monitor.Latitude) && !double.IsNaN(MainWindow.monitor.Longitude))
|
||||
{
|
||||
var lat = MainWindow.monitor.Latitude;
|
||||
var lon = MainWindow.monitor.Longitude;
|
||||
// Order by closest source
|
||||
sourceList.ItemsSource = sources.OrderBy(s => PointPlotView.Vincenty.GetDistanceVincenty(lat, lon, s.Latitude, s.Longitude));
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceList.ItemsSource = sources.OrderBy(s => s.CountryCode);
|
||||
}
|
||||
}
|
||||
Stream ntripStream;
|
||||
private void Connect_Click(object sender, RoutedEventArgs e)
|
||||
|
|
@ -89,4 +105,23 @@ namespace SampleApp.WinDesktop
|
|||
ntripstatus.Text = $"Connected";
|
||||
}
|
||||
}
|
||||
public class DistanceConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is NtripStream s && MainWindow.monitor?.IsFixValid == true)
|
||||
{
|
||||
var lat = MainWindow.monitor.Latitude;
|
||||
var lon = MainWindow.monitor.Longitude;
|
||||
var distance = PointPlotView.Vincenty.GetDistanceVincenty(lat, lon, s.Latitude, s.Longitude);
|
||||
return "Distance: " + (distance / 1000).ToString("0.##") + "km";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue