Skip to content

Commit

Permalink
Merge pull request #2949 from mapbox/azarovalex/electronic-horizon-edge
Browse files Browse the repository at this point in the history
Remove `ElectronicHorizon` struct
  • Loading branch information
azarovalex authored Apr 28, 2021
2 parents 477eea6 + 7ac85dc commit 9987b46
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 65 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* Added the `Directions.calculateOffline(options:completionHandler:)` and `Directions.calculateWithCache(options:completionHandler:)` methods, which incorporate routing tiles from the predictive cache when possible to avoid relying on a network connection to calculate the route. `RouteController` now also uses the predictive cache when rerouting. ([#2848](https://github.com/mapbox/mapbox-navigation-ios/pull/2848))
* Fixed an issue where `PassiveLocationDataSource` and `RouteController` did not use the access token and host specified by `PassiveLocationDataSource.directions` and `RouteController.directions`, respectively. Added the `PredictiveCacheOptions.credentials` property for specifying the access token and host used for prefetching resources. ([#2876](https://github.com/mapbox/mapbox-navigation-ios/pull/2876))
* The top banner can now show a wider variety of turn lane configurations, such as combination U-turn/left turn lanes and combination through/slight right turn lanes. ([#2882](https://github.com/mapbox/mapbox-navigation-ios/pull/2882))
* Removed `ElectronicHorizon` struct, now an electronic horizon notification directly contain pointer to a starting edge. `ElectronicHorizon.Edge` was renamed to `RoadGraph.Edge`. `ElectronicHorizon.NotificationUserInfoKey` was renamed to `RoadGraph.NotificationUserInfoKey`.

## v1.3.0

Expand Down
14 changes: 7 additions & 7 deletions Example/ViewController+FreeDrive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ extension ViewController {
}

@objc func didUpdateElectronicHorizonPosition(_ notification: Notification) {
guard let horizon = notification.userInfo?[ElectronicHorizon.NotificationUserInfoKey.treeKey] as? ElectronicHorizon else {
guard let startingEdge = notification.userInfo?[RoadGraph.NotificationUserInfoKey.treeKey] as? RoadGraph.Edge else {
return
}

// Avoid repeating edges that have already been printed out.
guard currentEdgeIdentifier != horizon.start.identifier ||
nextEdgeIdentifier != horizon.start.outletEdges.first?.identifier else {
guard currentEdgeIdentifier != startingEdge.identifier ||
nextEdgeIdentifier != startingEdge.outletEdges.first?.identifier else {
return
}
currentEdgeIdentifier = horizon.start.identifier
nextEdgeIdentifier = horizon.start.outletEdges.first?.identifier
currentEdgeIdentifier = startingEdge.identifier
nextEdgeIdentifier = startingEdge.outletEdges.first?.identifier
guard let currentEdgeIdentifier = currentEdgeIdentifier,
let nextEdgeIdentifier = nextEdgeIdentifier else {
return
Expand All @@ -117,14 +117,14 @@ extension ViewController {
var statusString = "Currently on \(edgeNames(identifier: currentEdgeIdentifier).joined(separator: " / ")), approaching \(edgeNames(identifier: nextEdgeIdentifier).joined(separator: " / "))"

// If there is an upcoming intersection, include the names of the cross streets.
let branchEdgeIdentifiers = horizon.start.outletEdges.suffix(from: 1).map({ $0.identifier })
let branchEdgeIdentifiers = startingEdge.outletEdges.suffix(from: 1).map({ $0.identifier })
if !branchEdgeIdentifiers.isEmpty {
let branchNames = branchEdgeIdentifiers.flatMap { edgeNames(identifier: $0) }
statusString += " at \(branchNames.joined(separator: ", "))"
}
}

func edgeNames(identifier: ElectronicHorizon.Edge.Identifier) -> [String] {
func edgeNames(identifier: RoadGraph.Edge.Identifier) -> [String] {
let passiveLocationDataSource = (navigationMapView.mapView.location.locationProvider as! PassiveLocationManager).dataSource
guard let metadata = passiveLocationDataSource.roadGraph.edgeMetadata(edgeIdentifier: identifier) else {
return []
Expand Down
4 changes: 2 additions & 2 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ViewController: UIViewController {
var rawTrackStyledFeature: StyledFeature!
var speedLimitView: SpeedLimitView!

var currentEdgeIdentifier: ElectronicHorizon.Edge.Identifier?
var nextEdgeIdentifier: ElectronicHorizon.Edge.Identifier?
var currentEdgeIdentifier: RoadGraph.Edge.Identifier?
var nextEdgeIdentifier: RoadGraph.Edge.Identifier?

typealias RouteRequestSuccess = ((RouteResponse) -> Void)
typealias RouteRequestFailure = ((Error) -> Void)
Expand Down
20 changes: 8 additions & 12 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,11 @@
DA303CA621B7A90100F921DC /* UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3529FCF521A5C5D900AEA9AA /* UIViewController.swift */; };
DA3525702010A5210048DDFC /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = DA35256E2010A5200048DDFC /* Localizable.stringsdict */; };
DA443DDE2278C90E00ED1307 /* CPTrip.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA443DDD2278C90E00ED1307 /* CPTrip.swift */; };
DA5F449A25F07A5C00F573EC /* ElectronicHorizon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F449925F07A5C00F573EC /* ElectronicHorizon.swift */; };
DA5F44AA25F07A6800F573EC /* RoadObjectType.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44A325F07A6500F573EC /* RoadObjectType.swift */; };
DA5F44AC25F07A6800F573EC /* RoadGraphPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44A525F07A6500F573EC /* RoadGraphPosition.swift */; };
DA5F44AE25F07A6800F573EC /* RoadObjectDistanceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44A725F07A6500F573EC /* RoadObjectDistanceInfo.swift */; };
DA5F44B025F07A6800F573EC /* ElectronicHorizonEdge.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44A925F07A6700F573EC /* ElectronicHorizonEdge.swift */; };
DA5F44BA25F07AA500F573EC /* ElectronicHorizonEdgeMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44B925F07AA500F573EC /* ElectronicHorizonEdgeMetadata.swift */; };
DA5F44B025F07A6800F573EC /* RoadGraphEdge.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44A925F07A6700F573EC /* RoadGraphEdge.swift */; };
DA5F44BA25F07AA500F573EC /* RoadGraphEdgeMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44B925F07AA500F573EC /* RoadGraphEdgeMetadata.swift */; };
DA5F44C625F07AB700F573EC /* RoadGraph.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44C325F07AB500F573EC /* RoadGraph.swift */; };
DA5F44C725F07AB700F573EC /* RoadName.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44C425F07AB500F573EC /* RoadName.swift */; };
DA5F44C825F07AB700F573EC /* MapboxStreetsRoadClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA5F44C525F07AB600F573EC /* MapboxStreetsRoadClass.swift */; };
Expand Down Expand Up @@ -950,12 +949,11 @@
DA545AC41FAA86450090908E /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
DA5AD03C1FEBA03700FC7D7B /* bg */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = bg; path = bg.lproj/Main.strings; sourceTree = "<group>"; };
DA5AD0401FEBA23200FC7D7B /* bg */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = bg; path = bg.lproj/Localizable.strings; sourceTree = "<group>"; };
DA5F449925F07A5C00F573EC /* ElectronicHorizon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElectronicHorizon.swift; sourceTree = "<group>"; };
DA5F44A325F07A6500F573EC /* RoadObjectType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoadObjectType.swift; sourceTree = "<group>"; };
DA5F44A525F07A6500F573EC /* RoadGraphPosition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoadGraphPosition.swift; sourceTree = "<group>"; };
DA5F44A725F07A6500F573EC /* RoadObjectDistanceInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoadObjectDistanceInfo.swift; sourceTree = "<group>"; };
DA5F44A925F07A6700F573EC /* ElectronicHorizonEdge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElectronicHorizonEdge.swift; sourceTree = "<group>"; };
DA5F44B925F07AA500F573EC /* ElectronicHorizonEdgeMetadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElectronicHorizonEdgeMetadata.swift; sourceTree = "<group>"; };
DA5F44A925F07A6700F573EC /* RoadGraphEdge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoadGraphEdge.swift; sourceTree = "<group>"; };
DA5F44B925F07AA500F573EC /* RoadGraphEdgeMetadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoadGraphEdgeMetadata.swift; sourceTree = "<group>"; };
DA5F44C325F07AB500F573EC /* RoadGraph.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoadGraph.swift; sourceTree = "<group>"; };
DA5F44C425F07AB500F573EC /* RoadName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoadName.swift; sourceTree = "<group>"; };
DA5F44C525F07AB600F573EC /* MapboxStreetsRoadClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapboxStreetsRoadClass.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1865,11 +1863,10 @@
DA5F446325F0744C00F573EC /* EHorizon */ = {
isa = PBXGroup;
children = (
DA5F449925F07A5C00F573EC /* ElectronicHorizon.swift */,
DA5F44A925F07A6700F573EC /* ElectronicHorizonEdge.swift */,
DA5F44B925F07AA500F573EC /* ElectronicHorizonEdgeMetadata.swift */,
DA5F44FF25F07DE200F573EC /* ElectronicHorizonOptions.swift */,
DA5F44C325F07AB500F573EC /* RoadGraph.swift */,
DA5F44A925F07A6700F573EC /* RoadGraphEdge.swift */,
DA5F44B925F07AA500F573EC /* RoadGraphEdgeMetadata.swift */,
DA2A01EF25F308B100AAB4C6 /* RoadGraphPath.swift */,
DA5F44A525F07A6500F573EC /* RoadGraphPosition.swift */,
DA5F44C425F07AB500F573EC /* RoadName.swift */,
Expand Down Expand Up @@ -2776,14 +2773,13 @@
DA754E1923AC56E5007E16B5 /* MBXAccountsLoader.m in Sources */,
2BE701252535943900F46E4E /* BorderCrossing.swift in Sources */,
3582A25020EEC46B0029C5DE /* Router.swift in Sources */,
DA5F449A25F07A5C00F573EC /* ElectronicHorizon.swift in Sources */,
8D75F991212B5C7F00F99CF3 /* TunnelAuthority.swift in Sources */,
C5E7A31C1F4F6828001CB015 /* NavigationRouteOptions.swift in Sources */,
352F464D20EB74C200147886 /* NavigationEventsManager.swift in Sources */,
351174F41EF1C0530065E248 /* ReplayLocationManager.swift in Sources */,
2BE701172535940D00F46E4E /* Tunnel.swift in Sources */,
8A3A219025EEC00200EDA999 /* CoreNavigationNavigator.swift in Sources */,
DA5F44BA25F07AA500F573EC /* ElectronicHorizonEdgeMetadata.swift in Sources */,
DA5F44BA25F07AA500F573EC /* RoadGraphEdgeMetadata.swift in Sources */,
DA5F44E825F07D2800F573EC /* RoadObjectLocation.swift in Sources */,
DABA591525E58D5600D0C1DB /* Accounts.swift in Sources */,
C5C94C1C1DDCD2340097296A /* LegacyRouteController.swift in Sources */,
Expand Down Expand Up @@ -2828,7 +2824,7 @@
DA5F44C825F07AB700F573EC /* MapboxStreetsRoadClass.swift in Sources */,
C51DF8661F38C31C006C6A15 /* Locale.swift in Sources */,
DA5F44F625F07D3B00F573EC /* RoadObjectsStore.swift in Sources */,
DA5F44B025F07A6800F573EC /* ElectronicHorizonEdge.swift in Sources */,
DA5F44B025F07A6800F573EC /* RoadGraphEdge.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 7 additions & 6 deletions Sources/MapboxCoreNavigation/CoreConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,28 +308,28 @@ public extension Notification.Name {
/**
Posted when the user’s position in the electronic horizon changes. This notification may be posted multiple times after `electronicHorizonDidEnterRoadObject` until the user transitions to a new electronic horizon.
The user info dictionary contains the keys `ElectronicHorizon.NotificationUserInfoKey.positionKey`, `ElectronicHorizon.NotificationUserInfoKey.treeKey`, `ElectronicHorizon.NotificationUserInfoKey.updatesMostProbablePathKey`, and `ElectronicHorizon.NotificationUserInfoKey.distancesByRoadObjectKey`.
The user info dictionary contains the keys `RoadGraph.NotificationUserInfoKey.positionKey`, `RoadGraph.NotificationUserInfoKey.treeKey`, `RoadGraph.NotificationUserInfoKey.updatesMostProbablePathKey`, and `RoadGraph.NotificationUserInfoKey.distancesByRoadObjectKey`.
*/
static let electronicHorizonDidUpdatePosition: Notification.Name = .init(rawValue: "ElectronicHorizonDidUpdatePosition")

/**
Posted when the user enters a linear road object.
The user info dictionary contains the keys `ElectronicHorizon.NotificationUserInfoKey.roadObjectIdentifierKey` and `ElectronicHorizon.NotificationUserInfoKey.didTransitionAtEndpointKey`.
The user info dictionary contains the keys `RoadGraph.NotificationUserInfoKey.roadObjectIdentifierKey` and `RoadGraph.NotificationUserInfoKey.didTransitionAtEndpointKey`.
*/
static let electronicHorizonDidEnterRoadObject: Notification.Name = .init(rawValue: "ElectronicHorizonDidEnterRoadObject")

/**
Posted when the user exits a linear road object.
The user info dictionary contains the keys `ElectronicHorizon.NotificationUserInfoKey.roadObjectIdentifierKey` and `ElectronicHorizon.NotificationUserInfoKey.transitionKey`.
The user info dictionary contains the keys `RoadGraph.NotificationUserInfoKey.roadObjectIdentifierKey` and `RoadGraph.NotificationUserInfoKey.transitionKey`.
*/
static let electronicHorizonDidExitRoadObject: Notification.Name = .init(rawValue: "ElectronicHorizonDidExitRoadObject")
}

extension ElectronicHorizon {
extension RoadGraph {
/**
Keys in the user info dictionaries of various notifications posted by instances of `RouteController` or `PassiveLocationDataSource` about `ElectronicHorizon`s.
Keys in the user info dictionaries of various notifications posted by instances of `RouteController` or `PassiveLocationDataSource` about `RoadGraph`s.
*/
public struct NotificationUserInfoKey: Hashable, Equatable, RawRepresentable {
public typealias RawValue = String
Expand All @@ -343,7 +343,8 @@ extension ElectronicHorizon {
public static let positionKey: NotificationUserInfoKey = .init(rawValue: "position")

/**
A key in the user info dictionary of a `Notification.Name.electronicHorizonDidUpdatePosition` notification. The corresponding value is an `ElectronicHorizon` at the root of a tree of edges in the routing graph. */
A key in the user info dictionary of a `Notification.Name.electronicHorizonDidUpdatePosition` notification. The corresponding value is an `RoadGraph.Edge` at the root of a tree of edges in the routing graph. This graph represents a probable path (or paths) of a vehicle within the routing graph for a certain distance in front of the vehicle, thus extending the user’s perspective beyond the “visible” horizon as the vehicle’s position and trajectory change.
*/
public static let treeKey: NotificationUserInfoKey = .init(rawValue: "tree")

/**
Expand Down
8 changes: 4 additions & 4 deletions Sources/MapboxCoreNavigation/CoreNavigationNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,25 @@ class Navigator {

extension Navigator: ElectronicHorizonObserver {
public func onPositionUpdated(for position: ElectronicHorizonPosition, distances: [String : MapboxNavigationNative.RoadObjectDistanceInfo]) {
let userInfo: [ElectronicHorizon.NotificationUserInfoKey: Any] = [
let userInfo: [RoadGraph.NotificationUserInfoKey: Any] = [
.positionKey: RoadGraph.Position(position.position()),
.treeKey: ElectronicHorizon(position.tree()),
.treeKey: try! position.tree(),
.updatesMostProbablePathKey: position.type() == .UPDATE,
.distancesByRoadObjectKey: distances.mapValues(RoadObjectDistanceInfo.init),
]
NotificationCenter.default.post(name: .electronicHorizonDidUpdatePosition, object: nil, userInfo: userInfo)
}

public func onRoadObjectEnter(for info: RoadObjectEnterExitInfo) {
let userInfo: [ElectronicHorizon.NotificationUserInfoKey: Any] = [
let userInfo: [RoadGraph.NotificationUserInfoKey: Any] = [
.roadObjectIdentifierKey: info.roadObjectId,
.didTransitionAtEndpointKey: info.isEnterFromStartOrExitFromEnd,
]
NotificationCenter.default.post(name: .electronicHorizonDidEnterRoadObject, object: nil, userInfo: userInfo)
}

public func onRoadObjectExit(for info: RoadObjectEnterExitInfo) {
let userInfo: [ElectronicHorizon.NotificationUserInfoKey: Any] = [
let userInfo: [RoadGraph.NotificationUserInfoKey: Any] = [
.roadObjectIdentifierKey: info.roadObjectId,
.didTransitionAtEndpointKey: info.isEnterFromStartOrExitFromEnd,
]
Expand Down
19 changes: 0 additions & 19 deletions Sources/MapboxCoreNavigation/EHorizon/ElectronicHorizon.swift

This file was deleted.

8 changes: 4 additions & 4 deletions Sources/MapboxCoreNavigation/EHorizon/RoadGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Turf
import MapboxNavigationNative

/**
`RoadGraph` provides methods to get edge shape (e.g. `ElectronicHorizon.Edge`) and metadata.
`RoadGraph` provides methods to get edge shape (e.g. `RoadGraph.Edge`) and metadata.
You do not create a `RoadGraph` object manually. Instead, observe the `Notification.Name.electronicHorizonDidUpdatePosition` notification to obtain edge identifiers and get more details about the edges using the `RouteController.roadGraph` or `PassiveLocationDataSource.roadGraph` property.
*/
Expand All @@ -14,9 +14,9 @@ public final class RoadGraph {
- returns: Metadata about the edge with the given edge identifier, or `nil` if the edge is inaccessible.
*/
public func edgeMetadata(edgeIdentifier: ElectronicHorizon.Edge.Identifier) -> ElectronicHorizon.Edge.Metadata? {
public func edgeMetadata(edgeIdentifier: Edge.Identifier) -> Edge.Metadata? {
if let edgeMetadata = native.getEdgeMetadata(forEdgeId: UInt64(edgeIdentifier)) {
return ElectronicHorizon.Edge.Metadata(edgeMetadata)
return Edge.Metadata(edgeMetadata)
}
return nil
}
Expand All @@ -26,7 +26,7 @@ public final class RoadGraph {
- returns: A line string corresponding to the given edge identifier, or `nil` if the edge is inaccessible.
*/
public func edgeShape(edgeIdentifier: ElectronicHorizon.Edge.Identifier) -> LineString? {
public func edgeShape(edgeIdentifier: Edge.Identifier) -> LineString? {
guard let locations = native.getEdgeShape(forEdgeId: UInt64(edgeIdentifier)) else {
return nil
}
Expand Down
Loading

0 comments on commit 9987b46

Please sign in to comment.