diff --git a/OSRMTextInstructions/OSRMTextInstructions.swift b/OSRMTextInstructions/OSRMTextInstructions.swift index 6bb45d0..5538b79 100644 --- a/OSRMTextInstructions/OSRMTextInstructions.swift +++ b/OSRMTextInstructions/OSRMTextInstructions.swift @@ -192,11 +192,11 @@ public class OSRMInstructionFormatter: Formatter { let isMotorway = roadClasses?.contains(.motorway) ?? false if let name = name, let ref = ref, name != ref, !isMotorway { - wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.wayName, ref)))" : "\(name) (\(ref))" + wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name)) (\(modifyValueByKey!(.code, ref)))" : "\(name) (\(ref))" } else if let ref = ref, isMotorway, let decimalRange = ref.rangeOfCharacter(from: .decimalDigits), !decimalRange.isEmpty { - wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref + wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref } else if name == nil, let ref = ref { - wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, ref))" : ref + wayName = modifyValueByKey != nil ? "\(modifyValueByKey!(.code, ref))" : ref } else { wayName = name != nil ? modifyValueByKey != nil ? "\(modifyValueByKey!(.wayName, name!))" : name! : "" } @@ -276,6 +276,7 @@ public class OSRMInstructionFormatter: Formatter { if let tokenType = TokenType(description: token! as String) { var replacement: String switch tokenType { + case .code: replacement = step.codes?.first ?? "" case .wayName: replacement = wayName case .destination: replacement = destination case .exitCode: replacement = exitCode diff --git a/OSRMTextInstructions/TokenType.swift b/OSRMTextInstructions/TokenType.swift index 0db3e41..6d43ab3 100644 --- a/OSRMTextInstructions/TokenType.swift +++ b/OSRMTextInstructions/TokenType.swift @@ -12,6 +12,7 @@ public enum TokenType: Int, CustomStringConvertible { case modifier case direction case wayPoint + case code public init?(description: String) { let type: TokenType @@ -34,6 +35,8 @@ public enum TokenType: Int, CustomStringConvertible { type = .direction case "nth": type = .wayPoint + case "ref": + type = .code default: return nil } @@ -60,6 +63,8 @@ public enum TokenType: Int, CustomStringConvertible { return "direction" case .wayPoint: return "nth" + case .code: + return "ref" } } }