Skip to content

Commit

Permalink
Track course over ground rather than heading (experiment)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Nov 10, 2023
1 parent e76cbeb commit ba9ac84
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apple/Sources/FerrostarCore/FerrostarCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ extension FerrostarCore: LocationManagingDelegate {
switch (update) {
case .navigating(snappedUserLocation: let userLocation, remainingWaypoints: let remainingWaypoints, currentStep: let currentStep, distanceToNextManeuver: let distanceToNextManeuver):
observableState?.snappedLocation = CLLocation(userLocation: userLocation)
observableState?.courseOverGround = location.course
observableState?.remainingWaypoints = remainingWaypoints.map { waypoint in
CLLocationCoordinate2D(geographicCoordinates: waypoint)
}
Expand All @@ -161,6 +162,7 @@ extension FerrostarCore: LocationManagingDelegate {
// TODO: "You have arrived"?
observableState?.visualInstructions = nil
observableState?.snappedLocation = location // We arrived; no more snapping needed
observableState?.courseOverGround = location.course
observableState?.spokenInstruction = nil
}
delegate?.core(self, didUpdateNavigationState: NavigationStateUpdate(update))
Expand Down
2 changes: 2 additions & 0 deletions apple/Sources/FerrostarCore/ObservableState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UniFFI
public final class FerrostarObservableState {
public internal(set) var snappedLocation: CLLocation
public internal(set) var heading: CLHeading?
public internal(set) var courseOverGround: CLLocationDirection?
public internal(set) var fullRouteShape: [CLLocationCoordinate2D]
public internal(set) var remainingWaypoints: [CLLocationCoordinate2D]
public internal(set) var currentStep: UniFFI.RouteStep
Expand All @@ -20,6 +21,7 @@ public final class FerrostarObservableState {
init(snappedLocation: CLLocation, heading: CLHeading? = nil, fullRoute: [CLLocationCoordinate2D], steps: [RouteStep]) {
self.snappedLocation = snappedLocation
self.heading = heading
self.courseOverGround = snappedLocation.course
self.fullRouteShape = fullRoute
self.remainingWaypoints = fullRoute
self.currentStep = steps.first!
Expand Down
6 changes: 5 additions & 1 deletion apple/Sources/FerrostarMapLibreUI/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import MapLibreSwiftUI
public struct NavigationMapView: View {
let lightStyleURL: URL
let darkStyleURL: URL
// TODO: Configurable camera and user "puck" rotation modes

var navigationState: FerrostarObservableState

Expand All @@ -17,6 +18,9 @@ public struct NavigationMapView: View {
return false
}

/// Creates a new instance of the default navigation map.
///
/// `lightStyleURL` and `darkStyleURL` are yet to be implemented.
public init(
lightStyleURL: URL,
darkStyleURL: URL,
Expand Down Expand Up @@ -80,7 +84,7 @@ public struct NavigationMapView: View {

SymbolStyleLayer(identifier: "user-location", source: userLocationSource)
.iconImage(constant: UIImage(systemName: "location.north.circle.fill")!)
.iconRotation(constant: navigationState.heading?.trueHeading.magnitude ?? 0)
.iconRotation(constant: navigationState.courseOverGround?.magnitude ?? 0)
}
.edgesIgnoringSafeArea(.all)
.overlay(alignment: .top, content: {
Expand Down
2 changes: 2 additions & 0 deletions apple/Tests/FerrostarCoreTests/FerrostarCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ let errorBody = Data("""
""".utf8)
let errorResponse = HTTPURLResponse(url: backendUrl, statusCode: 401, httpVersion: "HTTP/1.1", headerFields: ["Content-Type": "application/json"])!

// NOTE: you can also implement RouteAdapterProtocol directly.

private class MockRouteRequestGenerator: RouteRequestGenerator {
func generateRequest(userLocation: UniFFI.UserLocation, waypoints: [UniFFI.GeographicCoordinates]) throws -> UniFFI.RouteRequest {
return UniFFI.RouteRequest.httpPost(url: backendUrl.absoluteString, headers: [:], body: Data())
Expand Down
4 changes: 2 additions & 2 deletions common/ferrostar/src/routing_adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum RouteRequest {
/// Implementations may be either in Rust (most popular engines should eventually have Rust
/// implementations) or foreign code.
#[uniffi::export]
pub trait RouteRequestGenerator: Send + Sync + Debug {
pub trait RouteRequestGenerator: Send + Sync {
/// Generates a routing backend request given the set of locations.
///
/// While most implementations will treat the locations as an ordered sequence, this is not
Expand All @@ -51,7 +51,7 @@ pub trait RouteRequestGenerator: Send + Sync + Debug {
/// A generic interface describing any object capable of parsing a response from a routing
/// backend into one or more [Route]s.
#[uniffi::export]
pub trait RouteResponseParser: Send + Sync + Debug {
pub trait RouteResponseParser: Send + Sync {
/// Parses a raw response from the routing backend into a route.
///
/// We use a sequence of octets as a common interchange format.
Expand Down

0 comments on commit ba9ac84

Please sign in to comment.