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

Add SubType to VisualInstruction.Component. #778

Merged
merged 11 commits into from
Dec 19, 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
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Changes to Mapbox Directions for Swift

## v2.9.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entry should not be public just yet.


* Added the `RestStop.amenities` property that describes useful and important facilities such as gas stations, restaurants, and ATMs. ([#780](https://github.com/mapbox/mapbox-directions-swift/pull/780))

## v2.8.0

### Packaging
Expand Down
8 changes: 8 additions & 0 deletions MapboxDirections.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
43F89F942350F952007B591E /* MapMatchingResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F89F922350F952007B591E /* MapMatchingResponse.swift */; };
43F89F952350F952007B591E /* MapMatchingResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F89F922350F952007B591E /* MapMatchingResponse.swift */; };
43F89F962350F952007B591E /* MapMatchingResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43F89F922350F952007B591E /* MapMatchingResponse.swift */; };
8A2CD31E294CFA54006C0AF6 /* instructionComponentsWithSubType.json in Resources */ = {isa = PBXBuildFile; fileRef = 8A2CD31D294CFA54006C0AF6 /* instructionComponentsWithSubType.json */; };
8A2CD31F294CFA54006C0AF6 /* instructionComponentsWithSubType.json in Resources */ = {isa = PBXBuildFile; fileRef = 8A2CD31D294CFA54006C0AF6 /* instructionComponentsWithSubType.json */; };
8A2CD320294CFA54006C0AF6 /* instructionComponentsWithSubType.json in Resources */ = {isa = PBXBuildFile; fileRef = 8A2CD31D294CFA54006C0AF6 /* instructionComponentsWithSubType.json */; };
8A3B4C9B24EB55F60085DA64 /* RouteResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A3B4C9A24EB55F60085DA64 /* RouteResponseTests.swift */; };
8A47418F2947D1E100F231F9 /* AmenityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A47418E2947D1E100F231F9 /* AmenityTests.swift */; };
8A4741912947D22900F231F9 /* amenities.json in Resources */ = {isa = PBXBuildFile; fileRef = 8A4741902947D22900F231F9 /* amenities.json */; };
Expand Down Expand Up @@ -570,6 +573,7 @@
4392557523440EC2006EEE88 /* DirectionsError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectionsError.swift; sourceTree = "<group>"; };
43D992FB2437B8D2008A2D74 /* CredentialsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CredentialsTests.swift; sourceTree = "<group>"; };
43F89F922350F952007B591E /* MapMatchingResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapMatchingResponse.swift; sourceTree = "<group>"; };
8A2CD31D294CFA54006C0AF6 /* instructionComponentsWithSubType.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = instructionComponentsWithSubType.json; sourceTree = "<group>"; };
8A3B4C9A24EB55F60085DA64 /* RouteResponseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteResponseTests.swift; sourceTree = "<group>"; };
8A41B0FC24F5C2390021FFDC /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
8A47418E2947D1E100F231F9 /* AmenityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmenityTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -836,6 +840,7 @@
C5D1D7EF1F6AF91700A1C4F1 /* instructions.json */,
AEAB390C20D7F4F4008F4E54 /* subLaneInstructions.json */,
AEAB391020D94699008F4E54 /* subVisualInstructions.json */,
8A2CD31D294CFA54006C0AF6 /* instructionComponentsWithSubType.json */,
);
name = Instructions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1331,6 +1336,7 @@
buildActionMask = 2147483647;
files = (
DA737EE51D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */,
8A2CD31F294CFA54006C0AF6 /* instructionComponentsWithSubType.json in Resources */,
2BA2E747257A667500D7AFC6 /* incidents.json in Resources */,
DA1A10CF1D00F975009F82FA /* v5_driving_dc_polyline.json in Resources */,
2B54080A245B23BE006C820B /* incorrectRouteRefreshResponse.json in Resources */,
Expand Down Expand Up @@ -1368,6 +1374,7 @@
buildActionMask = 2147483647;
files = (
DA737EE61D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */,
8A2CD320294CFA54006C0AF6 /* instructionComponentsWithSubType.json in Resources */,
2BA2E748257A667500D7AFC6 /* incidents.json in Resources */,
DA1A10F31D010251009F82FA /* v5_driving_dc_polyline.json in Resources */,
2B54080B245B23BE006C820B /* incorrectRouteRefreshResponse.json in Resources */,
Expand Down Expand Up @@ -1412,6 +1419,7 @@
buildActionMask = 2147483647;
files = (
DA737EE41D05F91E005BDA16 /* v5_driving_dc_geojson.json in Resources */,
8A2CD31E294CFA54006C0AF6 /* instructionComponentsWithSubType.json in Resources */,
2BA2E746257A667500D7AFC6 /* incidents.json in Resources */,
DAC05F1C1CFC1E5300FA0071 /* v5_driving_dc_polyline.json in Resources */,
2B540809245B23BE006C820B /* incorrectRouteRefreshResponse.json in Resources */,
Expand Down
83 changes: 78 additions & 5 deletions Sources/MapboxDirections/VisualInstructionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public extension VisualInstruction {
/**
The component is an image of a zoomed junction, with a fallback text representation.
*/
case guidanceView(image: GuidanceViewImageRepresentation, alternativeText: TextRepresentation)
case guidanceView(image: GuidanceViewImageRepresentation, alternativeText: TextRepresentation, kind: GuidanceViewKind? = nil)

/**
The component contains the localized word for “Exit”.
Expand Down Expand Up @@ -254,6 +254,7 @@ public struct GuidanceViewImageRepresentation: Equatable {
extension VisualInstruction.Component: Codable {
private enum CodingKeys: String, CodingKey {
case kind = "type"
case guidanceViewKind = "subType"
case text
case abbreviatedText = "abbr"
case abbreviatedTextPriority = "abbr_priority"
Expand All @@ -275,6 +276,75 @@ extension VisualInstruction.Component: Codable {
case lane
}

/**
:nodoc:
MaximAlien marked this conversation as resolved.
Show resolved Hide resolved
Kind of the guidance view that provides more context about the component guidance view that may help in visual
markup and display choices.
*/
public enum GuidanceViewKind: String, Codable, CaseIterable {

/**
Junction view. Bird’s-eye artist’s rendition view of the overhead signage and
preferred road lane arrow on motorways where the road bifurcates into 2 or
more motorway trunk roads.
*/
case fork = "jct"
Comment on lines +287 to +291
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: imo, we should make these doc comments more clear since the naming has changed. Some of @1ec5's suggestions provide some clarity as to what each of these GuidanceViewKinds mean, and it would be great to let developers know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit hard to provide more clarity at this point, maybe in future we'll be able to extend these docs. Current info regarding sub types was taken from private docs and unfortunately they do not have enough info either.


/**
Advanced 2D signboard (vendor enhanced detailed signboard).
*/
case signboard = "signboard"

/**
Service area/parking area guide map. Vertical artist’s rendition guide map of an SAPA rest area
showing various facilities icons such as restaurants, restrooms and parking areas.
The scale is approximately 1 to 5K.
*/
case serviceAreaGuideMap = "sapaguidemap"

/**
Service area/parking area. Bird’s-eye artist’s rendition view of the overhead
signage and preferred road lane arrow at a rest area ramp where the route
leaves the main road.
*/
case serviceArea = "sapa"

/**
Sign image after a toll gate. Used immediately after exiting a toll gate containing just the
overhead signboard. The preferred road (not the lane) arrow is highlighted on the signboard.
*/
case afterToll = "aftertoll"

/**
3D city real. Bird’s-eye artist’s rendition view of a general road intersection
and preferred road lane arrow. There is no overhead signage.
*/
case realisticUrbanIntersection = "cityreal"

/**
Motorway entrance. Bird’s-eye artist’s rendition view of the overhead signage and
preferred road lane arrow at an entrance ramp onto a motorway.
*/
case motorwayEntrance = "entrance"

/**
Motorway exit. Bird’s-eye artist’s rendition view of the overhead signage and
preferred road lane arrow at an exit ramp from a motorway.
*/
case motorwayExit = "exit"

/**
Branched image after a toll gate. Bird’s-eye artist’s rendition view of the overhead
signage and preferred road lane arrow immediately after exiting a toll gate.
*/
case tollBranch = "tollbranch"

/**
Direction signboard guidance view.
*/
case directionBoard = "directionboard"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let kind = (try? container.decode(Kind.self, forKey: .kind)) ?? .text
Expand Down Expand Up @@ -317,7 +387,8 @@ extension VisualInstruction.Component: Codable {
imageURL = URL(string: imageURLString)
}
let guidanceViewImageRepresentation = GuidanceViewImageRepresentation(imageURL: imageURL)
self = .guidanceView(image: guidanceViewImageRepresentation, alternativeText: textRepresentation)
let guidanceViewKind = try container.decodeIfPresent(GuidanceViewKind.self, forKey: .guidanceViewKind)
self = .guidanceView(image: guidanceViewImageRepresentation, alternativeText: textRepresentation, kind: guidanceViewKind)
}
}

Expand Down Expand Up @@ -349,10 +420,11 @@ extension VisualInstruction.Component: Codable {
try container.encode(indications, forKey: .directions)
try container.encode(isUsable, forKey: .isActive)
try container.encodeIfPresent(preferredDirection, forKey: .activeDirection)
case .guidanceView(let image, let alternativeText):
case .guidanceView(let image, let alternativeText, let kind):
try container.encode(Kind.guidanceView, forKey: .kind)
textRepresentation = alternativeText
try container.encodeIfPresent(image.imageURL?.absoluteString, forKey: .imageURL)
try container.encodeIfPresent(kind, forKey: .guidanceViewKind)
}

if let textRepresentation = textRepresentation {
Expand All @@ -375,10 +447,11 @@ extension VisualInstruction.Component: Equatable {
let .image(rhsURL, rhsAlternativeText)):
return lhsURL == rhsURL
&& lhsAlternativeText == rhsAlternativeText
case (let .guidanceView(lhsURL, lhsAlternativeText),
let .guidanceView(rhsURL, rhsAlternativeText)):
case (let .guidanceView(lhsURL, lhsAlternativeText, lhsKind),
let .guidanceView(rhsURL, rhsAlternativeText, rhsKind)):
return lhsURL == rhsURL
&& lhsAlternativeText == rhsAlternativeText
&& lhsKind == rhsKind
case (let .lane(lhsIndications, lhsIsUsable, lhsPreferredDirection),
let .lane(rhsIndications, rhsIsUsable, rhsPreferredDirection)):
return lhsIndications == rhsIndications
Expand Down
Loading