From f571388d3b39c8b408fa594845282b030c8acee8 Mon Sep 17 00:00:00 2001 From: Fredrik Karlsson Date: Mon, 3 Jun 2019 14:46:14 +0200 Subject: [PATCH] Add MBDirectionsPriority to SPM flavor --- MapboxDirections.xcodeproj/project.pbxproj | 5 ++- Sources/MapboxDirections/MBRouteOptions.swift | 6 +-- Sources/MapboxDirections/SPM/Compat.swift | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 Sources/MapboxDirections/SPM/Compat.swift diff --git a/MapboxDirections.xcodeproj/project.pbxproj b/MapboxDirections.xcodeproj/project.pbxproj index 8c29dabb8..402be02ff 100644 --- a/MapboxDirections.xcodeproj/project.pbxproj +++ b/MapboxDirections.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 35828C9F217A003F00ED546E /* OfflineDirections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35828C9D217A003F00ED546E /* OfflineDirections.swift */; }; 35828CA0217A003F00ED546E /* OfflineDirections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35828C9D217A003F00ED546E /* OfflineDirections.swift */; }; 35828CA1217A003F00ED546E /* OfflineDirections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35828C9D217A003F00ED546E /* OfflineDirections.swift */; }; + 35AF332022A54D1E002066DE /* Compat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35AF331F22A54D1E002066DE /* Compat.swift */; }; 35C0D78F22563B2B005E05A5 /* MBRoadClasses.h in Headers */ = {isa = PBXBuildFile; fileRef = 35C0D78A22563B2A005E05A5 /* MBRoadClasses.h */; settings = {ATTRIBUTES = (Public, ); }; }; 35C0D79022563B2B005E05A5 /* MBRoadClasses.h in Headers */ = {isa = PBXBuildFile; fileRef = 35C0D78A22563B2A005E05A5 /* MBRoadClasses.h */; settings = {ATTRIBUTES = (Public, ); }; }; 35C0D79122563B2B005E05A5 /* MBRoadClasses.h in Headers */ = {isa = PBXBuildFile; fileRef = 35C0D78A22563B2A005E05A5 /* MBRoadClasses.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -322,12 +323,12 @@ 3556CE9C22649CF3009397B5 /* BridgingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = BridgingTests.m; path = ../objc/BridgingTests.m; sourceTree = ""; }; 356CBE52225CE73500048087 /* CoreLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreLocation.swift; sourceTree = ""; }; 35828C9D217A003F00ED546E /* OfflineDirections.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineDirections.swift; sourceTree = ""; }; + 35AF331F22A54D1E002066DE /* Compat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Compat.swift; sourceTree = ""; }; 35C0D78A22563B2A005E05A5 /* MBRoadClasses.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MBRoadClasses.h; path = Sources/objc/MBRoadClasses.h; sourceTree = SOURCE_ROOT; }; 35C0D78B22563B2A005E05A5 /* MBRouteOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MBRouteOptions.h; path = Sources/objc/MBRouteOptions.h; sourceTree = SOURCE_ROOT; }; 35C0D78C22563B2B005E05A5 /* MBLaneIndication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MBLaneIndication.h; path = Sources/objc/MBLaneIndication.h; sourceTree = SOURCE_ROOT; }; 35C0D78D22563B2B005E05A5 /* MBRouteOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MBRouteOptions.m; path = Sources/objc/MBRouteOptions.m; sourceTree = SOURCE_ROOT; }; 35C0D78E22563B2B005E05A5 /* MBAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MBAttribute.h; path = Sources/objc/MBAttribute.h; sourceTree = SOURCE_ROOT; }; - 358D48851E2EAB4500F32A65 /* MBRouteOptions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBRouteOptions.m; sourceTree = ""; }; 35CC310A2285739700EA1966 /* WalkingOptionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalkingOptionsTests.swift; sourceTree = ""; }; 35D92FEF218203AA000C78CB /* 2018-10-16-Liechtenstein.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = "2018-10-16-Liechtenstein.tar"; sourceTree = ""; }; 35DBF004217DF0D90009D2AE /* MBCoordinateBounds.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MBCoordinateBounds.swift; sourceTree = ""; }; @@ -514,6 +515,7 @@ children = ( 352FFA1122565F25007E7C40 /* LaneIndication.swift */, 356CBE52225CE73500048087 /* CoreLocation.swift */, + 35AF331F22A54D1E002066DE /* Compat.swift */, ); path = SPM; sourceTree = ""; @@ -1496,6 +1498,7 @@ C59094B5203B5C7F00EB2417 /* MBDrawingView.swift in Sources */, DADD27B81E5AAAD800D31FAD /* AppDelegate.swift in Sources */, 356CBE53225CE73500048087 /* CoreLocation.swift in Sources */, + 35AF332022A54D1E002066DE /* Compat.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/MapboxDirections/MBRouteOptions.swift b/Sources/MapboxDirections/MBRouteOptions.swift index e2f0a962f..f1cccbf8d 100644 --- a/Sources/MapboxDirections/MBRouteOptions.swift +++ b/Sources/MapboxDirections/MBRouteOptions.swift @@ -154,7 +154,7 @@ open class RouteOptions: DirectionsOptions { The value of this property must be at least `MBDirectionsPriority.low` and at most `MBDirectionsPriority.high`. The default value of `MBDirectionsPriority.default` neither prefers nor avoids alleys, while a negative value between `MBDirectionsPriority.low` and `MBDirectionsPriority.default` avoids alleys, and a positive value between `MBDirectionsPriority.default` and `MBDirectionsPriority.high` prefers alleys. A value of 0.9 is suitable for pedestrians who are comfortable with walking down alleys. */ - @objc open var alleyPriority: MBDirectionsPriority = .default + open var alleyPriority: MBDirectionsPriority = .default /** A number that influences whether the route should prefer or avoid roads or paths that are set aside for pedestrian-only use (walkways or footpaths). @@ -163,7 +163,7 @@ open class RouteOptions: DirectionsOptions { The value of this property must be at least `MBDirectionsPriority.low` and at most `MBDirectionsPriority.high`. The default value of `MBDirectionsPriority.default` neither prefers nor avoids walkways, while a negative value between `MBDirectionsPriority.low` and `MBDirectionsPriority.default` avoids walkways, and a positive value between `MBDirectionsPriority.default` and `MBDirectionsPriority.high` prefers walkways. A value of −0.1 results in less verbose routes in cities where sidewalks and crosswalks are generally mapped as separate footpaths. */ - @objc open var walkwayPriority: MBDirectionsPriority = .default + open var walkwayPriority: MBDirectionsPriority = .default /** The expected uniform travel speed measured in meters per second. @@ -172,7 +172,7 @@ open class RouteOptions: DirectionsOptions { The value of this property must be at least `MBMinimumWalkingSpeed` and at most `MBMaximumWalkingSpeed`. The default value is `MBDefaultWalkingSpeed`. */ - @objc open var speed: CLLocationSpeed = MBDefaultWalkingSpeed + open var speed: CLLocationSpeed = MBDefaultWalkingSpeed override open var urlQueryItems: [URLQueryItem] { var queryItems = super.urlQueryItems diff --git a/Sources/MapboxDirections/SPM/Compat.swift b/Sources/MapboxDirections/SPM/Compat.swift new file mode 100644 index 000000000..9196937e1 --- /dev/null +++ b/Sources/MapboxDirections/SPM/Compat.swift @@ -0,0 +1,40 @@ +import Foundation + + +public enum MBDirectionsPriority { + public typealias RawValue = Double + case low + case `default` + case high + case custom(Double) +} + +extension MBDirectionsPriority: RawRepresentable { + public init(rawValue: Double) { + switch rawValue { + case MBDirectionsPriority.low.rawValue: + self = .low + case MBDirectionsPriority.default.rawValue: + self = .default + case MBDirectionsPriority.high.rawValue: + self = .high + case MBDirectionsPriority.custom(rawValue).rawValue: + self = .custom(rawValue) + default: + self = .default + } + } + + public var rawValue: Double { + switch self { + case .low: + return -1.0 + case .default: + return 0 + case .high: + return 1.0 + case .custom(let val): + return val + } + } +}