diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a3e334df..558c534bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * MapboxDirections now requires [Turf v2.4](https://github.com/mapbox/turf-swift/releases/tag/v2.4.0). ([#703](https://github.com/mapbox/mapbox-directions-swift/pull/703)) * Added the `RouteOptions.maximumWeight` property to compute routes that excludes roads with a lower weight limit. ([#694](https://github.com/mapbox/mapbox-directions-swift/pull/694)) * Added `Route.refreshLegIncidents(from:)` method to allow refreshing `RouteLeg.incidents` during a route refresh. ([#704](https://github.com/mapbox/mapbox-directions-swift/pull/704)) +* Added the `Intersection.railroadCrossing`, `Intersection.trafficSignal`, `Intersection.stopSign` and `Intersection.yieldSign` properties to indicate the kind of traffic control devices at an intersection along the route. ([#706](https://github.com/mapbox/mapbox-directions-swift/pull/706)) ## v2.5.0 diff --git a/Sources/MapboxDirections/Intersection.swift b/Sources/MapboxDirections/Intersection.swift index 2a41da3dc..74695aa5b 100644 --- a/Sources/MapboxDirections/Intersection.swift +++ b/Sources/MapboxDirections/Intersection.swift @@ -25,7 +25,11 @@ public struct Intersection: ForeignMemberContainer { restStop: RestStop? = nil, isUrban: Bool? = nil, regionCode: String? = nil, - outletMapboxStreetsRoadClass: MapboxStreetsRoadClass? = nil) { + outletMapboxStreetsRoadClass: MapboxStreetsRoadClass? = nil, + railroadCrossing: Bool? = nil, + trafficSignal: Bool? = nil, + stopSign: Bool? = nil, + yieldSign: Bool? = nil) { self.location = location self.headings = headings self.approachIndex = approachIndex @@ -42,6 +46,10 @@ public struct Intersection: ForeignMemberContainer { self.restStop = restStop self.regionCode = regionCode self.outletMapboxStreetsRoadClass = outletMapboxStreetsRoadClass + self.railroadCrossing = railroadCrossing + self.trafficSignal = trafficSignal + self.stopSign = stopSign + self.yieldSign = yieldSign } // MARK: Getting the Location of the Intersection @@ -169,6 +177,34 @@ public struct Intersection: ForeignMemberContainer { If no lane information is available for the intersection, this property’s value is `nil` */ public let usableLaneIndication: ManeuverDirection? + + /** + Indicates whether there is a railroad crossing at the intersection. + + If such information is not available for an intersection, this property’s value is `nil`. + */ + public let railroadCrossing: Bool? + + /** + Indicates whether there is a traffic signal at the intersection. + + If such information is not available for an intersection, this property’s value is `nil`. + */ + public let trafficSignal: Bool? + + /** + Indicates whether there is a stop sign at the intersection. + + If such information is not available for an intersection, this property’s value is `nil`. + */ + public let stopSign: Bool? + + /** + Indicates whether there is a yield sign at the intersection. + + If such information is not available for an intersection, this property’s value is `nil`. + */ + public let yieldSign: Bool? } extension Intersection: Codable { @@ -187,6 +223,10 @@ extension Intersection: Codable { case restStop = "rest_stop" case administrativeRegionIndex = "admin_index" case geometryIndex = "geometry_index" + case railroadCrossing = "railway_crossing" + case trafficSignal = "traffic_signal" + case stopSign = "stop_sign" + case yieldSign = "yield_sign" } /// Used to code `Intersection.outletMapboxStreetsRoadClass` @@ -328,6 +368,22 @@ extension Intersection: Codable { try container.encode(geoIndex, forKey: .geometryIndex) } + if let railwayCrossing = railroadCrossing { + try container.encode(railwayCrossing, forKey: .railroadCrossing) + } + + if let trafficSignal = trafficSignal { + try container.encode(trafficSignal, forKey: .trafficSignal) + } + + if let stopSign = stopSign { + try container.encode(stopSign, forKey: .stopSign) + } + + if let yieldSign = yieldSign { + try container.encode(yieldSign, forKey: .yieldSign) + } + try encodeForeignMembers(notKeyedBy: CodingKeys.self, to: encoder) } @@ -372,6 +428,11 @@ extension Intersection: Codable { restStop = try container.decodeIfPresent(RestStop.self, forKey: .restStop) + railroadCrossing = try container.decodeIfPresent(Bool.self, forKey: .railroadCrossing) + trafficSignal = try container.decodeIfPresent(Bool.self, forKey: .trafficSignal) + stopSign = try container.decodeIfPresent(Bool.self, forKey: .stopSign) + yieldSign = try container.decodeIfPresent(Bool.self, forKey: .yieldSign) + try decodeForeignMembers(notKeyedBy: CodingKeys.self, with: decoder) } } @@ -393,6 +454,10 @@ extension Intersection: Equatable { lhs.outletRoadClasses == rhs.outletRoadClasses && lhs.tollCollection == rhs.tollCollection && lhs.tunnelName == rhs.tunnelName && - lhs.isUrban == rhs.isUrban + lhs.isUrban == rhs.isUrban && + lhs.railroadCrossing == rhs.railroadCrossing && + lhs.trafficSignal == rhs.trafficSignal && + lhs.stopSign == rhs.stopSign && + lhs.yieldSign == rhs.yieldSign } } diff --git a/Tests/MapboxDirectionsTests/IntersectionTests.swift b/Tests/MapboxDirectionsTests/IntersectionTests.swift index 1b63287e7..bf2a65b34 100644 --- a/Tests/MapboxDirectionsTests/IntersectionTests.swift +++ b/Tests/MapboxDirectionsTests/IntersectionTests.swift @@ -19,6 +19,10 @@ class IntersectionTests: XCTestCase { "type": "toll_booth", "name": "test toll booth" ], + "railway_crossing": true, + "traffic_signal": true, + "stop_sign": false, + "yield_sign": false ], [ "out": 1, @@ -59,6 +63,10 @@ class IntersectionTests: XCTestCase { XCTAssertEqual(intersection.headings, [80.0]) XCTAssertEqual(intersection.location, LocationCoordinate2D(latitude: 52.508068, longitude: 13.426579)) XCTAssertEqual(intersection.outletMapboxStreetsRoadClass, MapboxStreetsRoadClass.streetLimited) + XCTAssertEqual(intersection.railroadCrossing, true) + XCTAssertEqual(intersection.trafficSignal, true) + XCTAssertEqual(intersection.stopSign, false) + XCTAssertEqual(intersection.yieldSign, false) } intersections = [ @@ -76,7 +84,11 @@ class IntersectionTests: XCTestCase { tunnelName: nil, restStop: nil, isUrban: nil, - outletMapboxStreetsRoadClass: .streetLimited), + outletMapboxStreetsRoadClass: .streetLimited, + railroadCrossing: true, + trafficSignal: true, + stopSign: false, + yieldSign: false), Intersection(location: LocationCoordinate2D(latitude: 52.508022, longitude: 13.426688), headings: [30.0, 120.0, 300.0], approachIndex: 2, diff --git a/swift-package-baseline/breakage-allowlist-path.txt b/swift-package-baseline/breakage-allowlist-path.txt index dfef9ff31..0e160b014 100644 --- a/swift-package-baseline/breakage-allowlist-path.txt +++ b/swift-package-baseline/breakage-allowlist-path.txt @@ -1 +1,2 @@ -API breakage: var RouteLegRefreshSource.refreshedIncidents has been added as a protocol requirement \ No newline at end of file +API breakage: var RouteLegRefreshSource.refreshedIncidents has been added as a protocol requirement +API breakage: constructor Intersection.init(location:headings:approachIndex:outletIndex:outletIndexes:approachLanes:usableApproachLanes:preferredApproachLanes:usableLaneIndication:outletRoadClasses:tollCollection:tunnelName:restStop:isUrban:regionCode:outletMapboxStreetsRoadClass:) has been removed \ No newline at end of file