Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add centerMapAt util to MeshMap #918

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions Meshtastic/Views/Nodes/MeshMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this initial value will only matter when someone tries to deep link to a node before they've zoomed into an area on this map. (initial map zoom is set separately by MapCameraBounds(..., maximumDistance: .infinity),

It might be nice to tune this to whatever we find to be the most common ranges are when someone's wanting to view a point of interest. (be it waypoint or node)

@State private var editingSettings = false
@State private var editingFilters = false
@State var selectedPosition: PositionEntity?
Expand Down Expand Up @@ -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)
Expand All @@ -74,6 +86,9 @@ struct MeshMap: View {
.mapControlVisibility(.automatic)
}
.controlSize(.regular)
.onMapCameraChange(frequency: MapCameraUpdateFrequency.continuous, { context in
distance = context.camera.distance
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map zoom distance value isn't available through position (position.camera == nil). A few discussions I found recommended this solution.

})
.onTapGesture(count: 1, perform: { position in
newWaypointCoord = reader.convert(position, from: .local) ?? CLLocationCoordinate2D.init()
})
Expand All @@ -92,6 +107,7 @@ struct MeshMap: View {
Logger.services.error("Unable to convert local point to coordinate on map.")
return
}
centerMapAt(coordinate: coordinate)
Copy link
Contributor Author

@powersjcb powersjcb Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally a quick hack for testing (since I don't have a way to access node data from Simulator), but centering the map on the location a waypoint is being proposed actually felt very intuitive so I decided to open this PR.


newWaypointCoord = coordinate
editingWaypoint = WaypointEntity(context: context)
Expand Down Expand Up @@ -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
)
)
})
}
}
2 changes: 1 addition & 1 deletion Widgets/WidgetsLiveActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct WidgetsLiveActivity: Widget {
}
}


struct WidgetsLiveActivity_Previews: PreviewProvider {
static let attributes = MeshActivityAttributes(nodeNum: 123456789, name: "RAK Compact Rotary Handset Gray 8E6G")
static let state = MeshActivityAttributes.ContentState(uptimeSeconds: 600, channelUtilization: 1.2, airtime: 3.5, sentPackets: 12587, receivedPackets: 12555, badReceivedPackets: 800, nodesOnline: 99, totalNodes: 100, timerRange: Date.now...Date(timeIntervalSinceNow: 300))
Expand All @@ -139,7 +140,6 @@ struct WidgetsLiveActivity_Previews: PreviewProvider {
.previewDisplayName("Notification")
}
}

struct LiveActivityView: View {
@Environment(\.colorScheme) private var colorScheme
@Environment(\.isLuminanceReduced) var isLuminanceReduced
Expand Down
10 changes: 5 additions & 5 deletions scripts/lint/lint-fix-changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--path was removed in a recent versions of swiftlint. This should be compatible with older versions of swiftlint since it's been deprecated for at least 2 years before that.

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
Expand All @@ -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
fi