void ShowMap()
{
myMap.Children.Clear();
List<Flight> selected = GetSelectedFlights();
if (selected.Count == 0)
{
// show everything.
selected.Add(new Flight() { StartTime = DateTime.MinValue, Duration = TimeSpan.MaxValue });
}
var glitchIcon = XamlExtensions.LoadImageResource("Assets.GpsGlitchIcon.png");
var imageLayer = new MapLayer();
myMap.Children.Add(imageLayer);
MapPolyline last = currentFlight;
foreach (IDataLog log in this.logs)
{
if (log != null)
{
bool gpsIsBad = false;
foreach (var flight in selected)
{
if (flight.Log == null || flight.Log == log)
{
MapPolyline line = new MapPolyline();
line.StrokeThickness = 4;
line.Stroke = new SolidColorBrush(HlsColor.GetRandomColor());
LocationCollection points = new LocationCollection();
Debug.WriteLine("time,\t\tlat,\t\tlong,\t\t\tnsat,\talt,\thdop,\tfix");
foreach (var row in log.GetRows("GPS", flight.StartTime, flight.Duration))
{
LogEntryGPS gps = new LogEntryGPS(row);
//Debug.WriteLine("{0},\t{1},\t{2},\t{3},\t\t{4:F2},\t{5},\t{6}", gps.TimeMS, gps.Lat, gps.Lng, gps.NSats, gps.Alt, gps.HDop, gps.Fix);
if (!(gps.Lat == 0 && gps.Lon == 0))
{
var pos = new Location() { Altitude = gps.Alt, Latitude = gps.Lat, Longitude = gps.Lon };
points.Add(pos);
ulong time = (ulong)gps.GPSTime;
if (time != 0)
{
if ((gps.nSat < 5 || gps.EPH > 20))
{
if (!gpsIsBad)
{
gpsIsBad = true;
Debug.WriteLine("{0},\t{1},\t{2},\t{3},\t\t{4:F2},\t{5},\t{6}", gps.GPSTime, gps.Lat, gps.Lon, gps.nSat, gps.Alt, gps.EPH, gps.Fix);
Image img = new Image();
img.Width = 30;
img.Height = 30;
img.Source = glitchIcon;
img.Stretch = Stretch.None;
img.ToolTip = "GPS Glitch!";
imageLayer.AddChild(img, pos, PositionOrigin.Center);
}
}
else
{
gpsIsBad = false;
}
}
}
}
if (points.Count > 0)
{
line.Locations = points;
myMap.Children.Add(line);
last = line;
}
}
}
}
}
ModelViewer.Visibility = Visibility.Collapsed;
Messages.Visibility = Visibility.Collapsed;
ChartStack.Visibility = Visibility.Collapsed;
TextButton.IsChecked = false;
myMap.Visibility = Visibility.Visible;
myMap.UpdateLayout();
if (last != null)
{
try
{
myMap.SetView(last.Locations, new Thickness(20.0), 0);
}
catch (Exception ex)
{
ShowStatus(ex.Message);
}
}
}