-
Notifications
You must be signed in to change notification settings - Fork 318
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
Annotate intersecting roads and maneuver points along the current route #2928
Open
avi-c
wants to merge
3
commits into
main
Choose a base branch
from
ac-IntersectionAnnotationFeature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+680
−0
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add visible annotations to the map at intersecting roads along the ac…
…tive route as well as at maneuver points.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import UIKit | ||
import Turf | ||
import MapboxDirections | ||
import MapboxCoreNavigation | ||
import MapboxNavigation | ||
import MapboxCoreMaps | ||
import MapboxMaps | ||
|
||
// MARK: - Visible annotations on the map about the current drive | ||
|
||
extension NavigationMapView { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import MapboxCoreNavigation | ||
|
||
extension RoadGraph.Edge { | ||
var mpp: [RoadGraph.Edge]? { | ||
|
||
guard level == 0 else { return nil } | ||
|
||
var mostProbablePath = [self] | ||
|
||
for child in outletEdges { | ||
if let childMPP = child.mpp { | ||
mostProbablePath.append(contentsOf: childMPP) | ||
} | ||
} | ||
|
||
return mostProbablePath | ||
} | ||
|
||
func edgeNames(roadGraph: RoadGraph) -> [String] { | ||
guard let metadata = roadGraph.edgeMetadata(edgeIdentifier: identifier) else { | ||
return [] | ||
} | ||
let names = metadata.names.map { name -> String in | ||
switch name { | ||
case .name(let name): | ||
return name | ||
case .code(let code): | ||
return "(\(code))" | ||
} | ||
} | ||
|
||
// If the road is unnamed, fall back to the road class. | ||
if names.isEmpty { | ||
return ["\(metadata.mapboxStreetsRoadClass.rawValue)"] | ||
} | ||
return names | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
Sources/MapboxNavigation/NavigationMapView+IntersectionAnnotations.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import CoreLocation | ||
import UIKit | ||
import MapboxDirections | ||
import MapboxCoreNavigation | ||
import Turf | ||
import MapboxMaps | ||
|
||
extension NavigationMapView { | ||
|
||
struct EdgeIntersection { | ||
var root: RoadGraph.Edge | ||
var branch: RoadGraph.Edge | ||
var rootMetadata: RoadGraph.Edge.Metadata | ||
var rootShape: LineString | ||
var branchMetadata: RoadGraph.Edge.Metadata | ||
var branchShape: LineString | ||
|
||
var coordinate: CLLocationCoordinate2D? { | ||
rootShape.coordinates.first | ||
} | ||
|
||
var annotationPoint: CLLocationCoordinate2D? { | ||
guard let length = branchShape.distance() else { return nil } | ||
let targetDistance = min(length / 2, Double.random(in: 15...30)) | ||
guard let annotationPoint = branchShape.coordinateFromStart(distance: targetDistance) else { return nil } | ||
return annotationPoint | ||
} | ||
|
||
var wayName: String? { | ||
guard let roadName = rootMetadata.names.first else { return nil } | ||
|
||
switch roadName { | ||
case .name(let name): | ||
return name | ||
case .code(let code): | ||
return "(\(code))" | ||
} | ||
} | ||
var intersectingWayName: String? { | ||
guard let roadName = branchMetadata.names.first else { return nil } | ||
|
||
switch roadName { | ||
case .name(let name): | ||
return name | ||
case .code(let code): | ||
return "(\(code))" | ||
} | ||
} | ||
|
||
var incidentAngle: CLLocationDegrees { | ||
return (branchMetadata.heading - rootMetadata.heading).wrap(min: 0, max: 360) | ||
} | ||
|
||
var description: String { | ||
return "EdgeIntersection: root: \(wayName ?? "") intersection: \(intersectingWayName ?? "") coordinate: \(String(describing: coordinate))" | ||
} | ||
} | ||
|
||
enum AnnotationTailPosition: Int { | ||
case left | ||
case right | ||
case center | ||
} | ||
|
||
class AnnotationCacheEntry: Equatable, Hashable { | ||
var wayname: String | ||
var coordinate: CLLocationCoordinate2D | ||
var intersection: EdgeIntersection? | ||
var feature: Feature | ||
var lastAccessTime: Date | ||
|
||
init(coordinate: CLLocationCoordinate2D, wayname: String, intersection: EdgeIntersection? = nil, feature: Feature) { | ||
self.wayname = wayname | ||
self.coordinate = coordinate | ||
self.intersection = intersection | ||
self.feature = feature | ||
self.lastAccessTime = Date() | ||
} | ||
|
||
static func == (lhs: AnnotationCacheEntry, rhs: AnnotationCacheEntry) -> Bool { | ||
return lhs.wayname == rhs.wayname | ||
} | ||
|
||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(wayname.hashValue) | ||
} | ||
} | ||
|
||
class AnnotationCache { | ||
private let maxEntryAge = TimeInterval(30) | ||
var entries = Set<AnnotationCacheEntry>() | ||
var cachePruningTimer: Timer? | ||
|
||
init() { | ||
// periodically prune the cache to remove entries that have been passed already | ||
cachePruningTimer = Timer.scheduledTimer(withTimeInterval: 15, repeats: true, block: { [weak self] _ in | ||
self?.prune() | ||
}) | ||
} | ||
|
||
deinit { | ||
cachePruningTimer?.invalidate() | ||
cachePruningTimer = nil | ||
} | ||
|
||
func setValue(feature: Feature, coordinate: CLLocationCoordinate2D, intersection: EdgeIntersection?, for wayname: String) { | ||
entries.insert(AnnotationCacheEntry(coordinate: coordinate, wayname: wayname, intersection: intersection, feature: feature)) | ||
} | ||
|
||
func value(for wayname: String) -> AnnotationCacheEntry? { | ||
let matchingEntry = entries.first { entry -> Bool in | ||
entry.wayname == wayname | ||
} | ||
|
||
if let matchingEntry = matchingEntry { | ||
// update the timestamp used for pruning the cache | ||
matchingEntry.lastAccessTime = Date() | ||
} | ||
|
||
return matchingEntry | ||
} | ||
|
||
private func prune() { | ||
let now = Date() | ||
|
||
entries.filter { now.timeIntervalSince($0.lastAccessTime) > maxEntryAge }.forEach { remove($0) } | ||
} | ||
|
||
public func remove(_ entry: AnnotationCacheEntry) { | ||
entries.remove(entry) | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+4.74 KB
...on/Resources/Assets.xcassets/AnnotationCentered.imageset/AnnotationCentered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
Sources/MapboxNavigation/Resources/Assets.xcassets/AnnotationCentered.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "AnnotationCentered.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...es/MapboxNavigation/Resources/Assets.xcassets/AnnotationLeftHanded.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "RouteInfoAnnotationLeftHanded.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+2.33 KB
...Assets.xcassets/AnnotationLeftHanded.imageset/RouteInfoAnnotationLeftHanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
...s/MapboxNavigation/Resources/Assets.xcassets/AnnotationRightHanded.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "RouteInfoAnnotationRightHanded.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+2.41 KB
...sets.xcassets/AnnotationRightHanded.imageset/RouteInfoAnnotationRightHanded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assets should be stored as scalable PDFs. #2734/#2873 introduced more stylish RouteInfoAnnotationLeftHanded and RouteInfoAnnotationRightHanded assets, but there’s no corresponding RouteInfoAnnotationCentered asset.