From 089022d3626639135c043878ab5b4ed1339148a1 Mon Sep 17 00:00:00 2001 From: Jacob Powers Date: Sun, 8 Sep 2024 04:47:14 +0000 Subject: [PATCH 1/2] add centerMapAt --- Meshtastic/Views/Nodes/MeshMap.swift | 34 ++++++++++++++++++++++++++-- Widgets/WidgetsLiveActivity.swift | 4 ++-- scripts/lint/lint-fix-changes.sh | 10 ++++---- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Meshtastic/Views/Nodes/MeshMap.swift b/Meshtastic/Views/Nodes/MeshMap.swift index 595abb15..c4f987ab 100644 --- a/Meshtastic/Views/Nodes/MeshMap.swift +++ b/Meshtastic/Views/Nodes/MeshMap.swift @@ -33,6 +33,7 @@ struct MeshMap: View { @Namespace var mapScope @State var mapStyle: MapStyle = MapStyle.standard(elevation: .flat, emphasis: MapStyle.StandardEmphasis.muted, pointsOfInterest: .excludingAll, showsTraffic: false) @State var position = MapCameraPosition.automatic + @State private var distance = 10000.0 @State private var editingSettings = false @State private var editingFilters = false @State var selectedPosition: PositionEntity? @@ -60,8 +61,19 @@ struct MeshMap: View { NavigationStack { ZStack { MapReader { reader in - Map(position: $position, bounds: MapCameraBounds(minimumDistance: 1, maximumDistance: .infinity), scope: mapScope) { - MeshMapContent(showUserLocation: $showUserLocation, showTraffic: $showTraffic, showPointsOfInterest: $showPointsOfInterest, selectedMapLayer: $selectedMapLayer, selectedPosition: $selectedPosition, selectedWaypoint: $selectedWaypoint) + Map( + position: $position, + bounds: MapCameraBounds(minimumDistance: 1, maximumDistance: .infinity), + scope: mapScope + ) { + MeshMapContent( + showUserLocation: $showUserLocation, + showTraffic: $showTraffic, + showPointsOfInterest: $showPointsOfInterest, + selectedMapLayer: $selectedMapLayer, + selectedPosition: $selectedPosition, + selectedWaypoint: $selectedWaypoint + ) } .mapScope(mapScope) .mapStyle(mapStyle) @@ -74,6 +86,9 @@ struct MeshMap: View { .mapControlVisibility(.automatic) } .controlSize(.regular) + .onMapCameraChange(frequency: MapCameraUpdateFrequency.continuous, { context in + distance = context.camera.distance + }) .onTapGesture(count: 1, perform: { position in newWaypointCoord = reader.convert(position, from: .local) ?? CLLocationCoordinate2D.init() }) @@ -92,6 +107,7 @@ struct MeshMap: View { Logger.services.error("Unable to convert local point to coordinate on map.") return } + centerMapAt(coordinate: coordinate) newWaypointCoord = coordinate editingWaypoint = WaypointEntity(context: context) @@ -210,4 +226,18 @@ struct MeshMap: View { UIApplication.shared.isIdleTimerDisabled = false }) } + + // moves the map to a new coordinate + private func centerMapAt(coordinate: CLLocationCoordinate2D) { + withAnimation(.easeInOut(duration: 0.2), { + position = .camera( + MapCamera( + centerCoordinate: coordinate, // Set new center + distance: distance, // Preserve current zoom distance + heading: 0, // align north + pitch: 0 // set view to top down + ) + ) + }) + } } diff --git a/Widgets/WidgetsLiveActivity.swift b/Widgets/WidgetsLiveActivity.swift index e6177129..154edf9d 100644 --- a/Widgets/WidgetsLiveActivity.swift +++ b/Widgets/WidgetsLiveActivity.swift @@ -120,7 +120,7 @@ struct WidgetsLiveActivity: Widget { } } -//struct WidgetsLiveActivity_Previews: PreviewProvider { +// struct WidgetsLiveActivity_Previews: PreviewProvider { // static let attributes = MeshActivityAttributes(nodeNum: 123456789, name: "RAK Compact Rotary Handset Gray 8E6G") // static let state = MeshActivityAttributes.ContentState( // timerRange: Date.now...Date(timeIntervalSinceNow: 60), connected: true, channelUtilization: 25.84, airtime: 10.01, batteryLevel: 39, nodes: 17, nodesOnline: 9) @@ -139,7 +139,7 @@ struct WidgetsLiveActivity: Widget { // .previewContext(state, viewKind: .content) // .previewDisplayName("Notification") // } -//} +// } struct LiveActivityView: View { @Environment(\.colorScheme) private var colorScheme diff --git a/scripts/lint/lint-fix-changes.sh b/scripts/lint/lint-fix-changes.sh index e4dae8d0..2de03ea2 100755 --- a/scripts/lint/lint-fix-changes.sh +++ b/scripts/lint/lint-fix-changes.sh @@ -23,22 +23,22 @@ if [[ -e "${SWIFT_LINT}" ]]; then ##### Fix files or exit if no files found for fixing ##### if [ "$count" -ne 0 ]; then echo "Found files to fix! Running swiftLint --fix..." - + # Run SwiftLint --fix on each file for ((i = 0; i < count; i++)); do file_var="SCRIPT_INPUT_FILE_$i" file_path=${!file_var} echo "Fixing $file_path" - $SWIFT_LINT --fix --path "$file_path" + $SWIFT_LINT --fix "$file_path" done - + # Add the fixed files back to staging for ((i = 0; i < count; i++)); do file_var="SCRIPT_INPUT_FILE_$i" file_path=${!file_var} git add "$file_path" done - + echo "swiftLint --fix completed and files re-staged." # Optionally lint the fixed files @@ -61,4 +61,4 @@ if [[ -e "${SWIFT_LINT}" ]]; then else echo "SwiftLint not installed. Please install from https://github.com/realm/SwiftLint" exit -1 -fi \ No newline at end of file +fi From 496016c6fa1da51955bb9664d6b73d3746d963e8 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 19 Sep 2024 20:01:05 -0700 Subject: [PATCH 2/2] Use first appear on mesh map --- Localizable.xcstrings | 18 +++++++++++++++--- Meshtastic/Enums/AppSettingsEnums.swift | 1 - Meshtastic/Views/Nodes/MeshMap.swift | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Localizable.xcstrings b/Localizable.xcstrings index a61ea1cf..42554c57 100644 --- a/Localizable.xcstrings +++ b/Localizable.xcstrings @@ -21,6 +21,21 @@ }, ": %d" : { + }, + ".dot" : { + + }, + ".gauge" : { + + }, + ".gradient" : { + + }, + ".pill" : { + + }, + ".text" : { + }, "(Re)define PIN_GPS_EN for your board." : { @@ -19154,9 +19169,6 @@ }, "Send" : { - }, - "Send ${messageContent} to ${channelNumber}" : { - }, "Send a Group Message" : { diff --git a/Meshtastic/Enums/AppSettingsEnums.swift b/Meshtastic/Enums/AppSettingsEnums.swift index bfd8ce9e..690fe399 100644 --- a/Meshtastic/Enums/AppSettingsEnums.swift +++ b/Meshtastic/Enums/AppSettingsEnums.swift @@ -59,7 +59,6 @@ enum MeshMapDistances: Double, CaseIterable, Identifiable { case fifteenHundredMiles = 2414016 case twentyFiveHundredMiles = 4023360 case fiveThouandMiles = 8046720 - case tenThousandMiles = 16093440 var id: Double { self.rawValue } var description: String { let distanceFormatter = MKDistanceFormatter() diff --git a/Meshtastic/Views/Nodes/MeshMap.swift b/Meshtastic/Views/Nodes/MeshMap.swift index c4f987ab..5dd6e19a 100644 --- a/Meshtastic/Views/Nodes/MeshMap.swift +++ b/Meshtastic/Views/Nodes/MeshMap.swift @@ -205,7 +205,7 @@ struct MeshMap: View { .navigationBarItems(leading: MeshtasticLogo(), trailing: ZStack { ConnectedDevice(bluetoothOn: bleManager.isSwitchedOn, deviceConnected: bleManager.connectedPeripheral != nil, name: (bleManager.connectedPeripheral != nil) ? bleManager.connectedPeripheral.shortName : "?") }) - .onAppear { + .onFirstAppear { UIApplication.shared.isIdleTimerDisabled = true // let wayPointEntity = getWaypoint(id: Int64(deepLinkManager.waypointId) ?? -1, context: context)