Meshtastic-Apple/Meshtastic/Views/Nodes/Helpers/Map/MapSettingsForm.swift

230 lines
6.9 KiB
Swift
Raw Normal View History

//
// MapSettingsForm.swift
// Meshtastic
//
// Created by Garth Vander Houwen on 10/3/23.
//
import SwiftUI
import MapKit
2025-07-22 00:48:50 +00:00
import OSLog
struct MapSettingsForm: View {
@Environment(\.dismiss) private var dismiss
2024-07-17 21:43:06 -07:00
@State private var currentDetent = PresentationDetent.medium
@AppStorage("meshMapShowNodeHistory") private var nodeHistory = false
2025-05-24 00:19:00 -07:00
@AppStorage("meshMapShowRouteLines") private var enableMapRouteLines = false
@AppStorage("enableMapConvexHull") private var convexHull = false
2025-05-24 00:19:00 -07:00
@AppStorage("enableMapWaypoints") private var enableMapWaypoints = true
@AppStorage("enableMapShowFavorites") private var enableMapShowFavorites = false
2025-07-22 00:48:50 +00:00
@AppStorage("mapOverlaysEnabled") private var mapOverlaysEnabled = false
2025-07-22 04:13:54 +00:00
@ObservedObject private var mapDataManager = MapDataManager.shared
2023-11-09 17:43:38 -08:00
@Binding var traffic: Bool
@Binding var pointsOfInterest: Bool
@Binding var mapLayer: MapLayer
@AppStorage("meshMapDistance") private var meshMapDistance: Double = 800000
@Binding var meshMap: Bool
@Binding var enabledOverlayConfigs: Set<UUID>
var body: some View {
2023-11-26 10:45:03 -08:00
NavigationStack {
Form {
Section(header: Text("Map Options")) {
Picker(selection: $mapLayer, label: Text("")) {
ForEach(MapLayer.allCases, id: \.self) { layer in
if layer != MapLayer.offline {
2025-05-23 23:41:32 -07:00
Text(layer.localized.capitalized)
}
}
}
.pickerStyle(SegmentedPickerStyle())
.padding(.top, 5)
.padding(.bottom, 5)
2024-10-05 15:50:57 -07:00
.onChange(of: mapLayer) { _, newMapLayer in
2023-11-09 17:43:38 -08:00
UserDefaults.mapLayer = newMapLayer
}
if meshMap {
2024-03-25 15:21:38 -07:00
HStack {
Label("Show nodes", systemImage: "lines.measurement.horizontal")
Picker("", selection: $meshMapDistance) {
ForEach(MeshMapDistances.allCases) { di in
Text(di.description)
.tag(di.id)
2024-03-24 22:23:55 -07:00
}
}
2024-03-25 15:21:38 -07:00
.pickerStyle(DefaultPickerStyle())
2024-03-24 22:23:55 -07:00
}
2024-10-05 15:50:57 -07:00
.onChange(of: meshMapDistance) { _, newMeshMapDistance in
2024-03-24 22:23:55 -07:00
UserDefaults.meshMapDistance = newMeshMapDistance
}
2025-05-24 00:19:00 -07:00
Toggle(isOn: $enableMapWaypoints) {
Label {
Text("Show Waypoints")
} icon: {
Image(systemName: "signpost.right.and.left")
.symbolRenderingMode(.multicolor)
}
2024-03-25 19:20:36 -07:00
}
2025-05-24 00:19:00 -07:00
.tint(.accentColor)
}
2025-05-24 00:19:00 -07:00
Toggle(isOn: $enableMapShowFavorites) {
Label {
Text("Favorites")
} icon: {
Image(systemName: "star.fill")
.symbolRenderingMode(.multicolor)
}
2025-05-23 20:53:31 -07:00
}
2025-05-24 00:19:00 -07:00
.tint(.accentColor)
Toggle(isOn: $nodeHistory) {
Label("Node History", systemImage: "building.columns.fill")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.onTapGesture {
self.nodeHistory.toggle()
UserDefaults.enableMapNodeHistoryPins = self.nodeHistory
}
2025-05-24 00:19:00 -07:00
Toggle(isOn: $enableMapRouteLines) {
Label("Route Lines", systemImage: "road.lanes")
}
2025-05-24 00:19:00 -07:00
.tint(.accentColor)
Toggle(isOn: $convexHull) {
Label("Convex Hull", systemImage: "button.angledbottom.horizontal.right")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.onTapGesture {
self.convexHull.toggle()
UserDefaults.enableMapConvexHull = self.convexHull
}
Toggle(isOn: $traffic) {
Label("Traffic", systemImage: "car")
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.onTapGesture {
self.traffic.toggle()
UserDefaults.enableMapTraffic = self.traffic
}
Toggle(isOn: $pointsOfInterest) {
2025-05-24 00:19:00 -07:00
Label {
Text("Points of Interest")
} icon: {
Image(systemName: "mappin.and.ellipse")
.symbolRenderingMode(.multicolor)
}
}
2025-05-24 00:19:00 -07:00
.tint(.accentColor)
.onTapGesture {
self.pointsOfInterest.toggle()
UserDefaults.enableMapPointsOfInterest = self.pointsOfInterest
}
}
Section(header: Text("Map Overlays")) {
2025-07-21 21:42:36 +00:00
let hasUserData = GeoJSONOverlayManager.shared.hasUserData()
// Master toggle for map overlays
2025-07-22 00:48:50 +00:00
Toggle(isOn: $mapOverlaysEnabled) {
2025-07-16 02:45:17 +00:00
Label {
2025-07-21 21:42:36 +00:00
VStack(alignment: .leading) {
Text("Map Overlays")
Text(GeoJSONOverlayManager.shared.getActiveDataSource())
.font(.caption)
.foregroundColor(.secondary)
}
2025-07-16 02:45:17 +00:00
} icon: {
2025-07-21 21:42:36 +00:00
Image(systemName: "map")
.symbolRenderingMode(.multicolor)
2025-07-16 02:45:17 +00:00
}
}
.tint(.accentColor)
.disabled(!hasUserData && !mapOverlaysEnabled)
2025-07-22 00:48:50 +00:00
// Show individual file toggles when overlays are enabled
if mapOverlaysEnabled && hasUserData {
2025-07-22 04:13:54 +00:00
if !mapDataManager.getUploadedFiles().isEmpty {
2025-07-22 00:48:50 +00:00
// Individual file toggles
2025-07-22 04:13:54 +00:00
ForEach(mapDataManager.getUploadedFiles()) { file in
2025-07-22 00:48:50 +00:00
Toggle(isOn: Binding(
2025-07-23 20:26:50 +00:00
get: {
2025-07-22 02:18:00 +00:00
return enabledOverlayConfigs.contains(file.id)
2025-07-22 00:48:50 +00:00
},
set: { newValue in
if newValue {
enabledOverlayConfigs.insert(file.id)
} else {
enabledOverlayConfigs.remove(file.id)
}
2025-07-22 00:48:50 +00:00
}
)) {
Label {
VStack(alignment: .leading) {
Text(file.originalName)
.font(.subheadline)
HStack {
Text("\(file.overlayCount) \(file.overlayCount > 1 ? "features".localized : "feature".localized)")
2025-07-22 00:48:50 +00:00
.font(.caption2)
.foregroundColor(.secondary)
Spacer()
Text(ByteCountFormatter.string(fromByteCount: file.fileSize, countStyle: .file))
.font(.caption2)
.foregroundColor(.secondary)
}
}
} icon: {
let isEnabled = enabledOverlayConfigs.contains(file.id)
Image(systemName: isEnabled ? "doc.fill" : "doc")
.foregroundColor(isEnabled ? .accentColor : .secondary)
2025-07-22 00:48:50 +00:00
}
}
.tint(.accentColor)
}
2025-07-22 04:13:54 +00:00
NavigationLink(destination: MapDataFiles()) {
Label {
Text("Manage map data")
} icon: {
2025-07-22 00:48:50 +00:00
Image(systemName: "folder")
.symbolRenderingMode(.multicolor)
2025-07-22 00:48:50 +00:00
}
}
} else {
ContentUnavailableView ("No map data files uploaded", systemImage: "exclamationmark.triangle")
2025-07-21 21:42:36 +00:00
}
} else if !hasUserData {
2025-07-22 00:48:50 +00:00
// Upload prompt when no data available
2025-07-22 04:13:54 +00:00
NavigationLink(destination: MapDataFiles()) {
Label {
Text("Upload map data to enable overlays")
} icon: {
2025-07-21 21:42:36 +00:00
Image(systemName: "arrow.up.doc")
.symbolRenderingMode(.multicolor)
2025-07-21 21:42:36 +00:00
}
}
}
2025-07-16 02:45:17 +00:00
}
}
#if targetEnvironment(macCatalyst)
Spacer()
Button {
dismiss()
} label: {
Label("Close", systemImage: "xmark")
}
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.controlSize(.large)
.padding(.bottom)
#endif
}
2024-07-17 21:43:06 -07:00
.presentationDetents([.medium, .large], selection: $currentDetent)
.presentationContentInteraction(.scrolls)
2023-11-09 17:43:38 -08:00
.presentationDragIndicator(.visible)
2024-07-17 21:43:06 -07:00
.presentationBackgroundInteraction(.enabled(upThrough: .medium))
2025-07-22 00:48:50 +00:00
.onAppear {
2025-07-22 04:13:54 +00:00
// Initialize map data manager
mapDataManager.initialize()
2025-07-22 00:48:50 +00:00
}
}
}