-
Notifications
You must be signed in to change notification settings - Fork 312
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
Retrieve additional map attributes to display reliable current road name. #1576
Merged
vincethecoder
merged 24 commits into
master
from
navigation/reliable_current_roadname_label
Aug 2, 2018
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fdd18cd
[GH-1440] - WIP Created a Highway shield struct to contain all the de…
vincethecoder 48f8e59
[GH-1440] - Added TextPresenter which permits images to contain texts.
vincethecoder cb4976e
[GH-1440] - Modify styles to contain an attributed text.
vincethecoder 7874ada
[GH-1440] - Modify styles to contain an attributed text.
vincethecoder 6de1d55
[GH-1440] - Added function to insert a text in the current image.
vincethecoder 187fb0f
[GH-1440] - Refactor to clean up certain function signature. Cartfile…
vincethecoder 776eda8
[GH-1440] - Deleted un-used fill color added to the highway shield st…
vincethecoder 4a0938a
[GH-1440] - WIP - Struct to handle the parsing of highway shield icons.
vincethecoder 0907c18
[GH-1440] - Modified the highway shield with concise enum variations.…
vincethecoder ab7cd59
[GH-1440] - Modified the highway shield with concise enum variations.…
vincethecoder 254b832
Merge branch 'navigation/reliable_current_roadname_label' of github.c…
vincethecoder 2494cc6
[GH-1440] - Refactored the closures for locale and locale with road c…
vincethecoder afc19bf
[GH-1440] - Renamed the insert method in the uiimage extension.
vincethecoder 5c15b03
[GH-1440] - Bolden the text of the system font centered text in the h…
vincethecoder a5d75bf
[GH-1440] - Added missing enum types.
vincethecoder 795f553
[GH-1440] - Added convenience initializer to handle the composition o…
vincethecoder a76fafd
[GH-1440] - Refactored the logic that retrieves the shield name from …
vincethecoder 32942de
[GH-1440] - Minor clean up.
vincethecoder 0926a42
[GH-1440] - Refactor to retrieve the data for shield and names for th…
vincethecoder d33a3b9
[GH-1440] - Minor clean up - removed extra spaces.
vincethecoder 12f9954
[GH-1440] - Minor clean up - refactored variable names.
vincethecoder 5deaa9f
Merge branch 'master' into navigation/reliable_current_roadname_label
vincethecoder aedb833
[GH-1440] - Updates to include the road name when the road shield is …
vincethecoder efbbb5a
[GH-1440] - Minor refactor, to keep things aligned.
vincethecoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
struct HighwayShield { | ||
|
||
enum RoadClass: String { | ||
case alternate, duplex, business, truck, bypass, b | ||
case oneB = "1b", twoA = "2a", twoB = "2b" | ||
} | ||
|
||
enum RoadType: RawRepresentable { | ||
typealias RawValue = String | ||
typealias RoadTypeForLocaleRoadClassClosure = (Locale, RoadClass?) -> RoadType | ||
typealias RoadTypeForLocaleClosure = (Locale) -> RoadType | ||
|
||
var rawValue: String { | ||
switch self { | ||
case .generic: | ||
return "generic" | ||
case let .motorway(locale): | ||
return "\(locale.rawValue)-motorway" | ||
case let .expressway(locale): | ||
return "\(locale.rawValue)-expressway" | ||
case let .state(locale, roadClass): | ||
guard let currentRoadClass = roadClass else { return "\(locale)-state" } | ||
return "\(locale.rawValue)-state-\(currentRoadClass.rawValue)" | ||
case let .highway(locale, roadClass): | ||
guard let currentRoadClass = roadClass else { return "\(locale)-highway" } | ||
return "\(locale.rawValue)-highway-\(currentRoadClass.rawValue)" | ||
case let .national(locale): | ||
return "\(locale.rawValue)-national" | ||
case let .federal(locale): | ||
return "\(locale.rawValue)-federal" | ||
case let .main(locale): | ||
return "\(locale.rawValue)-main" | ||
case let .road(locale): | ||
return "\(locale.rawValue)-road" | ||
case let .primary(locale): | ||
return "\(locale.rawValue)-primary" | ||
case let .secondary(locale): | ||
return "\(locale.rawValue)-secondary" | ||
case let .trunk(locale): | ||
return "\(locale.rawValue)-trunk" | ||
case let .regional(locale): | ||
return "\(locale.rawValue)-regional" | ||
case let .voivodeship(locale): | ||
return "\(locale.rawValue)-voivodeship" | ||
case let .county(locale): | ||
return "\(locale.rawValue)-county" | ||
case let .communal(locale): | ||
return "\(locale)-communal" | ||
case let .interstate(locale, roadClass): | ||
guard let currentRoadClass = roadClass else { return "\(locale.rawValue)-interstate"} | ||
return "\(locale.rawValue)-interstate-\(currentRoadClass.rawValue)" | ||
case let .metropolitan(locale): | ||
return "\(locale.rawValue)-metropolitan" | ||
case let .provincial(locale): | ||
return "\(locale.rawValue)-provincial" | ||
} | ||
} | ||
|
||
init?(rawValue: RawValue) { | ||
let fields = rawValue.split(separator: "-").compactMap(String.init(_:)) | ||
switch fields.count { | ||
case 1 where rawValue == "default": | ||
self = .generic | ||
case 2: | ||
guard let roadType = RoadType.type(for: fields.last!), | ||
let locale = Locale(rawValue: fields.first!) else { | ||
return nil | ||
} | ||
self = roadType(locale, nil) | ||
case 3: | ||
guard let roadType = RoadType.type(for: fields[1]), | ||
let locale = Locale(rawValue: fields[0]), let roadClass = RoadClass(rawValue: fields[2]) else { | ||
return nil | ||
} | ||
self = roadType(locale, roadClass) | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
private static func type(for identifier: String) -> RoadTypeForLocaleRoadClassClosure? { | ||
switch identifier { | ||
case "motorway": | ||
return localeOnlyTransform(RoadType.motorway) | ||
case "expressway": | ||
return localeOnlyTransform(RoadType.expressway) | ||
case "national": | ||
return localeOnlyTransform(RoadType.national) | ||
case "federal": | ||
return localeOnlyTransform(RoadType.federal) | ||
case "main": | ||
return localeOnlyTransform(RoadType.main) | ||
case "road": | ||
return localeOnlyTransform(RoadType.road) | ||
case "primary": | ||
return localeOnlyTransform(RoadType.primary) | ||
case "secondary": | ||
return localeOnlyTransform(RoadType.secondary) | ||
case "trunk": | ||
return localeOnlyTransform(RoadType.trunk) | ||
case "regional": | ||
return localeOnlyTransform(RoadType.regional) | ||
case "voivodeship": | ||
return localeOnlyTransform(RoadType.voivodeship) | ||
case "county": | ||
return localeOnlyTransform(RoadType.county) | ||
case "communal": | ||
return localeOnlyTransform(RoadType.communal) | ||
case "provincial": | ||
return localeOnlyTransform(RoadType.provincial) | ||
case "metropolitan": | ||
return localeOnlyTransform(RoadType.metropolitan) | ||
case "state": | ||
return RoadType.state | ||
case "highway": | ||
return RoadType.highway | ||
case "interstate": | ||
return RoadType.interstate | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
static func localeOnlyTransform(_ closure: @escaping RoadTypeForLocaleClosure) -> RoadTypeForLocaleRoadClassClosure { | ||
return { locale, _ in | ||
return closure(locale) | ||
} | ||
} | ||
|
||
var textColor: UIColor? { | ||
switch self { | ||
case let .highway(locale, _): | ||
if locale == .slovakia { | ||
return .white | ||
} | ||
return .black | ||
case .generic, .communal, .voivodeship, .trunk, .primary, .secondary: | ||
return .black | ||
case .motorway, .expressway, .road, .interstate: | ||
return .white | ||
case let .state(locale, roadClass): | ||
switch locale { | ||
case .austria, .croatia, .newZealand, | ||
.serbia where roadClass == RoadClass.oneB: | ||
return .white | ||
default: | ||
return .black | ||
} | ||
case .regional, .metropolitan, .provincial: | ||
return .yellow | ||
case let .county(locale): | ||
if locale == .romania { | ||
return .white | ||
} | ||
return .black | ||
case let .main(locale): | ||
if locale == .slovenia { | ||
return .black | ||
} | ||
return .white | ||
case let .national(locale): | ||
switch locale { | ||
case .southAfrica: | ||
return .yellow | ||
case .poland, .romania, .greece, .bulgeria: | ||
return .white | ||
default: | ||
return .black | ||
} | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
case generic, motorway(Locale), expressway(Locale), state(Locale, RoadClass?), highway(Locale, RoadClass?) | ||
case national(Locale), federal(Locale), main(Locale), road(Locale), primary(Locale), secondary(Locale), trunk(Locale), regional(Locale) | ||
case voivodeship(Locale), county(Locale), communal(Locale), interstate(Locale, RoadClass?), metropolitan(Locale), provincial(Locale) | ||
} | ||
|
||
enum Locale: String { | ||
case austria = "at", bulgeria = "bg", brazil = "br", switzerland = "ch", czech = "cz", germany = "de", denmark = "dk", finland = "fi", greece = "gr", croatia = "hr", hungary = "hu", india = "in", mexico = "mx", newZealand = "nz", peru = "pe", poland = "pl", romania = "ro", serbia = "rs", sweden = "se", slovenia = "si", slovakia = "sk", usa = "us", southAfrica = "za", e | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've already pulled this value out above. See if you can combine these if let statements.