Skip to content

Commit 77f8bf5

Browse files
authored
Fix the building highlighting loss after out of map boundary and rerouting (#4034)
1 parent 8ca2312 commit 77f8bf5

File tree

8 files changed

+57
-30
lines changed

8 files changed

+57
-30
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* Fixed the issue where the route line endpoint is ahead of user location indicator on short straight-line route step when `NavigationViewController.routeLineTracksTraversal` enabled in active navigation. ([#3992](https://github.com/mapbox/mapbox-navigation-ios/pull/3992))
1919
* Added the ability to provide duration and completion handler while visualizing routes using `NavigationMapView.showcase(_:animated:duration:completion:)`. ([#4022](https://github.com/mapbox/mapbox-navigation-ios/pull/4022))
2020
* Fixed an issue where the maneuver arrow is not removed after arriving to the final destination. ([#4040](https://github.com/mapbox/mapbox-navigation-ios/pull/4040))
21+
* Fixed an issue where the destination building is not highlighted after rerouting. ([#4034](https://github.com/mapbox/mapbox-navigation-ios/pull/4034))
22+
* Fixed an issue where the incorrect destination building is highlighted after panning the correct building off screen. ([#4034](https://github.com/mapbox/mapbox-navigation-ios/pull/4034))
2123

2224
### CarPlay
2325

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
B4319F2F27A35EA8005A706E /* SpriteRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4319F2E27A35EA8005A706E /* SpriteRepository.swift */; };
339339
B44177F82649B08400781319 /* UserLocationStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B44177F72649B08400781319 /* UserLocationStyle.swift */; };
340340
B443A48B27BB0CB8000AF101 /* sprite-info.json in Resources */ = {isa = PBXBuildFile; fileRef = B443A48A27BB0CB8000AF101 /* sprite-info.json */; };
341+
B44E1A802891DD350093743C /* CLLocationCoordinate2D.swift in Sources */ = {isa = PBXBuildFile; fileRef = B44E1A7F2891DD350093743C /* CLLocationCoordinate2D.swift */; };
341342
B456A8C12620C9C300FD86D8 /* MMEEventsManager+Spy.h in Headers */ = {isa = PBXBuildFile; fileRef = B456A8B82620C9C000FD86D8 /* MMEEventsManager+Spy.h */; settings = {ATTRIBUTES = (Public, ); }; };
342343
B456A8D22620C9C700FD86D8 /* MMEEventsManager+Spy.m in Sources */ = {isa = PBXBuildFile; fileRef = B456A8B72620C9C000FD86D8 /* MMEEventsManager+Spy.m */; };
343344
B456A8EC2620D26B00FD86D8 /* LeakTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B456A8EB2620D26A00FD86D8 /* LeakTest.swift */; };
@@ -932,6 +933,7 @@
932933
B4319F2E27A35EA8005A706E /* SpriteRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpriteRepository.swift; sourceTree = "<group>"; };
933934
B44177F72649B08400781319 /* UserLocationStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserLocationStyle.swift; sourceTree = "<group>"; };
934935
B443A48A27BB0CB8000AF101 /* sprite-info.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "sprite-info.json"; sourceTree = "<group>"; };
936+
B44E1A7F2891DD350093743C /* CLLocationCoordinate2D.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLLocationCoordinate2D.swift; sourceTree = "<group>"; };
935937
B456A8B72620C9C000FD86D8 /* MMEEventsManager+Spy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "MMEEventsManager+Spy.m"; path = "include/MMEEventsManager+Spy.m"; sourceTree = "<group>"; };
936938
B456A8B82620C9C000FD86D8 /* MMEEventsManager+Spy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "MMEEventsManager+Spy.h"; path = "include/MMEEventsManager+Spy.h"; sourceTree = "<group>"; };
937939
B456A8EB2620D26A00FD86D8 /* LeakTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LeakTest.swift; sourceTree = "<group>"; };
@@ -1963,6 +1965,7 @@
19631965
3A8187C824BDAE9C00708F19 /* URLSession.swift */,
19641966
11D1F89F2696048D0053A93F /* Dictionary+DeepMerge.swift */,
19651967
8AC85EA328628E4F003F8FC8 /* UIDevice.swift */,
1968+
B44E1A7F2891DD350093743C /* CLLocationCoordinate2D.swift */,
19661969
);
19671970
name = Extensions;
19681971
sourceTree = "<group>";
@@ -3026,6 +3029,7 @@
30263029
35C77F621FE8219900338416 /* NavigationSettings.swift in Sources */,
30273030
41B901EB271048BD007F9F78 /* HistoryRecording.swift in Sources */,
30283031
DA5F44C825F07AB700F573EC /* MapboxStreetsRoadClass.swift in Sources */,
3032+
B44E1A802891DD350093743C /* CLLocationCoordinate2D.swift in Sources */,
30293033
2B5A4AC728099FA900170A2B /* AlternativeRoute.swift in Sources */,
30303034
2E50E0C0264E35CA009D3848 /* RoadObjectMatcher.swift in Sources */,
30313035
C51DF8661F38C31C006C6A15 /* Locale.swift in Sources */,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Foundation
2+
import CoreLocation
3+
4+
extension CLLocationCoordinate2D: Hashable {
5+
public func hash(into hasher: inout Hasher) {
6+
hasher.combine(latitude)
7+
hasher.combine(longitude)
8+
}
9+
10+
static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
11+
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
12+
}
13+
}

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,15 @@ extension RouteController: ReroutingControllerDelegate {
930930
}
931931

932932
func rerouteControllerDidRecieveReroute(_ rerouteController: RerouteController, response: RouteResponse, options: RouteOptions, routeOrigin: RouterOrigin) {
933+
// The response and options after reroute lost waypoint targetCoordinate.
934+
if response.waypoints?.count == routeProgress.routeOptions.waypoints.count,
935+
options.waypoints.count == routeProgress.routeOptions.waypoints.count {
936+
for (index, previousWayoint) in routeProgress.routeOptions.waypoints.enumerated() {
937+
response.waypoints?[index].targetCoordinate = previousWayoint.targetCoordinate
938+
options.waypoints[index].targetCoordinate = previousWayoint.targetCoordinate
939+
}
940+
}
941+
933942
let indexedRouteResponse = IndexedRouteResponse(routeResponse: response,
934943
routeIndex: 0,
935944
responseOrigin: routeOrigin)

Sources/MapboxNavigation/CGPoint.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ extension CGPoint {
77
public func distance(to: CGPoint) -> CGFloat {
88
return sqrt((self.x - to.x) * (self.x - to.x) + (self.y - to.y) * (self.y - to.y))
99
}
10+
11+
// `MapView.mapboxMap.point(for:)` will return the point if the coordinate is outside of the `MapView` bounds.
12+
static let pointOutOfMapViewBounds = CGPoint(x: -1.0, y: -1.0)
1013
}

Sources/MapboxNavigation/NavigationMapView+BuildingHighlighting.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ extension NavigationMapView {
2323
in3D extrudesBuildings: Bool = true,
2424
extrudeAll: Bool = false,
2525
completion: ((_ foundAllBuildings: Bool) -> Void)? = nil) {
26-
var foundBuildingIds = Set<Int64>()
26+
highlightedBuildingIdentifiersByCoordinate = highlightedBuildingIdentifiersByCoordinate.filter{ coordinates.contains($0.key) }
2727
let group = DispatchGroup()
2828
let identifiers = mapView.mapboxMap.style.allLayerIdentifiers
2929
.compactMap({ $0.id })
3030
.filter({ $0.contains("building") })
3131
let layerPosition = identifiers.last.map { LayerPosition.above($0) }
3232

33-
coordinates.forEach {
34-
group.enter()
33+
for coordinate in coordinates {
34+
let screenCoordinate = mapView.mapboxMap.point(for: coordinate)
35+
if screenCoordinate == .pointOutOfMapViewBounds {
36+
continue
37+
}
3538

36-
let screenCoordinate = mapView.mapboxMap.point(for: $0)
39+
group.enter()
3740
let options = RenderedQueryOptions(layerIds: identifiers, filter: nil)
3841

3942
mapView.mapboxMap.queryRenderedFeatures(with: screenCoordinate,
@@ -43,29 +46,31 @@ extension NavigationMapView {
4346
group.leave()
4447
}
4548

46-
guard let _ = self else { return }
49+
guard let self = self else { return }
4750

4851
if case .success(let queriedFeatures) = result {
4952
if let identifier = queriedFeatures.first?.feature.featureIdentifier {
50-
foundBuildingIds.insert(identifier)
53+
self.highlightedBuildingIdentifiersByCoordinate[coordinate] = identifier
5154
}
5255
}
5356
})
5457
}
5558

56-
group.notify(queue: DispatchQueue.main) {
57-
self.addBuildingsLayer(with: foundBuildingIds,
59+
group.notify(queue: DispatchQueue.main) { [weak self] in
60+
guard let self = self else { return }
61+
self.addBuildingsLayer(with: Set(self.highlightedBuildingIdentifiersByCoordinate.values),
5862
in3D: extrudesBuildings,
5963
extrudeAll: extrudeAll,
6064
layerPosition: layerPosition)
61-
completion?(foundBuildingIds.count == coordinates.count)
65+
completion?(self.highlightedBuildingIdentifiersByCoordinate.keys.count == coordinates.count)
6266
}
6367
}
6468

6569
/**
6670
Removes the highlight from all buildings highlighted by `highlightBuildings(at:in3D:completion:)`.
6771
*/
6872
public func unhighlightBuildings() {
73+
highlightedBuildingIdentifiersByCoordinate.removeAll()
6974
let identifier = NavigationMapView.LayerIdentifier.buildingExtrusionLayer
7075

7176
do {
@@ -90,18 +95,15 @@ extension NavigationMapView {
9095
highlightedBuildingsLayer.source = "composite"
9196
highlightedBuildingsLayer.sourceLayer = "building"
9297

93-
let extrudeExpression: Expression = Exp(.eq) {
94-
Exp(.get) {
95-
"extrude"
96-
}
97-
"true"
98-
}
99-
10098
if extrudeAll {
101-
highlightedBuildingsLayer.filter = extrudeExpression
99+
highlightedBuildingsLayer.filter = Exp(.eq) {
100+
Exp(.get) {
101+
"extrude"
102+
}
103+
"true"
104+
}
102105
} else {
103106
highlightedBuildingsLayer.filter = Exp(.all) {
104-
extrudeExpression
105107
Exp(.inExpression) {
106108
Exp(.id)
107109
Exp(.literal) {

Sources/MapboxNavigation/NavigationMapView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,11 @@ open class NavigationMapView: UIView {
896896
*/
897897
var mostRecentUserCourseViewLocation: CLLocation?
898898

899+
/**
900+
The coordinates and corresponding identifiers for highlight buildings.
901+
*/
902+
var highlightedBuildingIdentifiersByCoordinate = [CLLocationCoordinate2D: Int64]()
903+
899904
func setupUserLocation() {
900905
if !isAuthorized() { return }
901906

@@ -1017,7 +1022,7 @@ open class NavigationMapView: UIView {
10171022
animated: Bool = false) {
10181023
// If the point is outside of the bounds of `MapView` - hide user course view.
10191024
let point = mapView.mapboxMap.point(for: location.coordinate)
1020-
if point.x == -1.0 && point.y == -1.0 {
1025+
if point == .pointOutOfMapViewBounds {
10211026
userCourseView.isHidden = true
10221027
return
10231028
} else {

Tests/MapboxNavigationTests/NavigationViewControllerTests.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,17 +529,6 @@ extension NavigationViewControllerTests: NavigationViewControllerDelegate, Style
529529
}
530530
}
531531

532-
extension CLLocationCoordinate2D: Hashable {
533-
public func hash(into hasher: inout Hasher) {
534-
hasher.combine(latitude)
535-
hasher.combine(longitude)
536-
}
537-
538-
static func == (lhs: CLLocationCoordinate2D, rhs: CLLocationCoordinate2D) -> Bool {
539-
return lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude
540-
}
541-
}
542-
543532
extension NavigationViewControllerTests {
544533
fileprivate func location(at coordinate: CLLocationCoordinate2D) -> CLLocation {
545534
return CLLocation(coordinate: coordinate,

0 commit comments

Comments
 (0)