From a66fe96d2b174e8fe01f3648c25fa38bb4caad75 Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Wed, 17 Apr 2019 14:43:15 -0700 Subject: [PATCH 1/6] Specify the maxspeedAnnotation branch of MapboxDirections.swift --- Cartfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Cartfile b/Cartfile index 7e1a2c1d82a..599f031e642 100644 --- a/Cartfile +++ b/Cartfile @@ -1,6 +1,8 @@ binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 4.3 binary "https://www.mapbox.com/ios-sdk/MapboxNavigationNative.json" ~> 6.1.1 -github "mapbox/MapboxDirections.swift" ~> 0.27.3 +# github "https://github.com/avi-c/mapbox/MapboxDirections.swift.git" +# git "https://github.com/avi-c/MapboxDirections.swift" "maxspeedAnnotations" +github "mapbox/MapboxDirections.swift" "maxspeedAnnotations" github "mapbox/turf-swift" ~> 0.3 github "mapbox/mapbox-events-ios" ~> 0.8.1 github "ceeK/Solar" ~> 2.1.0 From 82c5df2f24b246cec8cc11a60f332e922fcafeea Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Wed, 17 Apr 2019 16:41:22 -0700 Subject: [PATCH 2/6] add maximumSpeedLimit to the route attribute options. --- MapboxCoreNavigation/NavigationRouteOptions.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MapboxCoreNavigation/NavigationRouteOptions.swift b/MapboxCoreNavigation/NavigationRouteOptions.swift index fcf6cf3b196..0c58471648a 100644 --- a/MapboxCoreNavigation/NavigationRouteOptions.swift +++ b/MapboxCoreNavigation/NavigationRouteOptions.swift @@ -25,7 +25,7 @@ open class NavigationRouteOptions: RouteOptions { shapeFormat = .polyline6 includesSteps = true routeShapeResolution = .full - attributeOptions = [.congestionLevel, .expectedTravelTime] + attributeOptions = [.congestionLevel, .expectedTravelTime, .maximumSpeedLimit] includesSpokenInstructions = true locale = Locale.nationalizedCurrent distanceMeasurementSystem = Locale.current.usesMetricSystem ? .metric : .imperial @@ -79,7 +79,7 @@ open class NavigationMatchOptions: MatchOptions { includesSteps = true routeShapeResolution = .full shapeFormat = .polyline6 - attributeOptions = [.congestionLevel, .expectedTravelTime] + attributeOptions = [.congestionLevel, .expectedTravelTime, .maximumSpeedLimit] includesSpokenInstructions = true locale = Locale.nationalizedCurrent distanceMeasurementSystem = Locale.current.usesMetricSystem ? .metric : .imperial From 00805b64d849f1686efdcf839794f9a5dfd20f5d Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Thu, 18 Apr 2019 09:13:40 -0700 Subject: [PATCH 3/6] Add accessors for prior, current, and next SpeedLimit along the RouteProgress. --- MapboxCoreNavigation/RouteProgress.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/MapboxCoreNavigation/RouteProgress.swift b/MapboxCoreNavigation/RouteProgress.swift index 2a4cb803a8a..895f8e1089e 100644 --- a/MapboxCoreNavigation/RouteProgress.swift +++ b/MapboxCoreNavigation/RouteProgress.swift @@ -415,6 +415,27 @@ open class RouteLegProgress: NSObject { */ @objc public var currentStepProgress: RouteStepProgress + /** + Returns the SpeedLimit object for the current step + */ + @objc public var currentSpeedLimit: SpeedLimit? { + return leg.segmentMaximumSpeedLimits?[stepIndex] + } + + @objc public var priorSpeedLimit: SpeedLimit? { + guard stepIndex - 1 >= 0 else { + return nil + } + return leg.segmentMaximumSpeedLimits?[stepIndex - 1] + } + + @objc public var upcomingSpeedLimit: SpeedLimit? { + guard stepIndex + 1 < leg.steps.endIndex else { + return nil + } + return leg.segmentMaximumSpeedLimits?[stepIndex + 1] + } + /** Intializes a new `RouteLegProgress`. From 50ddf50ddbfea224c8cbc2c26b5ddec6cb28c8cb Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Thu, 18 Apr 2019 14:48:19 -0700 Subject: [PATCH 4/6] Add accessor for speed limits by route leg as well as current speed limit for the route progress. --- MapboxCoreNavigation/RouteProgress.swift | 58 +++++++++++++++--------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/MapboxCoreNavigation/RouteProgress.swift b/MapboxCoreNavigation/RouteProgress.swift index 895f8e1089e..17878a6ec9a 100644 --- a/MapboxCoreNavigation/RouteProgress.swift +++ b/MapboxCoreNavigation/RouteProgress.swift @@ -171,6 +171,11 @@ open class RouteProgress: NSObject { */ public var congestionTimesPerStep: [[[CongestionLevel: TimeInterval]]] = [[[:]]] + /** + An array containing speed limits on the route broken up by leg and then step. + */ + public var maximumSpeedLimitsByLeg: [[[SpeedLimit]]] = [] + /** Intializes a new `RouteProgress`. @@ -184,6 +189,7 @@ open class RouteProgress: NSObject { super.init() for (legIndex, leg) in route.legs.enumerated() { + var maximumSpeedLimitsByStep: [[SpeedLimit]] = [] var maneuverCoordinateIndex = 0 congestionTimesPerStep.append([]) @@ -217,9 +223,40 @@ open class RouteProgress: NSObject { } congestionTravelTimesSegmentsByStep.append(congestionTravelTimesSegmentsByLeg) + + maneuverCoordinateIndex = 0 + if let segmentMaximumSpeedLimits = leg.segmentMaximumSpeedLimits { + for step in leg.steps { + guard let coordinates = step.coordinates else { continue } + let stepCoordinateCount = step.maneuverType == .arrive ? Int(step.coordinateCount) : coordinates.dropLast().count + let nextManeuverCoordinateIndex = maneuverCoordinateIndex + stepCoordinateCount - 1 + + guard nextManeuverCoordinateIndex < segmentMaximumSpeedLimits.count else { continue } + + let stepSegmentMaximumSpeedLimits = Array(segmentMaximumSpeedLimits[maneuverCoordinateIndex..= 0, legIndex < maximumSpeedLimitsByLeg.count, currentLegProgress.stepIndex < maximumSpeedLimitsByLeg[legIndex].count, let coordinates = currentLegProgress.currentStepProgress.step.coordinates else { return SpeedLimit.invalid } + + let indexedCoordinate = LineString(coordinates).indexedCoordinateFromStart(distance: currentLegProgress.currentStepProgress.distanceTraveled) + + guard let index = indexedCoordinate?.index, index < maximumSpeedLimitsByLeg[legIndex][currentLegProgress.stepIndex].count else { return SpeedLimit.invalid } + + let speedLimit = maximumSpeedLimitsByLeg[legIndex][currentLegProgress.stepIndex][index] + + return speedLimit + } + public var averageCongestionLevelRemainingOnLeg: CongestionLevel? { let coordinatesLeftOnStepCount = Int(floor((Double(currentLegProgress.currentStepProgress.step.coordinateCount)) * currentLegProgress.currentStepProgress.fractionTraveled)) @@ -415,27 +452,6 @@ open class RouteLegProgress: NSObject { */ @objc public var currentStepProgress: RouteStepProgress - /** - Returns the SpeedLimit object for the current step - */ - @objc public var currentSpeedLimit: SpeedLimit? { - return leg.segmentMaximumSpeedLimits?[stepIndex] - } - - @objc public var priorSpeedLimit: SpeedLimit? { - guard stepIndex - 1 >= 0 else { - return nil - } - return leg.segmentMaximumSpeedLimits?[stepIndex - 1] - } - - @objc public var upcomingSpeedLimit: SpeedLimit? { - guard stepIndex + 1 < leg.steps.endIndex else { - return nil - } - return leg.segmentMaximumSpeedLimits?[stepIndex + 1] - } - /** Intializes a new `RouteLegProgress`. From a15c373c3f90afcb50e84d7b3b54c0898fe3dc9e Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Fri, 19 Apr 2019 09:38:10 -0700 Subject: [PATCH 5/6] Add comment for currentSpeedLimit() function. --- MapboxCoreNavigation/RouteProgress.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MapboxCoreNavigation/RouteProgress.swift b/MapboxCoreNavigation/RouteProgress.swift index 17878a6ec9a..d53c34a7cd8 100644 --- a/MapboxCoreNavigation/RouteProgress.swift +++ b/MapboxCoreNavigation/RouteProgress.swift @@ -243,6 +243,9 @@ open class RouteProgress: NSObject { } } + /** + Returns the SpeedLimit for the current position along the route. Returns SpeedLimit.invalid if the speed limit is unknown or missing. + */ public var currentSpeedLimit: SpeedLimit { let coordinatesLeftOnStepCount = Int(floor((Double(currentLegProgress.currentStepProgress.step.coordinateCount)) * currentLegProgress.currentStepProgress.fractionTraveled)) From ec18eff1a61d50c72411766c7fbf2718768a18d7 Mon Sep 17 00:00:00 2001 From: Avi Cieplinski Date: Mon, 22 Apr 2019 14:26:18 -0700 Subject: [PATCH 6/6] remove commented out lines from Cartfile. --- Cartfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cartfile b/Cartfile index 599f031e642..a16985294d6 100644 --- a/Cartfile +++ b/Cartfile @@ -1,7 +1,5 @@ binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 4.3 binary "https://www.mapbox.com/ios-sdk/MapboxNavigationNative.json" ~> 6.1.1 -# github "https://github.com/avi-c/mapbox/MapboxDirections.swift.git" -# git "https://github.com/avi-c/MapboxDirections.swift" "maxspeedAnnotations" github "mapbox/MapboxDirections.swift" "maxspeedAnnotations" github "mapbox/turf-swift" ~> 0.3 github "mapbox/mapbox-events-ios" ~> 0.8.1