-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2694 from mapbox/vk/552-route-alerts
Route Alerts
- Loading branch information
Showing
21 changed files
with
288 additions
and
27 deletions.
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
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,23 @@ | ||
|
||
import Foundation | ||
import MapboxNavigationNative | ||
import MapboxDirections | ||
|
||
extension AdministrativeRegion { | ||
init(_ adminInfo: RouteAlertAdminInfo) { | ||
self.init(countryCode: adminInfo.iso_3166_1, countryCodeAlpha3: adminInfo.iso_3166_1_alpha3) | ||
} | ||
} | ||
|
||
/** | ||
`BorderCrossingInfo` encapsulates a border crossing, specifying crossing region codes. | ||
*/ | ||
public struct BorderCrossing { | ||
public let from: AdministrativeRegion | ||
public let to: AdministrativeRegion | ||
|
||
init(_ borderCrossing: RouteAlertBorderCrossingInfo) { | ||
from = AdministrativeRegion(borderCrossing.from) | ||
to = AdministrativeRegion(borderCrossing.to) | ||
} | ||
} |
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,53 @@ | ||
|
||
import Foundation | ||
import MapboxNavigationNative | ||
import MapboxDirections | ||
|
||
extension Incident { | ||
init?(_ incidentInfo: RouteAlertIncidentInfo) { | ||
var incidentType: Incident.Kind! | ||
switch incidentInfo.type { | ||
case .kAccident: | ||
incidentType = .accident | ||
case .kCongestion: | ||
incidentType = .congestion | ||
case .kConstruction: | ||
incidentType = .construction | ||
case .kDisabledVehicle: | ||
incidentType = .disabledVehicle | ||
case .kLaneRestriction: | ||
incidentType = .laneRestriction | ||
case .kMassTransit: | ||
incidentType = .massTransit | ||
case .kMiscellaneous: | ||
incidentType = .miscellaneous | ||
case .kOtherNews: | ||
incidentType = .otherNews | ||
case .kPlannedEvent: | ||
incidentType = .plannedEvent | ||
case .kRoadClosure: | ||
incidentType = .roadClosure | ||
case .kRoadHazard: | ||
incidentType = .roadHazard | ||
case .kWeather: | ||
incidentType = .weather | ||
} | ||
|
||
guard incidentType != nil else { | ||
return nil | ||
} | ||
|
||
self.init(identifier: incidentInfo.id, | ||
type: incidentType, | ||
description: incidentInfo.description ?? "", | ||
creationDate: incidentInfo.creationTime ?? Date.distantPast, | ||
startDate: incidentInfo.startTime ?? Date.distantPast, | ||
endDate: incidentInfo.endTime ?? Date.distantPast, | ||
impact: incidentInfo.impact ?? "", | ||
subtype: incidentInfo.subType, | ||
subtypeDescription: incidentInfo.subTypeDescription, | ||
alertCodes: Set(incidentInfo.alertcCodes.map { $0.intValue }), | ||
lanesBlocked: BlockedLanes(descriptions: incidentInfo.lanesBlocked), | ||
shapeIndexRange: -1 ..< -1) | ||
} | ||
} |
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,15 @@ | ||
|
||
import Foundation | ||
import MapboxNavigationNative | ||
import MapboxDirections | ||
|
||
extension RestStop { | ||
init(_ serviceArea: RouteAlertServiceAreaInfo) { | ||
switch serviceArea.type { | ||
case .kRestArea: | ||
self.init(type: .restArea) | ||
case .kServiceArea: | ||
self.init(type: .serviceArea) | ||
} | ||
} | ||
} |
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,95 @@ | ||
import Foundation | ||
import CoreLocation | ||
import MapboxNavigationNative | ||
import MapboxDirections | ||
|
||
/** | ||
`RouteAlert` encapsulates information about various incoming events. Common attributes like location, distance to the event, length and other is provided for each POI, while specific meta data is supplied via `alert` property. | ||
*/ | ||
public struct RouteAlert { | ||
/// Enumeration used for encapsulating additional details to describe specific type of alert | ||
public enum Alert { | ||
/// Incident alert with details | ||
case incident(Incident) | ||
/// Tunnel alert with details | ||
case tunnel(Tunnel) | ||
/// Border alert crossing with details | ||
case borderCrossing(BorderCrossing) | ||
/// Toll collect alert with details | ||
case tollCollection(TollCollection) | ||
/// Service area alert with details | ||
case serviceArea(RestStop) | ||
/// Restricted area alert | ||
case restrictedArea | ||
} | ||
|
||
/// Alert data with specific info. Contents depend on exact alert type. | ||
public let alert: Alert | ||
|
||
/// Distance to route alert relative to start of the route, meters. | ||
public let distance: CLLocationDistance | ||
/** | ||
Distance from current position to alert, meters. | ||
|
||
This value can be negative if it is a spanned alert and we are somewhere in the middle of it. | ||
*/ | ||
public let distanceToStart: CLLocationDistance | ||
/** | ||
Length of the alert info. | ||
|
||
This value will be non-null for composite route alerts */ | ||
public let length: CLLocationDistance? | ||
|
||
/// Coordinate of route alert beginning point | ||
public let beginCoordinate: CLLocationCoordinate2D | ||
/// Coordinate of route alert ending point | ||
public let endCoordinate: CLLocationCoordinate2D | ||
|
||
/// Segment index in corresponding `Route.shape` where this alert begins. | ||
public let beginSegmentIndex: UInt32 | ||
/// Segment index in corresponding `Route.shape` where this alert ends. | ||
public let endSegmentIndex: UInt32 | ||
|
||
init(_ upcomingAlert: UpcomingRouteAlert) { | ||
self.distance = upcomingAlert.alert.distance | ||
self.distanceToStart = upcomingAlert.distanceToStart | ||
self.length = upcomingAlert.alert.length?.doubleValue | ||
self.beginCoordinate = upcomingAlert.alert.beginCoordinate | ||
self.endCoordinate = upcomingAlert.alert.endCoordinate | ||
self.beginSegmentIndex = upcomingAlert.alert.beginGeometryIndex | ||
self.endSegmentIndex = upcomingAlert.alert.endGeometryIndex | ||
|
||
switch upcomingAlert.alert.type { | ||
case .kIncident: | ||
guard let incidentInfo = upcomingAlert.alert.incidentInfo else { | ||
preconditionFailure("Alert of type \(upcomingAlert.alert.type) did not contain an info data.") | ||
} | ||
guard let incident = Incident(incidentInfo) else { | ||
preconditionFailure("Alert of type \(upcomingAlert.alert.type) had unrecognized Incident type: \(incidentInfo.type).") | ||
} | ||
self.alert = .incident(incident) | ||
case .kTunnelEntrance: | ||
guard let tunnelInfo = upcomingAlert.alert.tunnelInfo else { | ||
preconditionFailure("Alert of type \(upcomingAlert.alert.type) did not contain an info data.") | ||
} | ||
self.alert = .tunnel(Tunnel(tunnelInfo)) | ||
case .kBorderCrossing: | ||
guard let adminInfo = upcomingAlert.alert.borderCrossingInfo else { | ||
preconditionFailure("Alert of type \(upcomingAlert.alert.type) did not contain an info data.") | ||
} | ||
self.alert = .borderCrossing(BorderCrossing(adminInfo)) | ||
case .kTollCollectionPoint: | ||
guard let tollInfo = upcomingAlert.alert.tollCollectionInfo else { | ||
preconditionFailure("Alert of type \(upcomingAlert.alert.type) did not contain an info data.") | ||
} | ||
self.alert = .tollCollection(TollCollection(tollInfo)) | ||
case .kServiceArea: | ||
guard let serviceAreaInfo = upcomingAlert.alert.serviceAreaInfo else { | ||
preconditionFailure("Alert of type \(upcomingAlert.alert.type) did not contain an info data.") | ||
} | ||
self.alert = .serviceArea(RestStop(serviceAreaInfo)) | ||
case .kRestrictedArea: | ||
self.alert = .restrictedArea | ||
} | ||
} | ||
} |
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,15 @@ | ||
|
||
import Foundation | ||
import MapboxNavigationNative | ||
import MapboxDirections | ||
|
||
extension TollCollection { | ||
init(_ tollInfo: RouteAlertTollCollectionInfo) { | ||
switch tollInfo.type { | ||
case .kTollBooth: | ||
self.init(type: .booth) | ||
case .kTollGantry: | ||
self.init(type: .gantry) | ||
} | ||
} | ||
} |
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,14 @@ | ||
|
||
import Foundation | ||
import MapboxNavigationNative | ||
|
||
/** | ||
`Tunnel` is used for naming incoming tunnels, together with route alerts. | ||
*/ | ||
public struct Tunnel { | ||
public let name: String | ||
|
||
init(_ tunnelInfo: RouteAlertTunnelInfo) { | ||
name = tunnelInfo.name | ||
} | ||
} |
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
Oops, something went wrong.