@@ -121,10 +121,20 @@ public class OSRMInstructionFormatter: Formatter {
121
121
typealias InstructionsByModifier = [ String : InstructionsByToken ]
122
122
123
123
override public func string( for obj: Any ? ) -> String ? {
124
- return string ( for: obj, legIndex: nil , numberOfLegs: nil , modifyValueByKey: nil )
124
+ return string ( for: obj, legIndex: nil , numberOfLegs: nil , roadClasses : nil , modifyValueByKey: nil )
125
125
}
126
126
127
- public func string( for obj: Any ? , legIndex: Int ? , numberOfLegs: Int ? , modifyValueByKey: ( ( TokenType , String ) -> String ) ? ) -> String ? {
127
+ /**
128
+ Creates an instruction given a step and options.
129
+
130
+ - parameter step:
131
+ - parameter legIndex: Current leg index the user is currently on.
132
+ - parameter numberOfLegs: Total number of `RouteLeg` for the given `Route`.
133
+ - parameter roadClasses: Option set representing the classes of road for the `RouteStep`.
134
+ - parameter modifyValueByKey: Allows for mutating the instruction at given parts of the instruction.
135
+ - returns: An instruction as a `String`.
136
+ */
137
+ public func string( for obj: Any ? , legIndex: Int ? , numberOfLegs: Int ? , roadClasses: RoadClasses ? = RoadClasses ( [ ] ) , modifyValueByKey: ( ( TokenType , String ) -> String ) ? ) -> String ? {
128
138
guard let step = obj as? RouteStep else {
129
139
return nil
130
140
}
@@ -179,9 +189,12 @@ public class OSRMInstructionFormatter: Formatter {
179
189
// Set wayName
180
190
let name = step. names? . first
181
191
let ref = step. codes? . first
192
+ let isMotorway = roadClasses? . contains ( . motorway) ?? false
182
193
183
- if let name = name, let ref = ref, name != ref {
194
+ if let name = name, let ref = ref, name != ref, !isMotorway {
184
195
wayName = modifyValueByKey != nil ? " \( modifyValueByKey!( . wayName, name) ) ( \( modifyValueByKey!( . wayName, ref) ) ) " : " \( name) ( \( ref) ) "
196
+ } else if let ref = ref, isMotorway, let decimalRange = ref. rangeOfCharacter ( from: . decimalDigits) , !decimalRange. isEmpty {
197
+ wayName = modifyValueByKey != nil ? " \( modifyValueByKey!( . wayName, ref) ) " : ref
185
198
} else if name == nil , let ref = ref {
186
199
wayName = modifyValueByKey != nil ? " \( modifyValueByKey!( . wayName, ref) ) " : ref
187
200
} else {
0 commit comments