Skip to content

Commit

Permalink
[GH-1440] - Refactor to clean up certain function signature. Cartfile…
Browse files Browse the repository at this point in the history
… updated.
  • Loading branch information
vincethecoder committed Jul 24, 2018
1 parent 6de1d55 commit 187fb0f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ github "Quick/Nimble" "v7.1.3"
github "Quick/Quick" "v1.3.1"
github "ceeK/Solar" "2.1.0"
github "mapbox/MapboxDirections.swift" "v0.22.0"
github "mapbox/mapbox-events-ios" "v0.4.2"
github "mapbox/mapbox-events-ios" "v0.4.3"
github "mapbox/mapbox-voice-swift" "v0.0.1"
github "mapbox/turf-swift" "v0.2.0"
github "raphaelmor/Polyline" "v4.2.0"
Expand Down
22 changes: 6 additions & 16 deletions MapboxNavigation/HighwayShield.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
struct HighwayShield {

enum textColor {
case black, white
}

enum fillColor {
case red, yellow, blue, green, white
}

enum borderColor {
case black, white
}

enum shield: String {
case `default`
enum Identifier: String {
case generic = "default"
case atMotorway = "at-motorway"
case atExpressway = "at-expressway"
case atStateB = "at-state-b"
Expand All @@ -38,7 +26,7 @@ struct HighwayShield {

func textColor() -> UIColor? {
switch self {
case .default:
case .generic:
return .black
case .atMotorway:
return .white
Expand Down Expand Up @@ -87,7 +75,7 @@ struct HighwayShield {

func fillColor() -> UIColor {
switch self {
case .default:
case .generic:
return .white
case .atMotorway:
return .blue
Expand Down Expand Up @@ -133,5 +121,7 @@ struct HighwayShield {
return .white
}
}

// TODO: borderColor
}
}
12 changes: 6 additions & 6 deletions MapboxNavigation/RouteMapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ extension RouteMapViewController: NavigationViewDelegate {
if let line = feature as? MGLPolylineFeature {
if let text = line.attribute(forKey: "ref") as? String, let shieldRawValue = line.attribute(forKey: "shield") as? String, let reflen = line.attribute(forKey: "reflen") {

let currentShield = HighwayShield.shield(rawValue: shieldRawValue)
let currentShield = HighwayShield.Identifier(rawValue: shieldRawValue)
let textColor = currentShield?.textColor()

let imageName = "\(shieldRawValue)-\(reflen)"
Expand Down Expand Up @@ -848,11 +848,11 @@ extension RouteMapViewController: NavigationViewDelegate {
let textHeight = font.lineHeight
let pointY = (shieldImage.size.height - textHeight) / 2

let compositeImage = shieldImage.insert(text: (text as NSString),
color: color ?? .black,
font: font,
atPoint: CGPoint(x: 0, y: pointY),
scale: UIScreen.main.scale)
let compositeImage = shieldImage.composited(text: (text as NSString),
color: color ?? .black,
font: font,
atPoint: CGPoint(x: 0, y: pointY),
scale: UIScreen.main.scale)

attachment.image = compositeImage

Expand Down
6 changes: 3 additions & 3 deletions MapboxNavigation/UIImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension UIImage {
return tintedImage
}

func insert(text: NSString, color: UIColor, font: UIFont, atPoint: CGPoint, scale: CGFloat) -> UIImage? {
func composited(text: NSString, color: UIColor, font: UIFont, atPoint: CGPoint, scale: CGFloat) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, scale)

let textStyle = NSMutableParagraphStyle()
Expand All @@ -22,9 +22,9 @@ extension UIImage {
let rect = CGRect(x: atPoint.x, y: atPoint.y, width: size.width, height: size.height)
text.draw(in: rect.integral, withAttributes: textFontAttributes)

let newImage = UIGraphicsGetImageFromCurrentImageContext()
let compositedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return newImage
return compositedImage
}
}

0 comments on commit 187fb0f

Please sign in to comment.