From 94f690fc4864693963c61858258fe971b95bf0ec Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Tue, 12 Sep 2023 07:11:02 -0700 Subject: [PATCH] Route lines --- Meshtastic.xcodeproj/project.pbxproj | 4 +- .../Views/Nodes/Helpers/NodeMapSwiftUI.swift | 52 +++++++++++++++---- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 1cb3e9a1..333e1f7c 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -1406,7 +1406,7 @@ CODE_SIGN_ENTITLEMENTS = Meshtastic/Meshtastic.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 655; + CURRENT_PROJECT_VERSION = 657; DEVELOPMENT_ASSET_PATHS = "\"Meshtastic/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; @@ -1440,7 +1440,7 @@ CODE_SIGN_ENTITLEMENTS = Meshtastic/Meshtastic.entitlements; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 655; + CURRENT_PROJECT_VERSION = 657; DEVELOPMENT_ASSET_PATHS = "\"Meshtastic/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; diff --git a/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift b/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift index d430c170..47bdc291 100644 --- a/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift +++ b/Meshtastic/Views/Nodes/Helpers/NodeMapSwiftUI.swift @@ -35,45 +35,77 @@ struct NodeMapSwiftUI: View { @ObservedObject var node: NodeInfoEntity var body: some View { + let nodeColor = UIColor(hex: UInt32(node.num)) let positionArray = node.positions?.array as? [PositionEntity] ?? [] let mostRecent = node.positions?.lastObject as? PositionEntity + let lineCoords = positionArray.compactMap({(position) -> CLLocationCoordinate2D in + return position.nodeCoordinate ?? LocationHelper.DefaultLocation + }) + if mostRecent != nil { NavigationStack { ZStack { - Map(initialPosition: .camera(MapCamera(centerCoordinate: mostRecent!.coordinate, distance: 500, heading: 90, pitch: 60)), bounds: MapCameraBounds(minimumDistance: 100, maximumDistance: 3500), scope: mapScope) { - ForEach(positionArray, id: \.id) { position in + /// Route Lines + if meshMapShowRouteLines { + MapPolyline(coordinates: lineCoords, contourStyle: .straight) + .stroke(Color(nodeColor.lighter()), lineWidth: 8) + } + /// Node Annotations + ForEach(positionArray.reversed(), id: \.id) { position in Annotation(position.latest ? node.user?.shortName ?? "?" : "", coordinate: position.coordinate) { ZStack { + + let pf = PositionFlags(rawValue: Int(position.nodePosition?.metadata?.positionFlags ?? 3)) + + let symbolName = "flipphone" + if position.latest { Circle() - .foregroundStyle(Color(UIColor(hex: UInt32(node.num)).darker()).opacity(0.4)) + .foregroundStyle(Color(nodeColor).opacity(0.4)) .frame(width: 60, height: 60) - Image(systemName: "flipphone") + + Image(systemName: symbolName) .symbolEffect(.pulse.byLayer) .padding(7) - .foregroundStyle(Color(UIColor(hex: UInt32(node.num)).lighter()).isLight() ? .black : .white) + .foregroundStyle(Color(nodeColor.lighter()).isLight() ? .black : .white) .background(Color(UIColor(hex: UInt32(node.num)).darker())) .clipShape(Circle()) + .zIndex(100) } else { if showNodeHistory { + if pf.contains(.Heading) { +// if parent.userTrackingMode != MKUserTrackingMode.followWithHeading { +// annotationView.glyphImage = UIImage(systemName: "location.north.fill")? +// subtitle.text! += "Heading: \(String(positionAnnotation.heading)) \n" +// } else { +// annotationView.glyphImage = UIImage(systemName: "flipphone") +// } + } + if pf.contains(.Speed) { +// let formatter = MeasurementFormatter() +// formatter.locale = Locale.current +// if positionAnnotation.speed <= 1 { +// annotationView.glyphImage = UIImage(systemName: "hexagon") +// } +// subtitle.text! += "Speed: \(formatter.string(from: Measurement(value: Double(positionAnnotation.speed), unit: UnitSpeed.kilometersPerHour))) \n" + } + + Image(systemName: "mappin.circle") .padding(2) .foregroundStyle(Color(UIColor(hex: UInt32(node.num)).lighter()).isLight() ? .black : .white) .background(Color(UIColor(hex: UInt32(node.num)).lighter())) .clipShape(Circle()) + .zIndex(1000) } } } } .tag(node.num) - -// Marker(node.user?.shortName ?? "?", systemImage: "mappin.and.ellipse", coordinate: position.coordinate) -// .tint(position.latest ? Color(UIColor(hex: UInt32(node.num)).darker()) : Color(UIColor(hex: UInt32(node.num)).lighter())) -// .tag(node.num) } } .mapScope(mapScope) @@ -94,7 +126,7 @@ struct NodeMapSwiftUI: View { MapCompass(scope: mapScope) .mapControlVisibility(.visible) } - .controlSize(.large) + .controlSize(.regular) } .navigationBarTitle(String("Node Map " + (node.user?.shortName ?? "unknown".localized)), displayMode: .inline) .navigationBarItems(trailing: