From 350678c2b99e71101c93ace6acb90c4243d7493d Mon Sep 17 00:00:00 2001 From: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com> Date: Fri, 23 May 2025 20:53:31 -0700 Subject: [PATCH] Added Favorites Only Map Option --- Localizable.xcstrings | 3 +++ Meshtastic/Extensions/UserDefaults.swift | 4 ++++ .../Map/MapContent/MeshMapContent.swift | 21 ++++++++++++++----- .../Nodes/Helpers/Map/MapSettingsForm.swift | 11 +++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index 1ea85731..078e657c 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -20686,6 +20686,9 @@ } } } + }, + "Only Show Favorites" : { + }, "Open Location Code (aka Plus Codes)" : { "localizations" : { diff --git a/Meshtastic/Extensions/UserDefaults.swift b/Meshtastic/Extensions/UserDefaults.swift index 87bfe3f2..ee9a9ebc 100644 --- a/Meshtastic/Extensions/UserDefaults.swift +++ b/Meshtastic/Extensions/UserDefaults.swift @@ -57,6 +57,7 @@ extension UserDefaults { case enableMapTraffic case enableMapPointsOfInterest case enableOfflineMaps + case onlyShowFavoriteNodesMap case mapTileServer case enableOverlayServer case mapOverlayServer @@ -118,6 +119,9 @@ extension UserDefaults { @UserDefault(.enableMapPointsOfInterest, defaultValue: false) static var enableMapPointsOfInterest: Bool + + @UserDefault(.onlyShowFavoriteNodesMap, defaultValue: false) + static var onlyShowFavoriteNodesMap: Bool @UserDefault(.enableDetectionNotifications, defaultValue: false) static var enableDetectionNotifications: Bool diff --git a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift index f8829d21..ba29cc1a 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/MapContent/MeshMapContent.swift @@ -15,6 +15,7 @@ struct MeshMapContent: MapContent { @AppStorage("meshMapShowNodeHistory") private var showNodeHistory = false @AppStorage("meshMapShowRouteLines") private var showRouteLines = false @AppStorage("enableMapConvexHull") private var showConvexHull = false + @AppStorage("onlyShowFavoriteNodesMap") private var favoriteNodesOnly = false @Binding var showTraffic: Bool @Binding var showPointsOfInterest: Bool @Binding var selectedMapLayer: MapLayer @@ -39,11 +40,12 @@ struct MeshMapContent: MapContent { @MapContentBuilder var positionAnnotations: some MapContent { ForEach(positions, id: \.id) { position in - /// Node color from node.num - let nodeColor = UIColor(hex: UInt32(position.nodePosition?.num ?? 0)) - let positionName = position.nodePosition?.user?.longName ?? "?" - /// Latest Position Anotations - Annotation(positionName, coordinate: position.coordinate) { + if !favoriteNodesOnly || (position.nodePosition?.favorite == true) { + /// Node color from node.num + let nodeColor = UIColor(hex: UInt32(position.nodePosition?.num ?? 0)) + let positionName = position.nodePosition?.user?.longName ?? "?" + /// Latest Position Anotations + Annotation(positionName, coordinate: position.coordinate) { LazyVStack { ZStack { let nodeColor = UIColor(hex: UInt32(position.nodePosition?.num ?? 0)) @@ -59,6 +61,13 @@ struct MeshMapContent: MapContent { .onAppear { self.scale = 1 } + .onChange(of: favoriteNodesOnly) { + + scale = 0.5 // Reset to initial state + DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { + scale = 1 + } + } .frame(width: 60, height: 60) } if position.nodePosition?.hasDetectionSensorMetrics ?? false { @@ -141,6 +150,8 @@ struct MeshMapContent: MapContent { } } } + + } } @MapContentBuilder diff --git a/Meshtastic/Views/Nodes/Helpers/Map/MapSettingsForm.swift b/Meshtastic/Views/Nodes/Helpers/Map/MapSettingsForm.swift index 85db444a..acea5d19 100644 --- a/Meshtastic/Views/Nodes/Helpers/Map/MapSettingsForm.swift +++ b/Meshtastic/Views/Nodes/Helpers/Map/MapSettingsForm.swift @@ -15,6 +15,7 @@ struct MapSettingsForm: View { @AppStorage("meshMapShowRouteLines") private var routeLines = false @AppStorage("enableMapConvexHull") private var convexHull = false @AppStorage("enableMapWaypoints") private var waypoints = true + @AppStorage("onlyShowFavoriteNodesMap") private var favoriteNodesOnly = false @Binding var traffic: Bool @Binding var pointsOfInterest: Bool @Binding var mapLayer: MapLayer @@ -61,7 +62,15 @@ struct MapSettingsForm: View { UserDefaults.enableMapWaypoints = !waypoints } } - + + Toggle(isOn: $favoriteNodesOnly) { + Label("Only Show Favorites", systemImage: "star.fill") + } + .toggleStyle(SwitchToggleStyle(tint: .accentColor)) + .onTapGesture { + self.favoriteNodesOnly.toggle() + UserDefaults.onlyShowFavoriteNodesMap = self.favoriteNodesOnly + } Toggle(isOn: $nodeHistory) { Label("Node History", systemImage: "building.columns.fill") }