Skip to content

Commit

Permalink
Draw slight left/right lanes
Browse files Browse the repository at this point in the history
  • Loading branch information
frederoni authored and Bobby Sudekum committed Apr 2, 2018
1 parent 5829a14 commit 3e3f710
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
53 changes: 44 additions & 9 deletions MapboxNavigation/LaneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,42 @@ open class LaneView: UIView {
if lane.indications.isSuperset(of: [.straightAhead, .sharpRight]) || lane.indications.isSuperset(of: [.straightAhead, .right]) || lane.indications.isSuperset(of: [.straightAhead, .slightRight]) {
flipLane = false
if !isValid {
LanesStyleKit.drawLane_straight_right(primaryColor: appropriatePrimaryColor)
if lane.indications == .slightRight {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
} else {
LanesStyleKit.drawLane_straight_right(primaryColor: appropriatePrimaryColor)
}
alpha = invalidAlpha
} else if maneuverDirection == .straightAhead {
LanesStyleKit.drawLane_straight_only(primaryColor: appropriatePrimaryColor, secondaryColor: secondaryColor)
} else if maneuverDirection == .sharpLeft || maneuverDirection == .left || maneuverDirection == .slightLeft {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
if lane.indications == .slightLeft {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
} else {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
}
flipLane = true
} else {
LanesStyleKit.drawLane_right_only(primaryColor: appropriatePrimaryColor, secondaryColor: secondaryColor)
}
} else if lane.indications.isSuperset(of: [.straightAhead, .sharpLeft]) || lane.indications.isSuperset(of: [.straightAhead, .left]) || lane.indications.isSuperset(of: [.straightAhead, .slightLeft]) {
flipLane = true
if !isValid {
LanesStyleKit.drawLane_straight_right(primaryColor: appropriatePrimaryColor)
if lane.indications == .slightLeft {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
} else {
LanesStyleKit.drawLane_straight_right(primaryColor: appropriatePrimaryColor)
}

alpha = invalidAlpha
} else if maneuverDirection == .straightAhead {
LanesStyleKit.drawLane_straight_only(primaryColor: appropriatePrimaryColor, secondaryColor: secondaryColor)
} else if maneuverDirection == .sharpRight || maneuverDirection == .right || maneuverDirection == .slightRight {
} else if maneuverDirection == .sharpRight || maneuverDirection == .right {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
flipLane = false
} else if maneuverDirection == .slightRight {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
flipLane = false
} else {
LanesStyleKit.drawLane_right_only(primaryColor: appropriatePrimaryColor, secondaryColor: secondaryColor)
}
Expand All @@ -67,20 +83,31 @@ open class LaneView: UIView {
// Account for a configuation where there is no straight lane
// but there are at least 2 indications.
// In this situation, just draw a left/right arrow
if maneuverDirection == .sharpRight || maneuverDirection == .right || maneuverDirection == .slightRight {
if maneuverDirection == .sharpRight || maneuverDirection == .right {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
flipLane = false
} else if maneuverDirection == .slightRight {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
flipLane = false
} else {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
flipLane = true
}
alpha = isValid ? 1 : invalidAlpha
} else if lane.indications.isSuperset(of: [.sharpRight]) || lane.indications.isSuperset(of: [.right]) || lane.indications.isSuperset(of: [.slightRight]) {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
if lane.indications == .slightRight {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
} else {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
}
flipLane = false
alpha = isValid ? 1 : invalidAlpha
} else if lane.indications.isSuperset(of: [.sharpLeft]) || lane.indications.isSuperset(of: [.left]) || lane.indications.isSuperset(of: [.slightLeft]) {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
if lane.indications == .slightLeft {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
} else {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
}
flipLane = true
alpha = isValid ? 1 : invalidAlpha
} else if lane.indications.isSuperset(of: [.straightAhead]) {
Expand All @@ -95,10 +122,18 @@ open class LaneView: UIView {
// If the lane indication is `none` and the maneuver modifier has a turn in it,
// show the turn in the lane image.
if maneuverDirection == .sharpRight || maneuverDirection == .right || maneuverDirection == .slightRight {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
if maneuverDirection == .slightRight {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
} else {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
}
flipLane = false
} else if maneuverDirection == .sharpLeft || maneuverDirection == .left || maneuverDirection == .slightLeft {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
if maneuverDirection == .slightLeft {
LanesStyleKit.drawLane_slight_right(primaryColor: appropriatePrimaryColor)
} else {
LanesStyleKit.drawLane_right_h(primaryColor: appropriatePrimaryColor)
}
flipLane = true
} else {
LanesStyleKit.drawLane_straight(primaryColor: appropriatePrimaryColor)
Expand Down
11 changes: 10 additions & 1 deletion MapboxNavigationTests/LaneTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import XCTest
import FBSnapshotTestCase
import MapboxDirections
@testable import MapboxDirections
@testable import MapboxNavigation
@testable import MapboxCoreNavigation

Expand Down Expand Up @@ -43,4 +43,13 @@ class LaneTests: FBSnapshotTestCase {
func testRightNone() {
assertLanes(step: steps[1])
}

func testSlightRight() {
let view = LaneView(frame: CGRect(origin: .zero, size: CGSize(width: 30, height: 30)))
view.backgroundColor = .white
view.lane = Lane(indications: [.slightRight])
view.maneuverDirection = .slightRight
view.isValid = true
FBSnapshotVerifyView(view)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3e3f710

Please sign in to comment.