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

Expose road classes in route steps #154

Merged
merged 9 commits into from
Jul 20, 2017
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
20 changes: 20 additions & 0 deletions MapboxDirections.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@
C57D55041DB566A800B94B74 /* MBIntersection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57D55001DB5669600B94B74 /* MBIntersection.swift */; };
C57D55051DB566A900B94B74 /* MBIntersection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57D55001DB5669600B94B74 /* MBIntersection.swift */; };
C57D55081DB58C0200B94B74 /* MBLane.swift in Sources */ = {isa = PBXBuildFile; fileRef = C57D55071DB58C0200B94B74 /* MBLane.swift */; };
C584E3F71F201C7B00BBC9BB /* MBRoadClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = C59426061F1EA6C400C8E59C /* MBRoadClasses.swift */; };
C584E3F81F201C7C00BBC9BB /* MBRoadClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = C59426061F1EA6C400C8E59C /* MBRoadClasses.swift */; };
C584E3F91F201C7D00BBC9BB /* MBRoadClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = C59426061F1EA6C400C8E59C /* MBRoadClasses.swift */; };
C584E3FB1F20285E00BBC9BB /* MBRoadClasses.h in Headers */ = {isa = PBXBuildFile; fileRef = C584E3FA1F2027EE00BBC9BB /* MBRoadClasses.h */; settings = {ATTRIBUTES = (Public, ); }; };
C584E3FC1F20286000BBC9BB /* MBRoadClasses.h in Headers */ = {isa = PBXBuildFile; fileRef = C584E3FA1F2027EE00BBC9BB /* MBRoadClasses.h */; settings = {ATTRIBUTES = (Public, ); }; };
C584E3FD1F20286100BBC9BB /* MBRoadClasses.h in Headers */ = {isa = PBXBuildFile; fileRef = C584E3FA1F2027EE00BBC9BB /* MBRoadClasses.h */; settings = {ATTRIBUTES = (Public, ); }; };
C584E3FE1F20286200BBC9BB /* MBRoadClasses.h in Headers */ = {isa = PBXBuildFile; fileRef = C584E3FA1F2027EE00BBC9BB /* MBRoadClasses.h */; settings = {ATTRIBUTES = (Public, ); }; };
C58EA7AA1E9D7EAD008F98CE /* MBCongestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C58EA7A91E9D7EAD008F98CE /* MBCongestion.swift */; };
C58EA7AB1E9D7F73008F98CE /* MBCongestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C58EA7A91E9D7EAD008F98CE /* MBCongestion.swift */; };
C58EA7AC1E9D7F74008F98CE /* MBCongestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C58EA7A91E9D7EAD008F98CE /* MBCongestion.swift */; };
C58EA7AD1E9D7F75008F98CE /* MBCongestion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C58EA7A91E9D7EAD008F98CE /* MBCongestion.swift */; };
C59426071F1EA6C400C8E59C /* MBRoadClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = C59426061F1EA6C400C8E59C /* MBRoadClasses.swift */; };
C5A3D3981E8188FE00D494A0 /* annotation.json in Resources */ = {isa = PBXBuildFile; fileRef = C5A3D3971E8188FE00D494A0 /* annotation.json */; };
DA1A10C61D00F969009F82FA /* MapboxDirections.h in Headers */ = {isa = PBXBuildFile; fileRef = DA6C9D8A1CAE442B00094FBC /* MapboxDirections.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA1A10C71D00F969009F82FA /* MBDirections.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6254731AE70CB700017857 /* MBDirections.swift */; };
Expand Down Expand Up @@ -169,7 +177,9 @@
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>"; };
C584E3FA1F2027EE00BBC9BB /* MBRoadClasses.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBRoadClasses.h; sourceTree = "<group>"; };
C58EA7A91E9D7EAD008F98CE /* MBCongestion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBCongestion.swift; sourceTree = "<group>"; };
C59426061F1EA6C400C8E59C /* MBRoadClasses.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBRoadClasses.swift; sourceTree = "<group>"; };
C5A3D3971E8188FE00D494A0 /* annotation.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = annotation.json; path = v5/annotation.json; sourceTree = "<group>"; };
DA1A10AF1D00F8FF009F82FA /* MapboxDirections.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MapboxDirections.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DA1A10B81D00F8FF009F82FA /* MapboxDirectionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapboxDirectionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -337,6 +347,8 @@
C558C58B1E94181A00617B37 /* MBAttribute.h */,
C51538CB1E807FF00093FF3E /* MBAttribute.swift */,
C58EA7A91E9D7EAD008F98CE /* MBCongestion.swift */,
C59426061F1EA6C400C8E59C /* MBRoadClasses.swift */,
C584E3FA1F2027EE00BBC9BB /* MBRoadClasses.h */,
DA6C9D8C1CAE442B00094FBC /* Info.plist */,
);
path = MapboxDirections;
Expand Down Expand Up @@ -495,6 +507,7 @@
358D48821E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA1A10C61D00F969009F82FA /* MapboxDirections.h in Headers */,
C558C58D1E94196200617B37 /* MBAttribute.h in Headers */,
C584E3FC1F20286000BBC9BB /* MBRoadClasses.h in Headers */,
C57B2E971DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -506,6 +519,7 @@
358D48831E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA1A10EC1D010247009F82FA /* MapboxDirections.h in Headers */,
C558C58E1E94196200617B37 /* MBAttribute.h in Headers */,
C584E3FD1F20286100BBC9BB /* MBRoadClasses.h in Headers */,
C57B2E981DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -517,6 +531,7 @@
358D48841E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA1A11031D0103A3009F82FA /* MapboxDirections.h in Headers */,
C558C58F1E94196300617B37 /* MBAttribute.h in Headers */,
C584E3FE1F20286200BBC9BB /* MBRoadClasses.h in Headers */,
C57B2E991DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -528,6 +543,7 @@
358D48811E2EAB2500F32A65 /* MBRouteOptions.h in Headers */,
DA6C9D8B1CAE442B00094FBC /* MapboxDirections.h in Headers */,
C558C58C1E94196100617B37 /* MBAttribute.h in Headers */,
C584E3FB1F20285E00BBC9BB /* MBRoadClasses.h in Headers */,
C57B2E961DB8171300E9123A /* MBLaneIndication.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -898,6 +914,7 @@
files = (
C53A02261E92C26E009837BD /* MBAttribute.swift in Sources */,
DA1A10C91D00F969009F82FA /* MBRouteLeg.swift in Sources */,
C584E3F71F201C7B00BBC9BB /* MBRoadClasses.swift in Sources */,
358D48871E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DA1A10CC1D00F969009F82FA /* MBWaypoint.swift in Sources */,
DA1A10CA1D00F969009F82FA /* MBRouteOptions.swift in Sources */,
Expand Down Expand Up @@ -931,6 +948,7 @@
files = (
C53A02271E92C26F009837BD /* MBAttribute.swift in Sources */,
DA1A10EF1D010247009F82FA /* MBRouteLeg.swift in Sources */,
C584E3F81F201C7C00BBC9BB /* MBRoadClasses.swift in Sources */,
358D48881E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DA1A10F21D010247009F82FA /* MBWaypoint.swift in Sources */,
DA1A10F01D010247009F82FA /* MBRouteOptions.swift in Sources */,
Expand Down Expand Up @@ -964,6 +982,7 @@
files = (
C53A02281E92C271009837BD /* MBAttribute.swift in Sources */,
DA1A11061D0103A3009F82FA /* MBRouteLeg.swift in Sources */,
C584E3F91F201C7D00BBC9BB /* MBRoadClasses.swift in Sources */,
358D48891E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DA1A11091D0103A3009F82FA /* MBWaypoint.swift in Sources */,
DA1A11071D0103A3009F82FA /* MBRouteOptions.swift in Sources */,
Expand All @@ -983,6 +1002,7 @@
files = (
C51538CC1E807FF00093FF3E /* MBAttribute.swift in Sources */,
DA2E03EB1CB0E13D00D1269A /* MBRouteOptions.swift in Sources */,
C59426071F1EA6C400C8E59C /* MBRoadClasses.swift in Sources */,
358D48861E2EAB4500F32A65 /* MBRouteOptions.m in Sources */,
DAC05F161CFBFAC400FA0071 /* MBWaypoint.swift in Sources */,
C57D55081DB58C0200B94B74 /* MBLane.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions MapboxDirections/MBAttribute.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import <Foundation/Foundation.h>

/**
Attributes are metadata information for a route leg.

Expand Down
17 changes: 17 additions & 0 deletions MapboxDirections/MBIntersection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public class Intersection: NSObject, NSSecureCoding {
*/
public let usableApproachLanes: IndexSet?

/**
Option set representing the classes of road.

If no road class information is available, this property's value is `nil`.
*/
public let roadClasses: MBRoadClasses?

internal init(json: JSONDictionary) {
location = CLLocationCoordinate2D(geoJSON: json["location"] as! [Double])
headings = json["bearings"] as! [CLLocationDirection]
Expand Down Expand Up @@ -77,6 +84,12 @@ public class Intersection: NSObject, NSSecureCoding {
approachLanes = nil
usableApproachLanes = nil
}

if let classStrings = json["classes"] as? [String] {
roadClasses = RoadClasses(descriptions: classStrings)
} else {
roadClasses = nil
}
}

public required init?(coder decoder: NSCoder) {
Expand All @@ -102,6 +115,8 @@ public class Intersection: NSObject, NSSecureCoding {

approachLanes = decoder.decodeObject(of: [NSArray.self, Lane.self], forKey: "approachLanes") as? [Lane]
usableApproachLanes = decoder.decodeObject(of: NSIndexSet.self, forKey: "usableApproachLanes") as IndexSet?

roadClasses = decoder.decodeObject(of: [NSArray.self, NSNumber.self], forKey: "roadClasses") as? RoadClasses
}

open static var supportsSecureCoding = true
Expand All @@ -120,5 +135,7 @@ public class Intersection: NSObject, NSSecureCoding {

coder.encode(approachLanes, forKey: "approachLanes")
coder.encode(usableApproachLanes, forKey: "usableApproachLanes")

coder.encode(roadClasses, forKey: "roadClass")
}
}
2 changes: 2 additions & 0 deletions MapboxDirections/MBLaneIndication.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import <Foundation/Foundation.h>

/**
Each of these options specifies a maneuver direction for which a given lane can
be used.
Expand Down
35 changes: 35 additions & 0 deletions MapboxDirections/MBRoadClasses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#import <Foundation/Foundation.h>

/**
Option set that contains attributes of a road segment.
*/
typedef NS_OPTIONS(NSUInteger, MBRoadClasses) {
Copy link
Contributor

Choose a reason for hiding this comment

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

All Objective-C files need to import headers for the types they use. This header uses NSUInteger, which is part of Foundation, so import Foundation.h. (This also applies to MBAttribute.h and MBLaneIndication.h.)


/**
The road segment is [tolled](https://wiki.openstreetmap.org/wiki/Key:toll).
*/
MBRoadClassesToll = (1 << 1),

/**
The road segment has access restrictions.

A road segment may have this class if there are [general access restrictions](https://wiki.openstreetmap.org/wiki/Key:access) or a [high-occupancy vehicle](https://wiki.openstreetmap.org/wiki/Key:hov) restriction.
*/
MBRoadClassesRestricted = (1 << 2),

/**
The road segment is a [freeway](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dmotorway) or [freeway ramp](https://wiki.openstreetmap.org/wiki/Tag:highway%3Dmotorway_link).

It may be desirable to suppress the name of the freeway when giving instructions and give instructions at fixed distances before an exit (such as 1 mile or 1 kilometer ahead).
*/
MBRoadClassesMotorway = (1 << 3),

/**
The user must travel this segment of the route by ferry.

The user should verify that the ferry is in operation. For driving and cycling directions, the user should also verify that his or her vehicle is permitted onboard the ferry.

In general, the transport type of the step containing the road segment is also `TransportType.ferry`.
*/
MBRoadClassesFerry = (1 << 4),
};
51 changes: 51 additions & 0 deletions MapboxDirections/MBRoadClasses.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Foundation

public typealias RoadClasses = MBRoadClasses

extension RoadClasses: CustomStringConvertible {

/**
Creates a `RoadClasses` given an array of strings.
*/
public init?(descriptions: [String]) {
var roadClasses: RoadClasses = []
for description in descriptions {
switch description {
case "toll":
roadClasses.insert(.toll)
case "restricted":
roadClasses.insert(.restricted)
case "motorway":
roadClasses.insert(.motorway)
case "ferry":
roadClasses.insert(.ferry)
case "none":
break
default:
return nil
}
}
self.init(rawValue: roadClasses.rawValue)
}

public var description: String {
if isEmpty {
return ""
}

var descriptions: [String] = []
if contains(.toll) {
descriptions.append("toll")
}
if contains(.restricted) {
descriptions.append("restricted")
}
if contains(.motorway) {
descriptions.append("motorway")
}
if contains(.ferry) {
descriptions.append("ferry")
}
return descriptions.joined(separator: ",")
}
}
1 change: 1 addition & 0 deletions MapboxDirections/MapboxDirections.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ FOUNDATION_EXPORT const unsigned char MapboxDirectionsVersionString[];
#import "MBLaneIndication.h"
#import "MBAttribute.h"
#import "MBRouteOptions.h"
#import "MBRoadClasses.h"
Empty file modified MapboxDirectionsTests/Fixtures/v5/annotation.json
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion MapboxDirectionsTests/Fixtures/v5/v5_driving_dc_geojson.json
100644 → 100755

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MapboxDirectionsTests/Fixtures/v5/v5_driving_dc_polyline.json
100644 → 100755

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions MapboxDirectionsTests/V5Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ class V5Tests: XCTestCase {
XCTAssertEqual(leg.name, "I 80, I 80;US 30")
XCTAssertEqual(leg.steps.count, 59)

let firstStep = leg.steps.first
XCTAssertNotNil(firstStep)
let firstStepIntersections = firstStep?.intersections
XCTAssertNotNil(firstStepIntersections)
let firstIntersection = firstStepIntersections?.first
XCTAssertNotNil(firstIntersection)
let roadClasses = firstIntersection?.roadClasses
XCTAssertNotNil(roadClasses)
XCTAssertTrue(roadClasses?.contains([.toll, .restricted]) ?? false)

let step = leg.steps[43]
XCTAssertEqual(round(step.distance), 688)
XCTAssertEqual(round(step.expectedTravelTime), 30)
Expand Down