-
Notifications
You must be signed in to change notification settings - Fork 92
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 then component #258
Add then component #258
Changes from 7 commits
b60c9a3
e4f8f3a
5b00f8c
93a883d
bda1e28
dfc2842
71bd911
58e505c
6b716c5
ee3b7aa
630a4d9
d94febe
7c549ae
dd78e95
b84d719
af610d9
8d5d65c
f0682bc
2264160
489338e
d9865e4
ecd20ab
9b66591
49af516
facefa5
ae6ac98
fe30487
93f0d2b
e54e52f
f4d363d
916531f
9fd9360
f29382a
8becd6c
84d1e29
0578d7d
4ab5aab
1d611ad
3e1dea8
0392017
fbc058f
a6cf422
7a9f950
7581816
fa1c78f
25d5650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,11 @@ open class VisualInstructionBanner: NSObject, NSSecureCoding { | |
*/ | ||
@objc public let secondaryInstruction: VisualInstruction? | ||
|
||
/** | ||
The information about the next maneuver (the one after the upcoming maneuver). This detail gives the driver heads up when the current step is short. | ||
*/ | ||
@objc public let subInstruction: VisualInstruction? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this property to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @1ec5 I understand your preference for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. “Sub” isn’t a word. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @1ec5 okay, if that's your notion, then we're better off with a real English word like PS: The initial lowercase of the entire variable is less favorable. |
||
|
||
/** | ||
Which side of a bidirectional road the driver should drive on, also known as the rule of the road. | ||
*/ | ||
|
@@ -38,14 +43,20 @@ open class VisualInstructionBanner: NSObject, NSSecureCoding { | |
|
||
let primary = json["primary"] as! JSONDictionary | ||
let secondary = json["secondary"] as? JSONDictionary | ||
let sub = json["sub"] as? JSONDictionary | ||
|
||
let primaryInstruction = VisualInstruction(json: primary) | ||
var secondaryInstruction: VisualInstruction? = nil | ||
if let secondary = secondary { | ||
secondaryInstruction = VisualInstruction(json: secondary) | ||
} | ||
|
||
self.init(distanceAlongStep: distanceAlongStep, primaryInstruction: primaryInstruction, secondaryInstruction: secondaryInstruction, drivingSide: drivingSide) | ||
var subInstruction: VisualInstruction? = nil | ||
if let sub = sub { | ||
subInstruction = VisualInstruction(json: sub) | ||
} | ||
|
||
self.init(distanceAlongStep: distanceAlongStep, primaryInstruction: primaryInstruction, secondaryInstruction: secondaryInstruction, subInstruction: subInstruction, drivingSide: drivingSide) | ||
} | ||
|
||
/** | ||
|
@@ -56,10 +67,11 @@ open class VisualInstructionBanner: NSObject, NSSecureCoding { | |
- parameter secondaryInstruction: Less important details about the `RouteStep`. | ||
- parameter drivingSide: Which side of a bidirectional road the driver should drive on. | ||
*/ | ||
@objc public init(distanceAlongStep: CLLocationDistance, primaryInstruction: VisualInstruction, secondaryInstruction: VisualInstruction?, drivingSide: DrivingSide) { | ||
@objc public init(distanceAlongStep: CLLocationDistance, primaryInstruction: VisualInstruction, secondaryInstruction: VisualInstruction?, subInstruction: VisualInstruction?, drivingSide: DrivingSide) { | ||
self.distanceAlongStep = distanceAlongStep | ||
self.primaryInstruction = primaryInstruction | ||
self.secondaryInstruction = secondaryInstruction | ||
self.subInstruction = subInstruction | ||
self.drivingSide = drivingSide | ||
} | ||
|
||
|
@@ -77,6 +89,7 @@ open class VisualInstructionBanner: NSObject, NSSecureCoding { | |
} | ||
self.primaryInstruction = primaryInstruction | ||
self.secondaryInstruction = decoder.decodeObject(of: VisualInstruction.self, forKey: "secondary") | ||
self.subInstruction = decoder.decodeObject(of: VisualInstruction.self, forKey: "sub") | ||
} | ||
|
||
open static var supportsSecureCoding = true | ||
|
@@ -85,6 +98,7 @@ open class VisualInstructionBanner: NSObject, NSSecureCoding { | |
coder.encode(distanceAlongStep, forKey: "distanceAlongStep") | ||
coder.encode(primaryInstruction, forKey: "primary") | ||
coder.encode(secondaryInstruction, forKey: "secondary") | ||
coder.encode(subInstruction, forKey: "sub") | ||
coder.encode(drivingSide, forKey: "drivingSide") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,20 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding { | |
*/ | ||
@objc public var abbreviationPriority: Int = NSNotFound | ||
|
||
/** | ||
An array indicating which directions you can go from a lane (left, right, or straight). | ||
|
||
If the value is `[.left", .straight]`, the driver can go straight or left from that lane. This is only set when the `component` is a lane. | ||
*/ | ||
@objc public var directions: LaneIndication | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be an array of edit: Oh it is, internally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also rename this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bsudekum Yep, it's already an array... 😸 |
||
|
||
/** | ||
The boolean that indicates whether the component is a lane and can be used to complete the upcoming maneuver. | ||
|
||
If multiple lanes are active, then they can all be used to complete the upcoming maneuver. This value is set to `false` by default. | ||
*/ | ||
@objc public var isLaneActive: Bool = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should strive for more similarities with how lane indications are normally exposed. It’s poor API design to expose multiple mutually exclusive properties that are optionally set depending on each other. Consider making VisualInstructionComponent an umbrella class or protocol for subclasses such as LaneInstructionComponent – There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better yet, instead of a bunch of lane instruction components, build up a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this property to |
||
|
||
/** | ||
Initializes a new visual instruction component object based on the given JSON dictionary representation. | ||
|
||
|
@@ -71,7 +85,18 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding { | |
imageURL = URL(string: "\(baseURL)@\(Int(scale))x.png") | ||
} | ||
|
||
self.init(type: type, text: text, imageURL: imageURL, abbreviation: abbreviation, abbreviationPriority: abbreviationPriority) | ||
var isLaneActive = false | ||
if let active = json["active"] as? Bool { | ||
isLaneActive = active | ||
} | ||
|
||
var directions = LaneIndication() | ||
if let laneDirections = json["directions"] as? [String], | ||
let laneIndication = LaneIndication(descriptions: laneDirections) { | ||
directions = laneIndication | ||
} | ||
|
||
self.init(type: type, text: text, imageURL: imageURL, abbreviation: abbreviation, abbreviationPriority: abbreviationPriority, directions: directions, isLaneActive: isLaneActive) | ||
} | ||
|
||
/** | ||
|
@@ -82,13 +107,17 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding { | |
- parameter imageURL: The URL to an image representation of this component. | ||
- parameter abbreviation: An abbreviated representation of `text`. | ||
- parameter abbreviationPriority: The priority for which the component should be abbreviated. | ||
- parameter directions: The possibile directions to go from a lane component. | ||
- parameter isLaneActive: The flag to indicate that the upcoming maneuver can be completed with a lane component. | ||
*/ | ||
@objc public init(type: VisualInstructionComponentType, text: String?, imageURL: URL?, abbreviation: String?, abbreviationPriority: Int) { | ||
@objc public init(type: VisualInstructionComponentType, text: String?, imageURL: URL?, abbreviation: String?, abbreviationPriority: Int, directions: LaneIndication = LaneIndication(), isLaneActive: Bool = false) { | ||
self.text = text | ||
self.imageURL = imageURL | ||
self.type = type | ||
self.abbreviation = abbreviation | ||
self.abbreviationPriority = abbreviationPriority | ||
self.directions = directions | ||
self.isLaneActive = isLaneActive | ||
} | ||
|
||
@objc public required init?(coder decoder: NSCoder) { | ||
|
@@ -111,6 +140,14 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding { | |
self.abbreviation = abbreviation | ||
|
||
abbreviationPriority = decoder.decodeInteger(forKey: "abbreviationPriority") | ||
|
||
guard let directions = decoder.decodeObject(of: [NSArray.self, NSString.self], forKey: "directions") as? [String] else { | ||
return nil | ||
} | ||
|
||
self.directions = LaneIndication(descriptions: directions) ?? LaneIndication() | ||
|
||
self.isLaneActive = decoder.decodeObject(forKey: "active") as? Bool ?? false | ||
} | ||
|
||
open static var supportsSecureCoding = true | ||
|
@@ -120,6 +157,8 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding { | |
coder.encode(type, forKey: "type") | ||
coder.encode(abbreviation, forKey: "abbreviation") | ||
coder.encode(abbreviationPriority, forKey: "abbreviationPriority") | ||
coder.encode(directions, forKey: "directions") | ||
coder.encode(isLaneActive, forKey: "active") | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ import Foundation | |
@objc(MBVisualInstructionComponentType) | ||
public enum VisualInstructionComponentType: Int, CustomStringConvertible { | ||
|
||
/** | ||
The step does not have a particular visual instruction component type associated with it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the developer supposed to do with a |
||
*/ | ||
case none | ||
|
||
/** | ||
The component separates two other destination components. | ||
|
||
|
@@ -30,6 +35,11 @@ public enum VisualInstructionComponentType: Int, CustomStringConvertible { | |
*/ | ||
case exit | ||
|
||
/** | ||
The component contains information about which lanes can be used to complete the maneuver. | ||
*/ | ||
case lane | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case becomes unnecessary because LaneIndicationComponent no longer has a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Key |
||
|
||
/** | ||
A component contains an exit number. | ||
*/ | ||
|
@@ -48,14 +58,18 @@ public enum VisualInstructionComponentType: Int, CustomStringConvertible { | |
type = .exit | ||
case "exit-number": | ||
type = .exitCode | ||
case "lane": | ||
type = .lane | ||
default: | ||
return nil | ||
type = .none | ||
} | ||
self.init(rawValue: type.rawValue) | ||
} | ||
|
||
public var description: String { | ||
switch self { | ||
case .none: | ||
return "none" | ||
case .delimiter: | ||
return "delimiter" | ||
case .image: | ||
|
@@ -66,6 +80,8 @@ public enum VisualInstructionComponentType: Int, CustomStringConvertible { | |
return "exit" | ||
case .exitCode: | ||
return "exit-number" | ||
case .lane: | ||
return "lane" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.