diff --git a/Meshtastic/Enums/AppSettingsEnums.swift b/Meshtastic/Enums/AppSettingsEnums.swift index 994a0e90..97435ff3 100644 --- a/Meshtastic/Enums/AppSettingsEnums.swift +++ b/Meshtastic/Enums/AppSettingsEnums.swift @@ -152,12 +152,27 @@ enum LocationUpdateInterval: Int, CaseIterable, Identifiable { } enum MapTileServerLinks: Int, CaseIterable, Identifiable { - case openStreetMaps - case wikimedia - case nationalMap + case none = 0 + case openStreetMaps = 1 + case wikimedia = 2 + case nationalMap = 3 var id: Int { self.rawValue } + var description: String { + switch self { + case .none: + return "Please Select" + case .wikimedia: + return "Wikimedia" + case .openStreetMaps: + return "Open Street Maps" + case .nationalMap: + return "US National Map" + } + } var tileUrl: String { switch self { + case .none: + return "" case .wikimedia: return "https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png" case .openStreetMaps: @@ -168,6 +183,8 @@ enum MapTileServerLinks: Int, CaseIterable, Identifiable { } var zoomRange: [Int] { switch self { + case .none: + return [Int](0...1) case .wikimedia: return [Int](0...24) case .openStreetMaps: diff --git a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift index d3959646..4d62b487 100644 --- a/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/Custom/MapViewSwiftUI.swift @@ -160,10 +160,10 @@ struct MapViewSwiftUI: UIViewRepresentable { var lineIndex = 0 for position in latest { - let nodePositions = positions.filter { $0.nodePosition?.num ?? 0 == position.nodePosition?.num ?? -1 } - let lineCoords = nodePositions.map ({ + let nodePositions = positions.filter { $0.nodeCoordinate != nil && $0.nodePosition?.num ?? 0 == position.nodePosition?.num ?? -1 } + let lineCoords = nodePositions.compactMap ({ (position) -> CLLocationCoordinate2D in - return position.nodeCoordinate! + return position.nodeCoordinate ?? LocationHelper.DefaultLocation }) let polyline = MKPolyline(coordinates: lineCoords, count: nodePositions.count) polyline.title = "\(String(position.nodePosition?.num ?? 0))" diff --git a/Meshtastic/Views/Nodes/NodeMap.swift b/Meshtastic/Views/Nodes/NodeMap.swift index 03c5dc70..d0f4f418 100644 --- a/Meshtastic/Views/Nodes/NodeMap.swift +++ b/Meshtastic/Views/Nodes/NodeMap.swift @@ -15,7 +15,7 @@ struct NodeMap: View { @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager - @AppStorage("meshMapType") private var meshMapType = 0 + @State var meshMapType: Int = UserDefaults.mapType @State var enableMapRecentering: Bool = UserDefaults.enableMapRecentering @State var enableMapRouteLines: Bool = UserDefaults.enableMapRouteLines @State var enableMapNodeHistoryPins: Bool = UserDefaults.enableMapNodeHistoryPins @@ -32,8 +32,9 @@ struct NodeMap: View { ), animation: .none) private var waypoints: FetchedResults - @State private var mapType: MKMapType = .standard + @State var mapType: MKMapType = .standard @State var selectedTracking: UserTrackingModes = .none + @State var selectedTileServer: MapTileServerLinks = .wikimedia @State var isPresentingInfoSheet: Bool = false @State var waypointCoordinate: WaypointCoordinate? @@ -137,8 +138,23 @@ struct NodeMap: View { self.enableOfflineMaps.toggle() UserDefaults.enableOfflineMaps = self.enableOfflineMaps } + Text("If you have shared a MBTiles file with meshtastic it will be loaded.") + .font(.caption) + .foregroundColor(.gray) + if UserDefaults.enableOfflineMaps { HStack { +// Picker("Tile Servers", selection: $selectedTileServer) { +// ForEach(MapTileServerLinks.allCases) { ts in +// Text(ts.description) +// .tag(ts.id) +// } +// } +// .pickerStyle(.menu) +// .onChange(of: (selectedTileServer)) { newTileServer in +// +// mapTileServer = selectedTileServer.tileUrl +// } Label("Tile Server", systemImage: "square.grid.3x2") TextField( @@ -147,7 +163,7 @@ struct NodeMap: View { axis: .vertical ) .foregroundColor(.gray) - .font(.caption2) + .font(.caption) .onChange(of: (mapTileServer)) { newMapTileServer in UserDefaults.mapTileServer = newMapTileServer }