From a13fa8a4dbe927721403131e786b14da6f91b2c2 Mon Sep 17 00:00:00 2001 From: Doug Slater Date: Sun, 6 Apr 2025 08:22:35 -0400 Subject: [PATCH] Fix map edit --- Directory.Build.props | 4 ++-- Ui/FitEdit.Ui.iOS/Info.plist | 4 ++-- Ui/FitEdit.Ui/ViewModels/MapViewModel.cs | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 423df1bf..76ca1ead 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,8 +9,8 @@ disable latest - 5.8.0 - 46 + 5.8.1 + 47 FitEdit EnduraByte LLC 2024 diff --git a/Ui/FitEdit.Ui.iOS/Info.plist b/Ui/FitEdit.Ui.iOS/Info.plist index ef1cd366..a97e3e94 100644 --- a/Ui/FitEdit.Ui.iOS/Info.plist +++ b/Ui/FitEdit.Ui.iOS/Info.plist @@ -7,7 +7,7 @@ CFBundleIdentifier com.endurabyte.fitedit CFBundleShortVersionString - 5.8.0 + 5.8.1 LSRequiresIPhoneOS MinimumOSVersion @@ -57,6 +57,6 @@ CFBundleVersion - 46 + 47 diff --git a/Ui/FitEdit.Ui/ViewModels/MapViewModel.cs b/Ui/FitEdit.Ui/ViewModels/MapViewModel.cs index 04e4a19d..9e71b03d 100644 --- a/Ui/FitEdit.Ui/ViewModels/MapViewModel.cs +++ b/Ui/FitEdit.Ui/ViewModels/MapViewModel.cs @@ -408,19 +408,39 @@ private ILayer? AddTrace int count = -1 ) { - var range = Enumerable.Range(index < 0 ? 0 : index, count < 0 ? fit.Records.Count : count); + var range = Enumerable + .Range(index < 0 ? 0 : index, count < 0 ? fit.Records.Count : count) + .ToList(); Coordinate[] coords = range .Select(i => fit.Records[i]) .Select(r => r.MapCoordinate()) - .Where(c => c.X != 0 && c.Y != 0) .ToArray(); + // Prevent zero lat lon + foreach (int i in range.Skip(1)) + { + PreventZeroLatLon(coords, i); + } + return editable ? AddEditTrace(coords, name, color, FitColor.RedCrayon) : AddTrace(coords, name, layer, color, lineWidth); } + private static void PreventZeroLatLon(Coordinate[] coords, int i) + { + Coordinate coord = coords[i]; + Coordinate prev = coords[i - 1]; + + const double tol = 1e-6; + if (Math.Abs(coord.X) < tol && Math.Abs(coord.Y) < tol) + { + coord.X = prev.X; + coord.Y = prev.Y; + } + } + private ILayer? AddTrace(Coordinate[] coords, string name, int layer, Avalonia.Media.Color color, int lineWidth) { if (coords.Length < 2) { return null; }