Skip to content

Commit

Permalink
Update the property and function names.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanMa1991 committed Oct 24, 2022
1 parent 57c8edf commit 5fe5f65
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
}

if annotatesIntersectionsAlongRoute {
navigationMapView?.updateIntersectionSignals(with: routeProgress)
navigationMapView?.updateIntersectionAnnotations(with: routeProgress)
}

navigationMapView?.updateRouteLine(routeProgress: routeProgress, coordinate: location.coordinate, shouldRedraw: legIndex != currentLegIndexMapped)
Expand Down Expand Up @@ -890,7 +890,7 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
navigationMapView?.showWaypoints(on: progress.route, legIndex: legIndex)

if annotatesIntersectionsAlongRoute {
navigationMapView?.updateIntersectionSignals(with: progress)
navigationMapView?.updateIntersectionAnnotations(with: progress)
}
}

Expand Down Expand Up @@ -1037,9 +1037,9 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
func updateIntersectionsAlongRoute() {
if annotatesIntersectionsAlongRoute {
navigationMapView?.updateIntersectionSymbolImages(styleType: styleManager?.currentStyleType)
navigationMapView?.updateIntersectionSignals(with: navigationService.routeProgress)
navigationMapView?.updateIntersectionAnnotations(with: navigationService.routeProgress)
} else {
navigationMapView?.removeIntersectionSignals()
navigationMapView?.removeIntersectionAnnotations()
}
}
}
Expand Down
24 changes: 18 additions & 6 deletions Sources/MapboxNavigation/NavigationMapView+Annotations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,20 @@ extension NavigationMapView {

// MARK: Intersection Signals Annotations


/**
Removes all the intersection annotations on current route.
*/
func removeIntersectionAnnotations() {
let style = mapView.mapboxMap.style
style.removeLayers([NavigationMapView.LayerIdentifier.intersectionAnnotationsLayer])
style.removeSources([NavigationMapView.SourceIdentifier.intersectionAnnotationsSource])
}

/**
Updates the image assets in the map style for the route intersection signals.
- parameter styleType: The `StyleType` to choose `Day` or `Night` style of icon images for route intersection signals.
*/
func updateIntersectionSymbolImages(styleType: StyleType?) {
let style = mapView.mapboxMap.style
Expand Down Expand Up @@ -428,9 +440,9 @@ extension NavigationMapView {
}
}

func updateIntersectionSignals(with routeProgress: RouteProgress) {
func updateIntersectionAnnotations(with routeProgress: RouteProgress) {
guard !routeProgress.routeIsComplete else {
removeIntersectionSignals()
removeIntersectionAnnotations()
return
}
var featureCollection = FeatureCollection(features: [])
Expand All @@ -440,15 +452,15 @@ extension NavigationMapView {
let stepIntersections = stepProgress.intersectionsIncludingUpcomingManeuverIntersection

for intersection in stepIntersections?.suffix(from: intersectionIndex) ?? [] {
if let feature = signalFeature(from: intersection) {
if let feature = intersectionFeature(from: intersection) {
featureCollection.features.append(feature)
}
}

let style = mapView.mapboxMap.style

do {
let sourceIdentifier = NavigationMapView.SourceIdentifier.intersectionSignalSource
let sourceIdentifier = NavigationMapView.SourceIdentifier.intersectionAnnotationsSource
if style.sourceExists(withId: sourceIdentifier) {
try style.updateGeoJSONSource(withId: sourceIdentifier, geoJSON: .featureCollection(featureCollection))
} else {
Expand All @@ -457,7 +469,7 @@ extension NavigationMapView {
try style.addSource(source, id: sourceIdentifier)
}

let layerIdentifier = NavigationMapView.LayerIdentifier.intersectionSignalLayer
let layerIdentifier = NavigationMapView.LayerIdentifier.intersectionAnnotationsLayer
guard !style.layerExists(withId: layerIdentifier) else { return }

var shapeLayer = SymbolLayer(id: layerIdentifier)
Expand All @@ -475,7 +487,7 @@ extension NavigationMapView {
}
}

private func signalFeature(from intersection: Intersection) -> Feature? {
private func intersectionFeature(from intersection: Intersection) -> Feature? {
var properties: JSONObject? = nil
if intersection.railroadCrossing == true {
properties = ["imageName": .string(ImageIdentifier.railroadCrossing)]
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ open class NavigationMapView: UIView {
LayerIdentifier.arrowLayer,
LayerIdentifier.arrowSymbolCasingLayer,
LayerIdentifier.arrowSymbolLayer,
LayerIdentifier.intersectionSignalLayer
LayerIdentifier.intersectionAnnotationsLayer
]
let uppermostSymbolLayers: [String] = [
LayerIdentifier.waypointCircleLayer,
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapboxNavigation/NavigationMapViewIdentifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension NavigationMapView {
static let arrowSymbolCasingLayer = "\(identifier)_arrowSymbolCasingLayer"
static let voiceInstructionLabelLayer = "\(identifier)_voiceInstructionLabelLayer"
static let voiceInstructionCircleLayer = "\(identifier)_voiceInstructionCircleLayer"
static let intersectionSignalLayer = "\(identifier)_trafficLayer"
static let intersectionAnnotationsLayer = "\(identifier)_intersectionAnnotationsLayer"
static let waypointCircleLayer = "\(identifier)_waypointCircleLayer"
static let waypointSymbolLayer = "\(identifier)_waypointSymbolLayer"
static let buildingExtrusionLayer = "\(identifier)_buildingExtrusionLayer"
Expand All @@ -26,7 +26,7 @@ extension NavigationMapView {
static let arrowStrokeSource = "\(identifier)_arrowStrokeSource"
static let arrowSymbolSource = "\(identifier)_arrowSymbolSource"
static let voiceInstructionSource = "\(identifier)_instructionSource"
static let intersectionSignalSource = "\(identifier)_trafficSource"
static let intersectionAnnotationsSource = "\(identifier)_intersectionAnnotationsSource"
static let waypointSource = "\(identifier)_waypointSource"
static let routeDurationAnnotationsSource: String = "\(identifier)_routeDurationAnnotationsSource"
static let continuousAlternativeRoutesDurationAnnotationsSource: String = "\(identifier)_continuousAlternativeRoutesDurationAnnotationsSource"
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapboxNavigation/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,9 @@ open class NavigationViewController: UIViewController, NavigationStatusPresenter
func updateIntersectionsAlongRoute() {
if annotatesIntersectionsAlongRoute {
navigationMapView?.updateIntersectionSymbolImages(styleType: styleManager?.currentStyleType)
navigationMapView?.updateIntersectionSignals(with: navigationService.routeProgress)
navigationMapView?.updateIntersectionAnnotations(with: navigationService.routeProgress)
} else {
navigationMapView?.removeIntersectionSignals()
navigationMapView?.removeIntersectionAnnotations()
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/MapboxNavigation/RouteLineController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension NavigationMapView {
}

if annotatesIntersections {
navigationMapView.updateIntersectionSignals(with: router.routeProgress)
navigationMapView.updateIntersectionAnnotations(with: router.routeProgress)
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ extension NavigationMapView {
}

if annotatesIntersections {
navigationMapView.updateIntersectionSignals(with: router.routeProgress)
navigationMapView.updateIntersectionAnnotations(with: router.routeProgress)
}
}

Expand All @@ -118,7 +118,7 @@ extension NavigationMapView {
}

if annotatesIntersections {
navigationMapView.updateIntersectionSignals(with: progress)
navigationMapView.updateIntersectionAnnotations(with: progress)
}

navigationMapView.updateRouteLine(routeProgress: progress, coordinate: location.coordinate, shouldRedraw: currentLegIndexMapped != legIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,11 @@ class NavigationViewControllerTests: TestCase {
"Failed to update the style of SpriteRepository singleton with the injected NavigationMapView.")
}

func testUpdateIntersectionSignalsAlongRouteOnMap() {
func testAnnotatesIntersectionsAlongRoute() {
let navigationViewController = navigationViewControllerMock()
let imageIdentifier = NavigationMapView.ImageIdentifier.trafficSignal
let layerIdentifier = NavigationMapView.LayerIdentifier.intersectionSignalLayer
let sourceIdentifier = NavigationMapView.SourceIdentifier.intersectionSignalSource
let layerIdentifier = NavigationMapView.LayerIdentifier.intersectionAnnotationsLayer
let sourceIdentifier = NavigationMapView.SourceIdentifier.intersectionAnnotationsSource

guard let style = navigationViewController.navigationMapView?.mapView.mapboxMap.style else {
XCTFail("Failed to get the MapView style object.")
Expand Down
10 changes: 5 additions & 5 deletions Tests/MapboxNavigationTests/RouteLineLayerPositionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class RouteLineLayerPositionTests: TestCase {
navigationMapView.showsRestrictedAreasOnRoute = false
navigationMapView.routeLineTracksTraversal = true
navigationMapView.updateIntersectionSymbolImages(styleType: .day)
navigationMapView.updateIntersectionSignals(with: routeProgress)
navigationMapView.updateIntersectionAnnotations(with: routeProgress)

expectedLayerSequence = [
buildingLayer["id"]!,
Expand All @@ -258,7 +258,7 @@ class RouteLineLayerPositionTests: TestCase {
NavigationMapView.LayerIdentifier.arrowLayer,
NavigationMapView.LayerIdentifier.arrowSymbolCasingLayer,
NavigationMapView.LayerIdentifier.arrowSymbolLayer,
NavigationMapView.LayerIdentifier.intersectionSignalLayer,
NavigationMapView.LayerIdentifier.intersectionAnnotationsLayer,
roadExitLayer["id"]!,
poiLabelLayer["id"]!,
poiLabelCircleLayer["id"]!
Expand All @@ -284,7 +284,7 @@ class RouteLineLayerPositionTests: TestCase {
layerPosition: .below(roadLabelLayer["id"]!))
navigationMapView.removeRoutes()
navigationMapView.removeArrow()
navigationMapView.removeIntersectionSignals()
navigationMapView.removeIntersectionAnnotations()

expectedLayerSequence = [
buildingLayer["id"]!,
Expand All @@ -307,7 +307,7 @@ class RouteLineLayerPositionTests: TestCase {
navigationMapView.show([multilegRoute])
navigationMapView.showsRestrictedAreasOnRoute = true
navigationMapView.routeLineTracksTraversal = false
navigationMapView.updateIntersectionSignals(with: routeProgress)
navigationMapView.updateIntersectionAnnotations(with: routeProgress)

expectedLayerSequence = [
buildingLayer["id"]!,
Expand All @@ -321,7 +321,7 @@ class RouteLineLayerPositionTests: TestCase {
NavigationMapView.LayerIdentifier.arrowLayer,
NavigationMapView.LayerIdentifier.arrowSymbolCasingLayer,
NavigationMapView.LayerIdentifier.arrowSymbolLayer,
NavigationMapView.LayerIdentifier.intersectionSignalLayer,
NavigationMapView.LayerIdentifier.intersectionAnnotationsLayer,
roadExitLayer["id"]!,
poiLabelLayer["id"]!,
poiLabelCircleLayer["id"]!,
Expand Down

0 comments on commit 5fe5f65

Please sign in to comment.