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

Port Route Duration Annotations feature to Maps SDK v10 map styling API #2873

Merged
merged 12 commits into from
May 11, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* Fixed an issue that the current road name label flashes when camera state changes or travels onto an unnamed road. ([#2958](https://github.com/mapbox/mapbox-navigation-ios/pull/2958))
* Added the `NavigationOptions.tileStoreConfiguration` property and arguments to `PassiveLocationDataSource(directions:systemLocationManager:tileStoreLocation:)`, `NavigationMapView(frame:navigationCameraType:tileStoreLocation:)`, and `PredictiveCacheManager(predictiveCacheOptions:tileStoreMapOptions:)` for customizing the locations where navigation and map tiles are stored. ([#2956](https://github.com/mapbox/mapbox-navigation-ios/pull/2956))
* Fixed an issue where lane guidance icons would sometimes highlight the wrong arrow.([#2942](https://github.com/mapbox/mapbox-navigation-ios/pull/2942))
* The duration annotations added by the `NavigationMapView.showRouteDurations(along:)` method are now set in the fonts you specify using the `NavigationMapView.routeDurationAnnotationFontNames` property. Use this property to specify a list of fallback fonts for better language support. ([#2873](https://github.com/mapbox/mapbox-navigation-ios/pull/2873))

## v1.3.0

Expand Down Expand Up @@ -108,6 +109,9 @@
* `NavigationMapViewDelegate.navigationMapView(_:alternativeRouteCasingStyleLayerWithIdentifier:source:)` to style the casing of alternative route.
* Fixed an issue where the route line periodically peeked out from behind the user puck even though `NavigationViewController.routeLineTracksTraversal` was enabled. ([#2737](https://github.com/mapbox/mapbox-navigation-ios/pull/2737))
* Created the `UserHaloCourseView` similar to `UserCourseView` for approximate location on iOS 14 during the navigation to represent user location. Allow the switch between `UserHaloCourseView` and `UserCourseView` when precise mode is changed. ([#2664](https://github.com/mapbox/mapbox-navigation-ios/pull/2664))
* Added option to show route duration callouts when previewing route alternatives ([#2734](https://github.com/mapbox/mapbox-navigation-ios/pull/2734)):
1ec5 marked this conversation as resolved.
Show resolved Hide resolved
* `NavigationMapView.showRouteDurations(along:)` to show duration annotation callouts on the map for the provided routes.
* `NavigationMapView.removeRouteDurations()` to remove any route duration annotations currently displayed on the map.

### Instruction banners

Expand Down
3 changes: 3 additions & 0 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ViewController: UIViewController {
navigationMapView.showsCongestionForAlternativeRoutes = true
navigationMapView.show(routes)
navigationMapView.showWaypoints(on: currentRoute)
navigationMapView.showRouteDurations(along: routes)
}
}

Expand Down Expand Up @@ -147,7 +148,9 @@ class ViewController: UIViewController {

navigationMapView?.unhighlightBuildings()
navigationMapView?.removeRoutes()
navigationMapView?.removeRouteDurations()
navigationMapView?.removeWaypoints()

waypoints.removeAll()
}

Expand Down
4 changes: 4 additions & 0 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
DAD903AF23E3DCC80057CF1F /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAD903AE23E3DCC80057CF1F /* DateTests.swift */; };
DADD82802161EC0300B8B47D /* UIViewAnimationOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DADD827F2161EC0300B8B47D /* UIViewAnimationOptionsTests.swift */; };
DAFA92071F01735000A7FB09 /* DistanceFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 351BEC0B1E5BCC72006FE110 /* DistanceFormatter.swift */; };
F46FF187260277F7007CC0E0 /* DateComponentsFormatter+NavigationAdditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F46FF186260277F7007CC0E0 /* DateComponentsFormatter+NavigationAdditions.swift */; };
F4BF512E24EAD7A50066A49B /* FeedbackSubtypeCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4BF512D24EAD7A50066A49B /* FeedbackSubtypeCollectionViewCell.swift */; };
F4C5A26F24EF1D16004ED0DD /* FeedbackSubtypeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4C5A26E24EF1D16004ED0DD /* FeedbackSubtypeViewController.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -1042,6 +1043,7 @@
DAFEB36D2093A11F00A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
DAFEB36E2093A3E000A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
DAFEB36F2093A3EF00A86A83 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ko; path = Resources/ko.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
F46FF186260277F7007CC0E0 /* DateComponentsFormatter+NavigationAdditions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DateComponentsFormatter+NavigationAdditions.swift"; sourceTree = "<group>"; };
F4BF512D24EAD7A50066A49B /* FeedbackSubtypeCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackSubtypeCollectionViewCell.swift; sourceTree = "<group>"; };
F4C5A26E24EF1D16004ED0DD /* FeedbackSubtypeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackSubtypeViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -1660,6 +1662,7 @@
C51923B41EA55C5E002AF9E1 /* Extensions */ = {
isa = PBXGroup;
children = (
F46FF186260277F7007CC0E0 /* DateComponentsFormatter+NavigationAdditions.swift */,
8A41F63B25BF631500BD6FCF /* NavigationMapView+BuildingHighlighting.swift */,
8A41F63A25BF631500BD6FCF /* NavigationMapView+VanishingRouteLine.swift */,
C5381F01204E03B600A5493E /* UIDevice.swift */,
Expand Down Expand Up @@ -2566,6 +2569,7 @@
8DE879661FBB9980002F06C0 /* EndOfRouteViewController.swift in Sources */,
AE47A33422B1F6AE0096458C /* InstructionsCardContainerView.swift in Sources */,
8D24A2F62040960C0098CBF8 /* UIEdgeInsets.swift in Sources */,
F46FF187260277F7007CC0E0 /* DateComponentsFormatter+NavigationAdditions.swift in Sources */,
353E3C8F20A3501C00FD1789 /* MapboxMapsStyle.swift in Sources */,
C57491DF1FACC42F006F97BC /* CGPoint.swift in Sources */,
16C2A421211526EE00FE6E68 /* CarPlayManager.swift in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions Sources/MapboxNavigation/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MapboxDirections
import CoreLocation
import Turf
import CoreGraphics
import MapboxDirections

extension Array {
/**
Expand Down Expand Up @@ -143,3 +144,26 @@ extension Array where Iterator.Element == CGPoint {
return []
}
}

extension Array where Element == RouteStep {
// Find the longest contiguous series of RouteSteps connected to the first one.
//
// tolerance: -- Maximum distance between the end of one RouteStep and the start of the next to still consider them connected. Defaults to 100 meters
func continuousShape(tolerance: CLLocationDistance = 100) -> LineString? {
guard count > 0 else { return nil }
guard count > 1 else { return self[0].shape }

let stepShapes = compactMap { $0.shape }
let filteredStepShapes = zip(stepShapes, stepShapes.suffix(from: 1)).filter({
guard let maneuverLocation = $1.coordinates.first else { return false }

return $0.coordinates.last?.distance(to: maneuverLocation) ?? Double.greatestFiniteMagnitude < tolerance
})

let coordinates = filteredStepShapes.flatMap { (firstLine, secondLine) -> [CLLocationCoordinate2D] in
return firstLine.coordinates
}

return LineString(coordinates)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation

extension DateComponentsFormatter {
public static let fullDateComponentsFormatter: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .full
formatter.allowedUnits = [.day, .hour, .minute]
return formatter
}()

public static let shortDateComponentsFormatter: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .short
formatter.allowedUnits = [.day, .hour, .minute]
return formatter
}()

public static let briefDateComponentsFormatter: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .brief
formatter.allowedUnits = [.day, .hour, .minute]
return formatter
}()
}
13 changes: 13 additions & 0 deletions Sources/MapboxNavigation/DayStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ extension UIColor {
class var alternativeTrafficSevere: UIColor { get { return #colorLiteral(red: 0.71, green: 0.51, blue: 0.51, alpha: 1.0) } }
class var defaultBuildingColor: UIColor { get { return #colorLiteral(red: 0.9833194452, green: 0.9843137255, blue: 0.9331936657, alpha: 0.8019049658) } }
class var defaultBuildingHighlightColor: UIColor { get { return #colorLiteral(red: 0.337254902, green: 0.6588235294, blue: 0.9843137255, alpha: 0.949406036) } }

class var routeDurationAnnotationColor: UIColor { get { return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) } }
class var selectedRouteDurationAnnotationColor: UIColor { get { return #colorLiteral(red: 0.337254902, green: 0.6588235294, blue: 0.9843137255, alpha: 1) } }

class var routeDurationAnnotationTextColor: UIColor { get { return #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) } }
class var selectedRouteDurationAnnotationTextColor: UIColor { get { return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) } }

}

extension UIColor {
Expand All @@ -49,6 +56,7 @@ extension UIFont {
// General styling
fileprivate class var defaultPrimaryText: UIFont { get { return UIFont.systemFont(ofSize: 26) } }
fileprivate class var defaultSecondaryText: UIFont { get { return UIFont.systemFont(ofSize: 16) } }
fileprivate class var defaultNavigationSymbolLayerFontNames: [String] { return ["DIN Pro Medium", "Noto Sans CJK JP Medium", "Arial Unicode MS Regular"] }
}

/**
Expand Down Expand Up @@ -165,6 +173,11 @@ open class DayStyle: Style {
NavigationMapView.appearance().alternativeTrafficUnknownColor = .alternativeTrafficUnknown
NavigationMapView.appearance().buildingDefaultColor = .defaultBuildingColor
NavigationMapView.appearance().buildingHighlightColor = .defaultBuildingHighlightColor
NavigationMapView.appearance().routeDurationAnnotationColor = .routeDurationAnnotationColor
NavigationMapView.appearance().routeDurationAnnotationSelectedColor = .selectedRouteDurationAnnotationColor
NavigationMapView.appearance().routeDurationAnnotationFontNames = UIFont.defaultNavigationSymbolLayerFontNames
NavigationMapView.appearance().routeDurationAnnotationTextColor = #colorLiteral(red: 0.09803921569, green: 0.09803921569, blue: 0.09803921569, alpha: 1)
NavigationMapView.appearance().routeDurationAnnotationSelectedTextColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
NavigationView.appearance().backgroundColor = #colorLiteral(red: 0.764706, green: 0.752941, blue: 0.733333, alpha: 1)
NextBannerView.appearance().backgroundColor = #colorLiteral(red: 0.9675388083, green: 0.9675388083, blue: 0.9675388083, alpha: 1)
NextBannerView.appearance(whenContainedInInstancesOf:[InstructionsCardContainerView.self]).backgroundColor = #colorLiteral(red: 0.9675388083, green: 0.9675388083, blue: 0.9675388083, alpha: 1)
Expand Down
Loading