diff --git a/CHANGELOG.md b/CHANGELOG.md index 18ef392..44d784d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/CHANGELOG_UNRELEASED.md b/CHANGELOG_UNRELEASED.md index 8b13789..df0df51 100644 --- a/CHANGELOG_UNRELEASED.md +++ b/CHANGELOG_UNRELEASED.md @@ -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 diff --git a/SitumWayfinding/Classes/Positioning/Internal/MarkerRenderer.swift b/SitumWayfinding/Classes/Positioning/Internal/MarkerRenderer.swift index fa841c2..0bc81e0 100644 --- a/SitumWayfinding/Classes/Positioning/Internal/MarkerRenderer.swift +++ b/SitumWayfinding/Classes/Positioning/Internal/MarkerRenderer.swift @@ -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 @@ -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, @@ -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) @@ -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] { @@ -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 { @@ -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 { @@ -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 @@ -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) } } diff --git a/SitumWayfinding/Classes/Positioning/PositioningViewController.swift b/SitumWayfinding/Classes/Positioning/PositioningViewController.swift index 029acd6..ac2637f 100644 --- a/SitumWayfinding/Classes/Positioning/PositioningViewController.swift +++ b/SitumWayfinding/Classes/Positioning/PositioningViewController.swift @@ -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") } } }