Skip to content

Commit 7f3363b

Browse files
committed
Add visible annotations to the map at intersecting roads along the active route as well as at maneuver points.
1 parent c28e1e7 commit 7f3363b

File tree

18 files changed

+728
-6
lines changed

18 files changed

+728
-6
lines changed

Example/ViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ class ViewController: UIViewController {
453453
func present(_ navigationViewController: NavigationViewController, completion: CompletionHandler? = nil) {
454454
navigationViewController.modalPresentationStyle = .fullScreen
455455
activeNavigationViewController = navigationViewController
456+
activeNavigationViewController?.navigationMapView?.showIntersectionAnnotations = true
456457

457458
present(navigationViewController, animated: true) {
458459
completion?()
@@ -467,6 +468,7 @@ class ViewController: UIViewController {
467468

468469
func dismissActiveNavigationViewController() {
469470
activeNavigationViewController?.dismiss(animated: true) {
471+
self.activeNavigationViewController?.navigationMapView?.showIntersectionAnnotations = false
470472
self.activeNavigationViewController = nil
471473
}
472474
}

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@
395395
DAD903AF23E3DCC80057CF1F /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD903AE23E3DCC80057CF1F /* DateTests.swift */; };
396396
DADD82802161EC0300B8B47D /* UIViewAnimationOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DADD827F2161EC0300B8B47D /* UIViewAnimationOptionsTests.swift */; };
397397
DAFA92071F01735000A7FB09 /* DistanceFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351BEC0B1E5BCC72006FE110 /* DistanceFormatter.swift */; };
398+
F43EE329261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift in Sources */ = {isa = PBXBuildFile; fileRef = F43EE328261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift */; };
399+
F43EE32A261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift in Sources */ = {isa = PBXBuildFile; fileRef = F43EE328261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift */; };
398400
F4BF512E24EAD7A50066A49B /* FeedbackSubtypeCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4BF512D24EAD7A50066A49B /* FeedbackSubtypeCollectionViewCell.swift */; };
399401
F4C5A26F24EF1D16004ED0DD /* FeedbackSubtypeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4C5A26E24EF1D16004ED0DD /* FeedbackSubtypeViewController.swift */; };
400402
/* End PBXBuildFile section */
@@ -1021,6 +1023,7 @@
10211023
DAFEB36D2093A11F00A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
10221024
DAFEB36E2093A3E000A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
10231025
DAFEB36F2093A3EF00A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ko; path = Resources/ko.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
1026+
F43EE328261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NavigationMapView+RoadAnnotations.swift"; sourceTree = "<group>"; };
10241027
F4BF512D24EAD7A50066A49B /* FeedbackSubtypeCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackSubtypeCollectionViewCell.swift; sourceTree = "<group>"; };
10251028
F4C5A26E24EF1D16004ED0DD /* FeedbackSubtypeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackSubtypeViewController.swift; sourceTree = "<group>"; };
10261029
/* End PBXFileReference section */
@@ -1352,6 +1355,7 @@
13521355
35002D721E5F6C830090E733 /* Supporting files */,
13531356
AED6285522CBE4CE00058A51 /* ViewController+GuidanceCards.swift */,
13541357
8A092F9A25DEE81900CA7CF5 /* ViewController+FreeDrive.swift */,
1358+
F43EE328261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift */,
13551359
3577B877214FF35800094294 /* FavoritesList.swift */,
13561360
358D14651E5E3B7700ADE590 /* AppDelegate.swift */,
13571361
35379CFB21480BFB00FD402E /* AppDelegate+CarPlay.swift */,
@@ -2600,6 +2604,7 @@
26002604
buildActionMask = 2147483647;
26012605
files = (
26022606
358D14681E5E3B7700ADE590 /* ViewController.swift in Sources */,
2607+
F43EE329261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift in Sources */,
26032608
C5D9800D1EFA8BA9006DBF2E /* CustomViewController.swift in Sources */,
26042609
AED6285622CBE4CE00058A51 /* ViewController+GuidanceCards.swift in Sources */,
26052610
8A092F9B25DEE81900CA7CF5 /* ViewController+FreeDrive.swift in Sources */,
@@ -2705,6 +2710,7 @@
27052710
C53F2EE720EBC95600D9798F /* WaypointConfirmationViewController.swift in Sources */,
27062711
C5DE4B6220F6B6B3007AFBE6 /* CustomStyles.swift in Sources */,
27072712
8A0D5DB725DF2A86006F0919 /* StyledFeature.swift in Sources */,
2713+
F43EE32A261F98DC0039D56F /* NavigationMapView+RoadAnnotations.swift in Sources */,
27082714
DA8805002316EAED00B54D87 /* ViewController+GuidanceCards.swift in Sources */,
27092715
8A092F9C25DEE81900CA7CF5 /* ViewController+FreeDrive.swift in Sources */,
27102716
35379CFD21480C0500FD402E /* AppDelegate+CarPlay.swift in Sources */,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import UIKit
2+
import Turf
3+
import MapboxDirections
4+
import MapboxCoreNavigation
5+
import MapboxNavigation
6+
import MapboxCoreMaps
7+
import MapboxMaps
8+
9+
// MARK: - Visible annotations on the map about the current drive
10+
11+
extension NavigationMapView {
12+
}

Sources/MapboxCoreNavigation/CoreConstants.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ extension ElectronicHorizon {
363363
/**
364364
A key in the user info dictionary of a `Notification.Name.electronicHorizonDidEnterRoadObject` or `Notification.Name.electronicHorizonDidExitRoadObject` notification. The corresponding value is a `RoadObjectIdentifier` identifying the road object that the user entered or exited. */
365365
public static let roadObjectIdentifierKey: NotificationUserInfoKey = .init(rawValue: "roadObjectIdentifier")
366+
367+
public static let roadGraphIdentifierKey: NotificationUserInfoKey = .init(rawValue: "roadGraph")
366368

367369
/**
368370
A key in the user info dictionary of a `Notification.Name.electronicHorizonDidEnterRoadObject` or `Notification.Name.electronicHorizonDidExitRoadObject` notification. The corresponding value is an `NSNumber` containing a Boolean value set to `true` if the user entered at the beginning or exited at the end of the road object, or `false` if they entered or exited somewhere along the road object. */

Sources/MapboxCoreNavigation/CoreNavigationNavigator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,15 @@ class Navigator {
128128

129129
extension Navigator: ElectronicHorizonObserver {
130130
public func onPositionUpdated(for position: ElectronicHorizonPosition, distances: [String : MapboxNavigationNative.RoadObjectDistanceInfo]) {
131-
let userInfo: [ElectronicHorizon.NotificationUserInfoKey: Any] = [
131+
var userInfo: [ElectronicHorizon.NotificationUserInfoKey: Any] = [
132132
.positionKey: RoadGraph.Position(try! position.position()),
133133
.treeKey: ElectronicHorizon(try! position.tree()),
134134
.updatesMostProbablePathKey: try! position.type() == .UPDATE,
135135
.distancesByRoadObjectKey: distances.mapValues(RoadObjectDistanceInfo.init),
136136
]
137+
if let roadGraph = roadGraph {
138+
userInfo.updateValue(roadGraph, forKey: .roadGraphIdentifierKey)
139+
}
137140
NotificationCenter.default.post(name: .electronicHorizonDidUpdatePosition, object: nil, userInfo: userInfo)
138141
}
139142

Sources/MapboxCoreNavigation/NavigationService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public class MapboxNavigationService: NSObject, NavigationService {
249249
let routerType = routerType ?? DefaultRouter.self
250250
router = routerType.init(along: route, routeIndex: routeIndex, options: routeOptions, directions: self.directions, dataSource: self)
251251
NavigationSettings.shared.distanceUnit = routeOptions.locale.usesMetric ? .kilometer : .mile
252-
252+
253253
let eventType = eventsManagerType ?? NavigationEventsManager.self
254254
eventsManager = eventType.init(dataSource: self, accessToken: self.directions.credentials.accessToken)
255255
locationManager.activityType = routeOptions.activityType

Sources/MapboxNavigation/DayStyle.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extension UIColor {
3636
class var alternativeTrafficSevere: UIColor { get { return #colorLiteral(red: 0.71, green: 0.51, blue: 0.51, alpha: 1.0) } }
3737
class var defaultBuildingColor: UIColor { get { return #colorLiteral(red: 0.9833194452, green: 0.9843137255, blue: 0.9331936657, alpha: 0.8019049658) } }
3838
class var defaultBuildingHighlightColor: UIColor { get { return #colorLiteral(red: 0.337254902, green: 0.6588235294, blue: 0.9843137255, alpha: 0.949406036) } }
39+
class var intersectionAnnotationDefaultBackgroundColor: UIColor { get { return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) } }
40+
class var intersectionAnnotationSelectedBackgroundColor: UIColor { get { return #colorLiteral(red: 0.337254902, green: 0.6588235294, blue: 0.9843137255, alpha: 1) } }
41+
class var intersectionAnnotationDefaultLabelColor: UIColor { get { return #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) } }
42+
class var intersectionAnnotationSelectedLabelColor: UIColor { get { return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) } }
3943
}
4044

4145
extension UIColor {

Sources/MapboxNavigation/NavigationMapView+BuildingHighlighting.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,16 @@ extension NavigationMapView {
101101
highlightedBuildingsLayer.paint?.fillExtrusionColor = .constant(.init(color: buildingHighlightColor))
102102
highlightedBuildingsLayer.paint?.fillExtrusionHeightTransition = StyleTransition(duration: 0.8, delay: 0)
103103
highlightedBuildingsLayer.paint?.fillExtrusionOpacityTransition = StyleTransition(duration: 0.8, delay: 0)
104+
105+
#if false
106+
if let _ = try? mapView.style.getSource(identifier: NavigationMapView.intersectionAnnotations, type: GeoJSONSource.self).get() {
107+
mapView.style.addLayer(layer: highlightedBuildingsLayer, layerPosition: LayerPosition(above: nil, below: IdentifierString.intersectionAnnotationsLayer, at: nil))
108+
} else {
109+
mapView.style.addLayer(layer: highlightedBuildingsLayer)
110+
}
111+
#else
104112
mapView.style.addLayer(layer: highlightedBuildingsLayer)
113+
#endif
105114
}
106115

107116
}

0 commit comments

Comments
 (0)