From 844c424c1b67473d2eb9e7bf9a3be3db160eaee4 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 20 Feb 2023 19:52:46 -0800 Subject: [PATCH] Hook up app setting for map type to mesh map Default to hybridFlyover Use short name for node annotation title, add long name to annotation detail Add map settings section to app settings --- Meshtastic.xcodeproj/project.pbxproj | 4 --- Meshtastic/Model/MapLocation.swift | 15 ---------- Meshtastic/Model/UserSettings.swift | 2 +- .../Persistence/PositionEntityExtension.swift | 2 +- .../Views/Map/Custom/MapViewSwiftUI.swift | 10 ++++--- Meshtastic/Views/Nodes/NodeMap.swift | 29 +++++++++++++++++-- Meshtastic/Views/Settings/AppSettings.swift | 17 ++++++----- 7 files changed, 45 insertions(+), 34 deletions(-) delete mode 100644 Meshtastic/Model/MapLocation.swift diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 27c1dcce..07d7f740 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -38,7 +38,6 @@ DD4F23CD28779A3C001D37CB /* EnvironmentMetricsLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD4F23CC28779A3C001D37CB /* EnvironmentMetricsLog.swift */; }; DD5394FC276993AD00AD86B1 /* SwiftProtobuf in Frameworks */ = {isa = PBXBuildFile; productRef = DD5394FB276993AD00AD86B1 /* SwiftProtobuf */; }; DD5394FE276BA0EF00AD86B1 /* PositionEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5394FD276BA0EF00AD86B1 /* PositionEntityExtension.swift */; }; - DD539502276DAA6A00AD86B1 /* MapLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD539501276DAA6A00AD86B1 /* MapLocation.swift */; }; DD58C5F22919AD3C00D5BEFB /* ChannelEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD58C5F12919AD3C00D5BEFB /* ChannelEntityExtension.swift */; }; DD5D0A9C2931B9F200F7EA61 /* EthernetModes.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5D0A9B2931B9F200F7EA61 /* EthernetModes.swift */; }; DD5E5202298EE33B00D21B61 /* admin.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5E51F0298EE33B00D21B61 /* admin.pb.swift */; }; @@ -168,7 +167,6 @@ DD4A911D2708C65400501B7E /* AppSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; sourceTree = ""; }; DD4F23CC28779A3C001D37CB /* EnvironmentMetricsLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnvironmentMetricsLog.swift; sourceTree = ""; }; DD5394FD276BA0EF00AD86B1 /* PositionEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionEntityExtension.swift; sourceTree = ""; }; - DD539501276DAA6A00AD86B1 /* MapLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapLocation.swift; sourceTree = ""; }; DD58C5F12919AD3C00D5BEFB /* ChannelEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelEntityExtension.swift; sourceTree = ""; }; DD5D0A9A2931AD6B00F7EA61 /* MeshtasticDataModelV2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModelV2.xcdatamodel; sourceTree = ""; }; DD5D0A9B2931B9F200F7EA61 /* EthernetModes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthernetModes.swift; sourceTree = ""; }; @@ -543,7 +541,6 @@ isa = PBXGroup; children = ( DD23A50E26FD1B4400D9B90C /* PeripheralModel.swift */, - DD539501276DAA6A00AD86B1 /* MapLocation.swift */, DD35018A2852FC79000FC853 /* UserSettings.swift */, ); path = Model; @@ -872,7 +869,6 @@ DD5E5210298EE33B00D21B61 /* telemetry.pb.swift in Sources */, DD5E5205298EE33B00D21B61 /* mesh.pb.swift in Sources */, DD8169F9271F1A6100F4AB02 /* MeshLogger.swift in Sources */, - DD539502276DAA6A00AD86B1 /* MapLocation.swift in Sources */, DD41582A28585C32009B0E59 /* RangeTestConfig.swift in Sources */, DD1925B728CDA5A400720036 /* CannedMessagesConfigEnums.swift in Sources */, DD5E5211298EE33B00D21B61 /* remote_hardware.pb.swift in Sources */, diff --git a/Meshtastic/Model/MapLocation.swift b/Meshtastic/Model/MapLocation.swift deleted file mode 100644 index 77fd9d02..00000000 --- a/Meshtastic/Model/MapLocation.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// MapLocation.swift -// MeshtasticApple -// -// Created by Garth Vander Houwen on 12/17/21. -// -import Foundation -import MapKit - -struct MapLocation: Identifiable { - - let id = UUID() - let name: String - let coordinate: CLLocationCoordinate2D -} diff --git a/Meshtastic/Model/UserSettings.swift b/Meshtastic/Model/UserSettings.swift index 2b95b871..2ccecdb8 100644 --- a/Meshtastic/Model/UserSettings.swift +++ b/Meshtastic/Model/UserSettings.swift @@ -59,7 +59,7 @@ class UserSettings: ObservableObject { self.provideLocation = UserDefaults.standard.object(forKey: "provideLocation") as? Bool ?? false self.provideLocationInterval = UserDefaults.standard.object(forKey: "provideLocationInterval") as? Int ?? 900 self.keyboardType = UserDefaults.standard.object(forKey: "keyboardType") as? Int ?? 0 - self.meshMapType = UserDefaults.standard.string(forKey: "meshMapType") ?? "hybrid" + self.meshMapType = UserDefaults.standard.string(forKey: "meshMapType") ?? "hybridFlyover" self.meshMapCustomTileServer = UserDefaults.standard.string(forKey: "meshMapCustomTileServer") ?? "" } } diff --git a/Meshtastic/Persistence/PositionEntityExtension.swift b/Meshtastic/Persistence/PositionEntityExtension.swift index 6bda7147..23ec54b2 100644 --- a/Meshtastic/Persistence/PositionEntityExtension.swift +++ b/Meshtastic/Persistence/PositionEntityExtension.swift @@ -52,6 +52,6 @@ extension PositionEntity { extension PositionEntity: MKAnnotation { public var coordinate: CLLocationCoordinate2D { nodeCoordinate ?? LocationHelper.DefaultLocation } - public var title: String? { nodePosition?.user?.longName ?? NSLocalizedString("unknown", comment: "Unknown") } + public var title: String? { nodePosition?.user?.shortName ?? NSLocalizedString("unknown", comment: "Unknown") } public var subtitle: String? { time?.formatted() } } diff --git a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift index 6cce2dcb..de52d486 100644 --- a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift @@ -16,9 +16,10 @@ struct MapViewSwiftUI: UIViewRepresentable { var onLongPress: (_ waypointCoordinate: CLLocationCoordinate2D) -> Void var onWaypointEdit: (_ waypointId: Int ) -> Void let mapView = MKMapView() - dynamic var positions: [PositionEntity] + dynamic let positions: [PositionEntity] dynamic let waypoints: [WaypointEntity] - let mapViewType: MKMapType + dynamic let mapViewType: MKMapType + let centerOnPositionsOnly: Bool // Offline Maps @@ -64,7 +65,7 @@ struct MapViewSwiftUI: UIViewRepresentable { if self.customMapOverlay != self.presentCustomMapOverlayHash || self.loadedLastUpdatedLocalMapFile != self.lastUpdatedLocalMapFile { mapView.removeOverlays(mapView.overlays) if self.customMapOverlay != nil { - + let fileManager = FileManager.default let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first! let tilePath = documentsDirectory.appendingPathComponent("offline_map.mbtiles", isDirectory: false).path @@ -148,7 +149,8 @@ struct MapViewSwiftUI: UIViewRepresentable { leftIcon.backgroundColor = UIColor(.indigo) annotationView.leftCalloutAccessoryView = leftIcon let subtitle = UILabel() - subtitle.text = "Latitude: \(String(format: "%.5f", positionAnnotation.coordinate.latitude)) \n" + subtitle.text = "Long Name: \(positionAnnotation.nodePosition?.user?.longName ?? "Unknown") \n" + subtitle.text! += "Latitude: \(String(format: "%.5f", positionAnnotation.coordinate.latitude)) \n" subtitle.text! += "Longitude: \(String(format: "%.5f", positionAnnotation.coordinate.longitude)) \n" let distanceFormatter = MKDistanceFormatter() subtitle.text! += "Altitude: \(distanceFormatter.string(fromDistance: Double(positionAnnotation.altitude))) \n" diff --git a/Meshtastic/Views/Nodes/NodeMap.swift b/Meshtastic/Views/Nodes/NodeMap.swift index b13caa0c..043be960 100644 --- a/Meshtastic/Views/Nodes/NodeMap.swift +++ b/Meshtastic/Views/Nodes/NodeMap.swift @@ -29,6 +29,8 @@ struct NodeMap: View { } } } + @AppStorage("meshMapType") private var meshMapType = "standard" + //&& nodePosition != nil @FetchRequest(sortDescriptors: [NSSortDescriptor(key: "time", ascending: true)], predicate: NSPredicate(format: "time >= %@ && nodePosition != nil", Calendar.current.startOfDay(for: Date()) as NSDate), animation: .none) @@ -40,7 +42,7 @@ struct NodeMap: View { ), animation: .none) private var waypoints: FetchedResults - @State private var mapType: MKMapType = .standard + @State private var mapType: MKMapType = .hybridFlyover @State var waypointCoordinate: CLLocationCoordinate2D = LocationHelper.DefaultLocation @State var editingWaypoint: Int = 0 @State private var presentingWaypointForm = false @@ -71,7 +73,7 @@ struct NodeMap: View { } }, positions: Array(positions), waypoints: Array(waypoints), - mapViewType: mapType ?? MKMapType.standard, + mapViewType: mapType , centerOnPositionsOnly: false, customMapOverlay: self.customMapOverlay, overlays: self.overlays @@ -109,6 +111,29 @@ struct NodeMap: View { .onAppear(perform: { self.bleManager.context = context self.bleManager.userSettings = userSettings + + switch meshMapType { + case "standard": + mapType = .standard + break + case "mutedStandard": + mapType = .mutedStandard + break + case "hybrid": + mapType = .hybrid + break + case "hybridFlyover": + mapType = .hybridFlyover + break + case "satellite": + mapType = .satellite + break + case "satelliteFlyover": + mapType = .satelliteFlyover + break + default: + mapType = .hybridFlyover + } }) } } diff --git a/Meshtastic/Views/Settings/AppSettings.swift b/Meshtastic/Views/Settings/AppSettings.swift index d8e2cecc..5d616d47 100644 --- a/Meshtastic/Views/Settings/AppSettings.swift +++ b/Meshtastic/Views/Settings/AppSettings.swift @@ -35,13 +35,6 @@ struct AppSettings: View { } } .pickerStyle(DefaultPickerStyle()) - - Picker("map.type", selection: $userSettings.meshMapType) { - ForEach(MeshMapType.allCases) { map in - Text(map.description) - } - } - .pickerStyle(DefaultPickerStyle()) } @@ -66,6 +59,16 @@ struct AppSettings: View { .listRowSeparator(.visible) } } + + Section(header: Text("map options")) { + + Picker("map.type", selection: $userSettings.meshMapType) { + ForEach(MeshMapType.allCases) { map in + Text(map.description) + } + } + .pickerStyle(DefaultPickerStyle()) + } } HStack { Button {