From 992a5605642f417c5bd676328c226508815f4a04 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 9 Nov 2023 23:48:16 -0800 Subject: [PATCH] More map updates --- Meshtastic/Views/ContentView.swift | 1 + .../Views/Nodes/Helpers/MapSettingsForm.swift | 1 + .../Views/Nodes/Helpers/PositionPopover.swift | 4 +++- .../Views/Nodes/Helpers/WaypointPopover.swift | 23 ++++++++----------- Meshtastic/Views/Nodes/MeshMap.swift | 19 ++++++++------- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Meshtastic/Views/ContentView.swift b/Meshtastic/Views/ContentView.swift index bbdaddcf..c3e03235 100644 --- a/Meshtastic/Views/ContentView.swift +++ b/Meshtastic/Views/ContentView.swift @@ -26,6 +26,7 @@ struct ContentView: View { .tag(Tab.nodes) if #available(iOS 17.0, macOS 14.0, *) { MeshMap() + //NodeMap() .tabItem { Label("map", systemImage: "map") } diff --git a/Meshtastic/Views/Nodes/Helpers/MapSettingsForm.swift b/Meshtastic/Views/Nodes/Helpers/MapSettingsForm.swift index 400ef2e5..fdf4cc4a 100644 --- a/Meshtastic/Views/Nodes/Helpers/MapSettingsForm.swift +++ b/Meshtastic/Views/Nodes/Helpers/MapSettingsForm.swift @@ -90,6 +90,7 @@ Spacer() .buttonStyle(.bordered) .buttonBorderShape(.capsule) .controlSize(.large) + .padding(.bottom) #endif } .presentationDetents([.fraction(0.45), .fraction(0.65)]) diff --git a/Meshtastic/Views/Nodes/Helpers/PositionPopover.swift b/Meshtastic/Views/Nodes/Helpers/PositionPopover.swift index 12af8f4b..93cb886a 100644 --- a/Meshtastic/Views/Nodes/Helpers/PositionPopover.swift +++ b/Meshtastic/Views/Nodes/Helpers/PositionPopover.swift @@ -128,6 +128,8 @@ struct PositionPopover: View { if position.nodePosition != nil { BatteryGauge(node: position.nodePosition!) } + let mpInt = Int(position.nodePosition?.loRaConfig?.modemPreset ?? 0) + LoRaSignalStrengthMeter(snr: position.snr, rssi: position.rssi, preset: ModemPresets(rawValue: mpInt) ?? ModemPresets.longFast, compact: false) } } .padding(.top) @@ -146,7 +148,7 @@ struct PositionPopover: View { #endif } } - .presentationDetents([.fraction(0.45), .medium]) + .presentationDetents([.fraction(0.45), .fraction(0.55), .fraction(0.65)]) .presentationDragIndicator(.visible) } } diff --git a/Meshtastic/Views/Nodes/Helpers/WaypointPopover.swift b/Meshtastic/Views/Nodes/Helpers/WaypointPopover.swift index 9eb2e16e..12b1d1ad 100644 --- a/Meshtastic/Views/Nodes/Helpers/WaypointPopover.swift +++ b/Meshtastic/Views/Nodes/Helpers/WaypointPopover.swift @@ -13,14 +13,16 @@ struct WaypointPopover: View { var waypoint: WaypointEntity let distanceFormatter = MKDistanceFormatter() var body: some View { - VStack (alignment: .leading) { + VStack { HStack { - CircleText(text: String(UnicodeScalar(Int(waypoint.icon)) ?? "📍"), color: Color.orange) + CircleText(text: String(UnicodeScalar(Int(waypoint.icon)) ?? "📍"), color: Color.orange, circleSize: 65) + Spacer() Text(waypoint.name ?? "?") - .font(.title3) + .font(.largeTitle) + Spacer() if waypoint.locked > 0 { Image(systemName: "lock.fill" ) - .font(.title2) + .font(.largeTitle) } else { // Edit Button } @@ -40,12 +42,10 @@ struct WaypointPopover: View { .frame(width: 35) } .padding(.bottom, 5) - Divider() } /// Coordinate Label { Text("Coordinates: \(String(format: "%.6f", waypoint.coordinate.latitude)), \(String(format: "%.6f", waypoint.coordinate.longitude))") - //.font(.footnote) .textSelection(.enabled) .foregroundColor(.primary) } icon: { @@ -54,7 +54,6 @@ struct WaypointPopover: View { .frame(width: 35) } .padding(.bottom, 5) - Divider() /// Created Label { Text("Created: \(waypoint.created?.formatted() ?? "?")") @@ -65,7 +64,6 @@ struct WaypointPopover: View { .frame(width: 35) } .padding(.bottom, 5) - Divider() /// Updated if waypoint.lastUpdated != nil { Label { @@ -77,7 +75,6 @@ struct WaypointPopover: View { .frame(width: 35) } .padding(.bottom, 5) - Divider() } /// Expires if waypoint.expire != nil { @@ -85,12 +82,11 @@ struct WaypointPopover: View { Text("Expires: \(waypoint.expire?.formatted() ?? "?")") .foregroundColor(.primary) } icon: { - Image(systemName: "clock.badge.xmark") + Image(systemName: "hourglass.bottomhalf.filled") .symbolRenderingMode(.hierarchical) .frame(width: 35) } .padding(.bottom, 5) - Divider() } /// Distance if LocationHelper.currentLocation.distance(from: LocationHelper.DefaultLocation) > 0.0 { @@ -104,10 +100,11 @@ struct WaypointPopover: View { .frame(width: 35) } .padding(.bottom, 5) - Divider() } } + .padding(.top) #if targetEnvironment(macCatalyst) + Spacer() Button { dismiss() } label: { @@ -119,7 +116,7 @@ struct WaypointPopover: View { .padding() #endif } - .presentationDetents([.fraction(0.3), .medium]) + .presentationDetents([.fraction(0.5), .fraction(0.65)]) .tag(waypoint.id) } } diff --git a/Meshtastic/Views/Nodes/MeshMap.swift b/Meshtastic/Views/Nodes/MeshMap.swift index 2d07971a..de21cb0d 100644 --- a/Meshtastic/Views/Nodes/MeshMap.swift +++ b/Meshtastic/Views/Nodes/MeshMap.swift @@ -37,6 +37,7 @@ struct MeshMap: View { @State var selectedPosition: PositionEntity? @State var showWaypoints = false @State var selectedWaypoint: WaypointEntity? + @State var newWaypointLocation :CLLocationCoordinate2D? = nil var delay: Double = 0 @State private var scale: CGFloat = 0.5 @@ -65,12 +66,11 @@ struct MeshMap: View { ForEach(Array(waypoints), id: \.id) { waypoint in Annotation(waypoint.name ?? "?", coordinate: waypoint.coordinate) { ZStack { - CircleText(text: String(UnicodeScalar(Int(waypoint.icon)) ?? "📍"), color: Color.orange, circleSize: 35) - .onTapGesture(coordinateSpace: .named("meshmap")) { location in - print("Tapped at \(location)") + CircleText(text: String(UnicodeScalar(Int(waypoint.icon)) ?? "📍"), color: Color.orange, circleSize: 40) + .onTapGesture(perform: { location in let pinLocation = reader.convert(location, from: .local) selectedWaypoint = (selectedWaypoint == waypoint ? nil : waypoint) - } + }) } } } @@ -84,11 +84,9 @@ struct MeshMap: View { //.stroke(Color(nodeColor.darker()), lineWidth: 3) //.foregroundStyle(Color(nodeColor).opacity(0.4)) } - /// Position Annotations ForEach(Array(positions), id: \.id) { position in - let pf = PositionFlags(rawValue: Int(position.nodePosition?.metadata?.positionFlags ?? 3)) - /// Node Color from node.num + /// Node color from node.num let nodeColor = UIColor(hex: UInt32(position.nodePosition?.num ?? 0)) Annotation(position.nodePosition?.user?.longName ?? "?", coordinate: position.coordinate) { ZStack { @@ -134,7 +132,8 @@ struct MeshMap: View { MapPolyline(coordinates: routeCoords) .stroke(gradient, style: dashed) } - } // Node History + } + /// Node History if showNodeHistory { ForEach(position.nodePosition!.positions!.reversed() as! [PositionEntity], id: \.self) { (mappin: PositionEntity) in Annotation(position.latest ? position.nodePosition?.user?.shortName ?? "?": "", coordinate: position.coordinate) { @@ -152,6 +151,10 @@ struct MeshMap: View { } } } + .onTapGesture(perform: { screenCoord in + newWaypointLocation = reader.convert(screenCoord, from: .local) + print("Tapped at \(newWaypointLocation)") + }) } } .mapScope(mapScope)