Skip to content
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

Fix bug in navigation mode #156

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ All non released changes should be in CHANGELOG_UNRELEASED.md file
- UI Improvements: Decrease the size of POI icons.
- UI Improvements: Update size, font and stroke of POI labels. The new font used is Roboto
### Fixed:
- Fixed a bug that shows an invisible nav bar if search bar is set to be hidden SITLibrarySettings and you stop positioning.
- Fixed a bug that shows an invisible nav bar if search bar is set to be hidden SITLibrarySettings and you stop positioning
- Fixed crash in POI selection when user filter POI categories or change floor
- Fixed crash in POI selection that occurs sometimes when clustering is enabled

## [0.12.0] - 2022-10-20
### Added:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@

### Fixed:
- Fixed a bug that incorrectly show POIs when user is in navigation mode when user filters POIs by category or user
changes floor
51 changes: 42 additions & 9 deletions SitumWayfinding/Classes/Positioning/Internal/MarkerRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import GoogleMapsUtils

class MarkerRenderer {
var isClusteringEnabled: Bool { return markerClustering != nil }

private(set) var markers: [SitumMarker] = []
private var mapView: GMSMapView
private var buildingManager: BuildingManager
Expand All @@ -19,7 +19,10 @@ class MarkerRenderer {

private var currentFloor: SITFloor? = nil
private var selectedPoi: SITPOI? = nil

private var isUserNavigating: Bool = false
private var destinationOfNavigation: SitumMarker? = nil
private var userCustomMarker: SitumMarker? = nil

init(
mapView: GMSMapView,
buildingManager: BuildingManager,
Expand All @@ -36,9 +39,32 @@ class MarkerRenderer {
}
self.buildingManager.addDelegate(self)
}

func displayPoiMarkers(forFloor floor: SITFloor) {

func displayMarkers(forFloor floor: SITFloor, withCustomMarker marker: SitumMarker?) {
currentFloor = floor
userCustomMarker = marker
deactivateNavigation()
displayPoiMarkers(forFloor: floor)
}

func displayMarkersWhileNavigating(forFloor floor: SITFloor, withDestination destination: SitumMarker?) {
guard let destination = destination else { return }
currentFloor = floor
activateNavigation()
destinationOfNavigation = destination
displayOnlyDestinationMarker(destination, forFloor: floor)
}

private func deactivateNavigation() {
isUserNavigating = false
destinationOfNavigation = nil
}

private func activateNavigation() {
isUserNavigating = true
}

private func displayPoiMarkers(forFloor floor: SITFloor) {
removeMarkers()
var poisInFloor = buildingManager.filterPoisByCategories().filter(by: floor)
poisInFloor = preserveSelectedPoi(pois: poisInFloor, floor: floor)
Expand All @@ -56,6 +82,10 @@ class MarkerRenderer {
}
selectMarkerIfIsSelectedPoi(marker: marker, poi: poi)
}

if let marker = userCustomMarker {
displayLongPressMarker(marker, forFloor: floor)
}
}

private func preserveSelectedPoi(pois: [SITPOI], floor: SITFloor) -> [SITPOI] {
Expand All @@ -73,14 +103,14 @@ class MarkerRenderer {
}
}

func displayLongPressMarker(_ marker: SitumMarker, forFloor floor: SITFloor) {
private func displayLongPressMarker(_ marker: SitumMarker, forFloor floor: SITFloor) {
if floor.identifier == marker.floorIdentifier {
markers.append(marker)
selectMarker(marker)
}
}

func displayOnlyDestinationMarker(_ marker: SitumMarker, forFloor floor: SITFloor) {
private func displayOnlyDestinationMarker(_ marker: SitumMarker, forFloor floor: SITFloor) {
removeMarkers()
if let markerCluster = markerClustering {
if floor.identifier == marker.floorIdentifier {
Expand Down Expand Up @@ -189,7 +219,7 @@ class MarkerRenderer {
// do not load images for markers that are not currently rendered (internal array)
// also, ensure the marker is a reference to internal array of SitumMarker
guard let marker = searchMarker(byPoi: poi) else { return }
let showPoiNames = showPoiNames
let localShowPoiNames = showPoiNames

iconsStore.obtainIconFor(category: poi.category) { items in
guard var icon = selected ? items?[1] : items?[0] else {
Expand All @@ -201,7 +231,7 @@ class MarkerRenderer {

let color = UIColor(hex: "#5b5b5bff") ?? UIColor.gray
let title = poi.name
if showPoiNames {
if localShowPoiNames {
marker.gmsMarker.icon = icon.setTitle(title: title, size: 16.0, color: color, weight: .bold)
} else {
marker.gmsMarker.icon = icon
Expand All @@ -224,7 +254,10 @@ class MarkerRenderer {

extension MarkerRenderer: BuildingManagerDelegate {
func poiFiltersByCategoriesWereUpdated() {
if let floor = currentFloor {
guard let floor = currentFloor else { return }
if isUserNavigating {
displayMarkersWhileNavigating(forFloor: floor, withDestination: destinationOfNavigation)
} else {
displayPoiMarkers(forFloor: floor)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,22 +1251,16 @@ extension PositioningViewController {
func displayMarkers(forFloor floor: SITFloor, isUserNavigating: Bool) {
guard let renderer = markerRenderer else { return }
if !isUserNavigating {
renderer.displayPoiMarkers(forFloor: floor)
if let customMarker = lastCustomMarker {
renderer.displayLongPressMarker(customMarker, forFloor: floor)
}
renderer.displayMarkers(forFloor: floor, withCustomMarker: lastCustomMarker)

// in the future selection should be encapsulated in some other class to abstract Google maps
for marker in renderer.markers {
if marker == lastSelectedMarker {
select(marker: marker)
}
if let marker = renderer.markers.first(where: { $0 == lastSelectedMarker }) {
select(marker: marker)
}
} else {
if let marker = destinationMarker {
renderer.displayOnlyDestinationMarker(marker, forFloor: floor)
} else {
Logger.logDebugMessage("Destination will not be shown becuase there is no destinationMarker selected")
renderer.displayMarkersWhileNavigating(forFloor: floor, withDestination: destinationMarker)
if destinationMarker == nil {
Logger.logDebugMessage("Destination will not be shown because there is no destinationMarker selected")
}
}
}
Expand Down