diff --git a/Cartfile b/Cartfile index 7e1a2c1d82a..a16985294d6 100644 --- a/Cartfile +++ b/Cartfile @@ -1,6 +1,6 @@ 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 "mapbox/MapboxDirections.swift" "maxspeedAnnotations" github "mapbox/turf-swift" ~> 0.3 github "mapbox/mapbox-events-ios" ~> 0.8.1 github "ceeK/Solar" ~> 2.1.0 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 diff --git a/MapboxCoreNavigation/RouteProgress.swift b/MapboxCoreNavigation/RouteProgress.swift index 2a4cb803a8a..d53c34a7cd8 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,43 @@ 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))