From 776f1c15e4992fea2ecf4157558fe3d3de1b046a Mon Sep 17 00:00:00 2001 From: johnjore Date: Mon, 30 Sep 2024 09:29:27 +1000 Subject: [PATCH 1/2] Remove OSM as option for bulk download Optimize Tracks when displaying at startup --- Fragments/Fragment_preferences.cs | 17 +++++++++++++---- GPX/GPXAdapter.cs | 3 +++ Utils/DisplayMapItems.cs | 19 ++++++++++++------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Fragments/Fragment_preferences.cs b/Fragments/Fragment_preferences.cs index dc524d8..6b4a151 100644 --- a/Fragments/Fragment_preferences.cs +++ b/Fragments/Fragment_preferences.cs @@ -87,8 +87,8 @@ public override void OnCreatePreferences(Bundle? savedInstanceState, string? roo SetPreferencesFromResource(Resource.Xml.Preferences, rootKey); //Populate the ListPreference's - CreateArrayList((ListPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.OSM_Browse_Source))); - CreateArrayList((ListPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.OSM_BulkDownload_Source))); + CreateArrayList((ListPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.OSM_Browse_Source)), false); + CreateArrayList((ListPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.OSM_BulkDownload_Source)), true); //Set Summary to "Not Set" or "Hidden" for sensitive fields SetSummary((EditTextPreference)FindPreference(Platform.CurrentActivity?.GetString(Resource.String.MapboxToken))); @@ -103,14 +103,23 @@ public override void OnCreatePreferences(Bundle? savedInstanceState, string? roo PreferenceManager.GetDefaultSharedPreferences(Platform.AppContext)?.RegisterOnSharedPreferenceChangeListener(this); } - private static void CreateArrayList(ListPreference? lp) + private static void CreateArrayList(ListPreference? lp, bool FilterOpenStreetMap) { if (lp == null) { return; } - string[] entries = MapSources.Select(x => x.Name).ToArray(); + string[] entries = []; + if (FilterOpenStreetMap) + { + //Remove OpenStreetMap entry, it can't be used for bulk downloads + entries = MapSources.Where(x => x.Name != "OpenStreetMap").Select(x => x.Name).ToArray(); + } + else + { + entries = MapSources.Select(x => x.Name).ToArray(); + } lp.SetEntries(entries); lp.SetEntryValues(entries); diff --git a/GPX/GPXAdapter.cs b/GPX/GPXAdapter.cs index 7be0da7..00bb332 100644 --- a/GPX/GPXAdapter.cs +++ b/GPX/GPXAdapter.cs @@ -252,6 +252,9 @@ private void gpx_menu_showonmap(GPXViewHolder vh, ViewGroup parent) { Log.Information($"Show route on map '{vh.Name.Text}'"); + //Enumerate route/tracks on Layer, and only add if not already displayed + /**/ + //Get the route var routetrack_2 = RouteDatabase.GetRouteAsync(vh.Id).Result; GpxClass gpx_2 = GpxClass.FromXml(routetrack_2.GPX); diff --git a/Utils/DisplayMapItems.cs b/Utils/DisplayMapItems.cs index c2a5f0b..a8b6b13 100644 --- a/Utils/DisplayMapItems.cs +++ b/Utils/DisplayMapItems.cs @@ -67,7 +67,7 @@ public static void AddPOIToMap() } catch (Exception ex) { - Serilog.Log.Fatal(ex, $"MapItems - AddPOIToMap"); + Serilog.Log.Fatal(ex, $"DisplayMapItems - AddPOIToMap"); } } @@ -93,7 +93,7 @@ public static void AddRouteToMap(string mapRoute, GPXType gpxtype, bool UpdateMe } catch (Exception ex) { - Serilog.Log.Fatal(ex, $"MapItems - AddRouteToMap()"); + Serilog.Log.Fatal(ex, $"DisplayMapItems - AddRouteToMap()"); } //Enable menu @@ -127,19 +127,24 @@ public static void AddTracksToMap() { GpxClass gpx = GpxClass.FromXml(track.GPX); + //Reduce the number of waypoints before drawing on map + gpx = GPX.GPXOptimize.Optimize(gpx); + if (track.GPXType == GPXType.Track) { gpx.Routes.Add(gpx.Tracks[0].ToRoutes()[0]); } string? mapRouteTrack = Import.ParseGPXtoRoute(gpx.Routes[0]).Item1; - - //Menus etc not yet created as app not fully initialized. Dirty workaround - AddRouteToMap(mapRouteTrack, GPXType.Track, false); + if (mapRouteTrack != null) + { + //Menus etc not yet created as app not fully initialized. Dirty workaround + AddRouteToMap(mapRouteTrack, GPXType.Track, false); + } } } catch (Exception ex) { - Serilog.Log.Fatal(ex, $"Import - AddTracksToMap()"); + Serilog.Log.Fatal(ex, $"DisplayMapItems - AddTracksToMap()"); } } @@ -232,7 +237,7 @@ private static ILayer CreateRouteandTrackLayer(string strRoute, Mapsui.Styles.Co } catch (Exception ex) { - Serilog.Log.Fatal(ex, $"MapItems - CreateRouteAndTrackLayer()"); + Serilog.Log.Fatal(ex, $"DisplayMapItems - CreateRouteAndTrackLayer()"); } return new MemoryLayer From ba22f49404a0b960738209a770091f512ddaf868 Mon Sep 17 00:00:00 2001 From: johnjore Date: Mon, 30 Sep 2024 11:03:26 +1000 Subject: [PATCH 2/2] Update packages --- hajk.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hajk.csproj b/hajk.csproj index b394fcc..825f9f0 100644 --- a/hajk.csproj +++ b/hajk.csproj @@ -73,12 +73,12 @@ - - + + - +