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

Custom AttributeOptions #748

Merged
merged 7 commits into from
Oct 10, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Other Changes

* Added the `Waypoint.layer` property, which can ensure that the route begins on the correct road if it is above or below another road. ([#745](https://github.com/mapbox/mapbox-directions-swift/pull/745))
* Expanded `AttributeOptions` to allow user options with custom values. See `AttributeOptions.customOptionsByRawValue` for reference. ([#748](https://github.com/mapbox/mapbox-directions-swift/pull/748))
* Fixed incorrect shape indicies in `RouteLeg.incidents` after route refresh. ([#752](https://github.com/mapbox/mapbox-directions-swift/pull/752))

## 2.7.0
Expand Down
26 changes: 26 additions & 0 deletions MapboxDirections.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
2B28E22527EDB2AA0029E4C1 /* ForeignMemberContainerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B28E22227EDB2A90029E4C1 /* ForeignMemberContainerTests.swift */; };
2B39DD40270F034700ED68E4 /* CodingOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B39DD3F270F034700ED68E4 /* CodingOperation.swift */; };
2B4383022549C22700A3E38B /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B4383002549C22700A3E38B /* main.swift */; };
2B46024528EDB1670008A624 /* CustomValueOptionSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024428EDB1670008A624 /* CustomValueOptionSet.swift */; };
2B46024628EDB1670008A624 /* CustomValueOptionSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024428EDB1670008A624 /* CustomValueOptionSet.swift */; };
2B46024728EDB1670008A624 /* CustomValueOptionSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024428EDB1670008A624 /* CustomValueOptionSet.swift */; };
2B46024828EDB1670008A624 /* CustomValueOptionSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024428EDB1670008A624 /* CustomValueOptionSet.swift */; };
2B46025328EDB62E0008A624 /* AttributeOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024A28EDB18B0008A624 /* AttributeOptionsTests.swift */; };
2B46025428EDB62F0008A624 /* AttributeOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024A28EDB18B0008A624 /* AttributeOptionsTests.swift */; };
2B46025528EDB6300008A624 /* AttributeOptionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024A28EDB18B0008A624 /* AttributeOptionsTests.swift */; };
2B46025628EDB6390008A624 /* CustomStringOptionSetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024928EDB18B0008A624 /* CustomStringOptionSetTests.swift */; };
2B46025728EDB63A0008A624 /* CustomStringOptionSetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024928EDB18B0008A624 /* CustomStringOptionSetTests.swift */; };
2B46025828EDB63B0008A624 /* CustomStringOptionSetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B46024928EDB18B0008A624 /* CustomStringOptionSetTests.swift */; };
2B46DB0C27EDF8580068C893 /* RouteRefreshResponseWithForeignMembers.json in Resources */ = {isa = PBXBuildFile; fileRef = 2B46DB0B27EDF8580068C893 /* RouteRefreshResponseWithForeignMembers.json */; };
2B46DB0D27EDF8580068C893 /* RouteRefreshResponseWithForeignMembers.json in Resources */ = {isa = PBXBuildFile; fileRef = 2B46DB0B27EDF8580068C893 /* RouteRefreshResponseWithForeignMembers.json */; };
2B46DB0E27EDF8580068C893 /* RouteRefreshResponseWithForeignMembers.json in Resources */ = {isa = PBXBuildFile; fileRef = 2B46DB0B27EDF8580068C893 /* RouteRefreshResponseWithForeignMembers.json */; };
Expand Down Expand Up @@ -495,6 +505,9 @@
2B28E22227EDB2A90029E4C1 /* ForeignMemberContainerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForeignMemberContainerTests.swift; sourceTree = "<group>"; };
2B39DD3F270F034700ED68E4 /* CodingOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CodingOperation.swift; path = Sources/MapboxDirectionsCLI/CodingOperation.swift; sourceTree = "<group>"; };
2B4383002549C22700A3E38B /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = main.swift; path = Sources/MapboxDirectionsCLI/main.swift; sourceTree = "<group>"; };
2B46024428EDB1670008A624 /* CustomValueOptionSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomValueOptionSet.swift; sourceTree = "<group>"; };
2B46024928EDB18B0008A624 /* CustomStringOptionSetTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomStringOptionSetTests.swift; sourceTree = "<group>"; };
2B46024A28EDB18B0008A624 /* AttributeOptionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributeOptionsTests.swift; sourceTree = "<group>"; };
2B46DB0B27EDF8580068C893 /* RouteRefreshResponseWithForeignMembers.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = RouteRefreshResponseWithForeignMembers.json; sourceTree = "<group>"; };
2B5407EC2451B17E006C820B /* RouteRefreshResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteRefreshResponse.swift; sourceTree = "<group>"; };
2B5407F12452FA8C006C820B /* RefreshedRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshedRoute.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -835,6 +848,7 @@
C51538CB1E807FF00093FF3E /* AttributeOptions.swift */,
C58EA7A91E9D7EAD008F98CE /* Congestion.swift */,
2B9F387F272AE23A001DBA12 /* Credentials.swift */,
2B46024428EDB1670008A624 /* CustomValueOptionSet.swift */,
DD6254731AE70CB700017857 /* Directions.swift */,
4392557523440EC2006EEE88 /* DirectionsError.swift */,
C59094BE203B800300EB2417 /* DirectionsOptions.swift */,
Expand Down Expand Up @@ -885,7 +899,9 @@
children = (
DA6C9DAD1CAEC93800094FBC /* Fixtures */,
C5247D701E818A24004B6154 /* AnnotationTests.swift */,
2B46024A28EDB18B0008A624 /* AttributeOptionsTests.swift */,
43D992FB2437B8D2008A2D74 /* CredentialsTests.swift */,
2B46024928EDB18B0008A624 /* CustomStringOptionSetTests.swift */,
DAD06E34239F0B19001A917D /* DirectionsErrorTests.swift */,
DA1A110A1D01045E009F82FA /* DirectionsTests.swift */,
DA6C9DB11CAECA0E00094FBC /* Fixture.swift */,
Expand Down Expand Up @@ -1450,6 +1466,7 @@
C53A02261E92C26E009837BD /* AttributeOptions.swift in Sources */,
DA1A10C91D00F969009F82FA /* RouteLeg.swift in Sources */,
C52552BA1FA15D5E00B1545C /* VisualInstructionBanner.swift in Sources */,
2B46024628EDB1670008A624 /* CustomValueOptionSet.swift in Sources */,
35828C9F217A003F00ED546E /* OfflineDirections.swift in Sources */,
2B5F0E01273BEB3600CC2C1A /* RoadClassExclusionViolation.swift in Sources */,
DAE7EA95230B5FD10003B211 /* Measurement.swift in Sources */,
Expand Down Expand Up @@ -1517,6 +1534,7 @@
DA8F3A7323B56D3B00B56786 /* RouteLegTests.swift in Sources */,
DA1A10CD1D00F972009F82FA /* V5Tests.swift in Sources */,
DAE33A1C1F215DF600C06039 /* IntersectionTests.swift in Sources */,
2B46025428EDB62F0008A624 /* AttributeOptionsTests.swift in Sources */,
2B5407FD245B070A006C820B /* RouteRefreshTests.swift in Sources */,
C5DAACB0201AA92B001F9261 /* MatchTests.swift in Sources */,
DA1A10CE1D00F972009F82FA /* Fixture.swift in Sources */,
Expand All @@ -1527,6 +1545,7 @@
DA4F84EE21C08BFB008A0434 /* WaypointTests.swift in Sources */,
DAABF78F2395ABA900CEEB61 /* SpokenInstructionTests.swift in Sources */,
35CC310C2285739700EA1966 /* WalkingOptionsTests.swift in Sources */,
2B46025728EDB63A0008A624 /* CustomStringOptionSetTests.swift in Sources */,
DABE6C7F236A37E200D370F4 /* JSONSerialization.swift in Sources */,
DAABF7932395AE9800CEEB61 /* GeoJSONTests.swift in Sources */,
F4D785F01DDD82C100FF4665 /* RouteStepTests.swift in Sources */,
Expand All @@ -1547,6 +1566,7 @@
C53A02271E92C26F009837BD /* AttributeOptions.swift in Sources */,
DA1A10EF1D010247009F82FA /* RouteLeg.swift in Sources */,
C52552BB1FA15D5F00B1545C /* VisualInstructionBanner.swift in Sources */,
2B46024728EDB1670008A624 /* CustomValueOptionSet.swift in Sources */,
35828CA0217A003F00ED546E /* OfflineDirections.swift in Sources */,
2B5F0E02273BEB3600CC2C1A /* RoadClassExclusionViolation.swift in Sources */,
DAE7EA96230B5FD10003B211 /* Measurement.swift in Sources */,
Expand Down Expand Up @@ -1614,6 +1634,7 @@
DA8F3A7423B56D3B00B56786 /* RouteLegTests.swift in Sources */,
DA1A10F41D010251009F82FA /* V5Tests.swift in Sources */,
DAE33A1D1F215DF600C06039 /* IntersectionTests.swift in Sources */,
2B46025528EDB6300008A624 /* AttributeOptionsTests.swift in Sources */,
2B5407FE245B070A006C820B /* RouteRefreshTests.swift in Sources */,
C5DAACB1201AA92B001F9261 /* MatchTests.swift in Sources */,
DA1A10F51D010251009F82FA /* Fixture.swift in Sources */,
Expand All @@ -1624,6 +1645,7 @@
DA4F84EF21C08BFB008A0434 /* WaypointTests.swift in Sources */,
DAABF7902395ABA900CEEB61 /* SpokenInstructionTests.swift in Sources */,
35CC310D2285739700EA1966 /* WalkingOptionsTests.swift in Sources */,
2B46025828EDB63B0008A624 /* CustomStringOptionSetTests.swift in Sources */,
DABE6C80236A37E200D370F4 /* JSONSerialization.swift in Sources */,
DAABF7942395AE9800CEEB61 /* GeoJSONTests.swift in Sources */,
F4D785F11DDD82C100FF4665 /* RouteStepTests.swift in Sources */,
Expand All @@ -1644,6 +1666,7 @@
C53A02281E92C271009837BD /* AttributeOptions.swift in Sources */,
DA1A11061D0103A3009F82FA /* RouteLeg.swift in Sources */,
C52552BC1FA15D6000B1545C /* VisualInstructionBanner.swift in Sources */,
2B46024828EDB1670008A624 /* CustomValueOptionSet.swift in Sources */,
35828CA1217A003F00ED546E /* OfflineDirections.swift in Sources */,
2B5F0E03273BEB3600CC2C1A /* RoadClassExclusionViolation.swift in Sources */,
DAE7EA97230B5FD10003B211 /* Measurement.swift in Sources */,
Expand Down Expand Up @@ -1706,6 +1729,7 @@
DA2E03EB1CB0E13D00D1269A /* RouteOptions.swift in Sources */,
C582BA2E2073ED6300647DAA /* Array.swift in Sources */,
C52552B91FA15D5900B1545C /* VisualInstructionBanner.swift in Sources */,
2B46024528EDB1670008A624 /* CustomValueOptionSet.swift in Sources */,
35828C9E217A003F00ED546E /* OfflineDirections.swift in Sources */,
2B5F0E00273BEB3600CC2C1A /* RoadClassExclusionViolation.swift in Sources */,
DAE7EA94230B5FD10003B211 /* Measurement.swift in Sources */,
Expand Down Expand Up @@ -1773,6 +1797,7 @@
DA6C9DAC1CAEC72800094FBC /* V5Tests.swift in Sources */,
8A3B4C9B24EB55F60085DA64 /* RouteResponseTests.swift in Sources */,
DAE33A1B1F215DF600C06039 /* IntersectionTests.swift in Sources */,
2B46025328EDB62E0008A624 /* AttributeOptionsTests.swift in Sources */,
2B5407FC245B070A006C820B /* RouteRefreshTests.swift in Sources */,
C5DAACAF201AA92B001F9261 /* MatchTests.swift in Sources */,
DA6C9DB21CAECA0E00094FBC /* Fixture.swift in Sources */,
Expand All @@ -1783,6 +1808,7 @@
DA4F84ED21C08BFB008A0434 /* WaypointTests.swift in Sources */,
DAABF78E2395ABA900CEEB61 /* SpokenInstructionTests.swift in Sources */,
35CC310B2285739700EA1966 /* WalkingOptionsTests.swift in Sources */,
2B46025628EDB6390008A624 /* CustomStringOptionSetTests.swift in Sources */,
DABE6C7E236A37E200D370F4 /* JSONSerialization.swift in Sources */,
DAABF7922395AE9800CEEB61 /* GeoJSONTests.swift in Sources */,
F4D785EF1DDD82C100FF4665 /* RouteStepTests.swift in Sources */,
Expand Down
13 changes: 12 additions & 1 deletion Sources/MapboxDirections/AttributeOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import Foundation

When any of the attributes are specified, the resulting route leg contains one attribute value for each segment in leg, where a segment is the straight line between two coordinates in the route leg’s full geometry.
*/
public struct AttributeOptions: OptionSet, CustomStringConvertible {
public struct AttributeOptions: CustomValueOptionSet, CustomStringConvertible {
public var rawValue: Int
Udumft marked this conversation as resolved.
Show resolved Hide resolved

public var customOptionsByRawValue: [Int: String] = [:]

public init(rawValue: Int) {
self.rawValue = rawValue
}

public init() {
rawValue = 0
}

/**
Distance (in meters) along the segment.

Expand Down Expand Up @@ -106,6 +112,11 @@ public struct AttributeOptions: OptionSet, CustomStringConvertible {
if contains(.numericCongestionLevel) {
descriptions.append("congestion_numeric")
}
for (key, value) in customOptionsByRawValue {
if rawValue & key != 0 {
descriptions.append(value)
}
}
return descriptions.joined(separator: ",")
}
}
Expand Down
Loading