Skip to content

Commit

Permalink
Add isDelimiter to VisualInstructionComponent (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobby Sudekum authored Jan 17, 2018
1 parent b0bf987 commit 8463f0d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
10 changes: 10 additions & 0 deletions MapboxDirections.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
C558C58E1E94196200617B37 /* MBAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = C558C58B1E94181A00617B37 /* MBAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; };
C558C58F1E94196300617B37 /* MBAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = C558C58B1E94181A00617B37 /* MBAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; };
C55FB44B1F6AEBF6006BD1E9 /* MBSpokenInstruction.swift in Sources */ = {isa = PBXBuildFile; fileRef = C55FB44A1F6AEBF6006BD1E9 /* MBSpokenInstruction.swift */; };
C56516841FE1A2DD00A0AD18 /* MBVisualInstructionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C56516831FE1A2DD00A0AD18 /* MBVisualInstructionType.swift */; };
C56516851FE1AB8F00A0AD18 /* MBVisualInstructionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C56516831FE1A2DD00A0AD18 /* MBVisualInstructionType.swift */; };
C56516861FE1AB9000A0AD18 /* MBVisualInstructionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C56516831FE1A2DD00A0AD18 /* MBVisualInstructionType.swift */; };
C56516871FE1AB9100A0AD18 /* MBVisualInstructionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C56516831FE1A2DD00A0AD18 /* MBVisualInstructionType.swift */; };
C57B2E961DB8171300E9123A /* MBLaneIndication.h in Headers */ = {isa = PBXBuildFile; fileRef = C57B2E951DB8171300E9123A /* MBLaneIndication.h */; settings = {ATTRIBUTES = (Public, ); }; };
C57B2E971DB8171300E9123A /* MBLaneIndication.h in Headers */ = {isa = PBXBuildFile; fileRef = C57B2E951DB8171300E9123A /* MBLaneIndication.h */; settings = {ATTRIBUTES = (Public, ); }; };
C57B2E981DB8171300E9123A /* MBLaneIndication.h in Headers */ = {isa = PBXBuildFile; fileRef = C57B2E951DB8171300E9123A /* MBLaneIndication.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -212,6 +216,7 @@
C52CE3921F6AF6E70069963D /* IntructionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntructionsTests.swift; sourceTree = "<group>"; };
C558C58B1E94181A00617B37 /* MBAttribute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBAttribute.h; sourceTree = "<group>"; };
C55FB44A1F6AEBF6006BD1E9 /* MBSpokenInstruction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MBSpokenInstruction.swift; sourceTree = "<group>"; };
C56516831FE1A2DD00A0AD18 /* MBVisualInstructionType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBVisualInstructionType.swift; sourceTree = "<group>"; };
C57B2E951DB8171300E9123A /* MBLaneIndication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBLaneIndication.h; sourceTree = "<group>"; };
C57D55001DB5669600B94B74 /* MBIntersection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBIntersection.swift; sourceTree = "<group>"; };
C57D55071DB58C0200B94B74 /* MBLane.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBLane.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -419,6 +424,7 @@
C55FB44A1F6AEBF6006BD1E9 /* MBSpokenInstruction.swift */,
C52552B81FA15D5900B1545C /* MBVisualInstruction.swift */,
C52552BF1FA1628A00B1545C /* MBVisualInstructionComponent.swift */,
C56516831FE1A2DD00A0AD18 /* MBVisualInstructionType.swift */,
);
path = MapboxDirections;
sourceTree = "<group>";
Expand Down Expand Up @@ -1009,6 +1015,7 @@
C52CE38F1F6AF63C0069963D /* MBSpokenInstruction.swift in Sources */,
C58EA7AB1E9D7F73008F98CE /* MBCongestion.swift in Sources */,
8D381B6B1FDB3D8A008D5A58 /* String.swift in Sources */,
C56516851FE1AB8F00A0AD18 /* MBVisualInstructionType.swift in Sources */,
C547EC691DB59F8F009817F3 /* MBLane.swift in Sources */,
DA1A10C71D00F969009F82FA /* MBDirections.swift in Sources */,
);
Expand Down Expand Up @@ -1049,6 +1056,7 @@
C52CE3901F6AF63D0069963D /* MBSpokenInstruction.swift in Sources */,
C58EA7AC1E9D7F74008F98CE /* MBCongestion.swift in Sources */,
8D381B6C1FDB3D8B008D5A58 /* String.swift in Sources */,
C56516861FE1AB9000A0AD18 /* MBVisualInstructionType.swift in Sources */,
C547EC6A1DB59F90009817F3 /* MBLane.swift in Sources */,
DA1A10ED1D010247009F82FA /* MBDirections.swift in Sources */,
);
Expand Down Expand Up @@ -1089,6 +1097,7 @@
C52CE3911F6AF63E0069963D /* MBSpokenInstruction.swift in Sources */,
C58EA7AD1E9D7F75008F98CE /* MBCongestion.swift in Sources */,
8D381B6D1FDB3D8B008D5A58 /* String.swift in Sources */,
C56516871FE1AB9100A0AD18 /* MBVisualInstructionType.swift in Sources */,
C547EC6B1DB59F91009817F3 /* MBLane.swift in Sources */,
DA1A11041D0103A3009F82FA /* MBDirections.swift in Sources */,
);
Expand All @@ -1113,6 +1122,7 @@
C55FB44B1F6AEBF6006BD1E9 /* MBSpokenInstruction.swift in Sources */,
C58EA7AA1E9D7EAD008F98CE /* MBCongestion.swift in Sources */,
8D381B6A1FDB101F008D5A58 /* String.swift in Sources */,
C56516841FE1A2DD00A0AD18 /* MBVisualInstructionType.swift in Sources */,
C57D55011DB5669600B94B74 /* MBIntersection.swift in Sources */,
DA2E03E91CB0E0B000D1269A /* MBRouteStep.swift in Sources */,
);
Expand Down
25 changes: 22 additions & 3 deletions MapboxDirections/MBVisualInstructionComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,27 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding {
*/
@objc public var imageURL: URL?


/**
:nodoc:
The type of visual instruction component. You can display the component differently depending on its type.
*/
@objc public var type: VisualInstructionComponentType

/**
:nodoc:
Initialize A `VisualInstructionComponent`.
*/
@objc public convenience init(json: [String: Any]) {
let text = json["text"] as? String
var type: VisualInstructionComponentType?
if let _ = json["delimiter"] as? Bool {
type = .delimiter
} else {
type = .destination
}

var imageURL: URL?

if let baseURL = json["imageBaseURL"] as? String {
let scale: CGFloat
#if os(OSX)
Expand All @@ -52,16 +64,17 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding {
imageURL = URL(string: "\(baseURL)@\(Int(scale))x.png")
}

self.init(text: text, imageURL: imageURL)
self.init(type: type!, text: text, imageURL: imageURL)
}

/**
:nodoc:
Initialize A `VisualInstructionComponent`.
*/
@objc public init(text: String?, imageURL: URL?) {
@objc public init(type: VisualInstructionComponentType, text: String?, imageURL: URL?) {
self.text = text
self.imageURL = imageURL
self.type = type
}

@objc public required init?(coder decoder: NSCoder) {
Expand All @@ -74,12 +87,18 @@ open class VisualInstructionComponent: NSObject, NSSecureCoding {
return nil
}
self.imageURL = imageURL

guard let typeString = decoder.decodeObject(of: NSString.self, forKey: "type") as String?, let type = VisualInstructionComponentType(description: typeString) else {
return nil
}
self.type = type
}

open static var supportsSecureCoding = true

public func encode(with coder: NSCoder) {
coder.encode(text, forKey: "text")
coder.encode(imageURL, forKey: "imageURL")
coder.encode(type, forKey: "type")
}
}
42 changes: 42 additions & 0 deletions MapboxDirections/MBVisualInstructionType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Foundation

/**
`VisualInstructionComponentType` describes the type of `VisualInstructionComponent`.
*/
@objc(MBVisualInstructionComponentType)
public enum VisualInstructionComponentType: Int, CustomStringConvertible {

/**
The component separates two other destination components.
If the two adjacent components are both displayed as images, you can hide this delimiter component.
*/
case delimiter

/**
The component bears an exit number or the name of a place or street.
*/
case destination

public init?(description: String) {
let type: VisualInstructionComponentType
switch description {
case "delimiter":
type = .delimiter
case "destination":
type = .destination
default:
return nil
}
self.init(rawValue: type.rawValue)
}

public var description: String {
switch self {
case .delimiter:
return "delimiter"
case .destination:
return "destination"
}
}
}

0 comments on commit 8463f0d

Please sign in to comment.