Skip to content

Commit

Permalink
Use POI featureset for QRF if present (#7632)
Browse files Browse the repository at this point in the history
  • Loading branch information
persidskiy authored and chizhavko committed Dec 23, 2024
1 parent 6a9da27 commit 1f23096
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to the Mapbox Navigation SDK for iOS

## v3.6.0

* Improved support for tapping POI features in the Standard Style.

## v3.6.0-rc.1

### Packaging
Expand Down
24 changes: 22 additions & 2 deletions Sources/MapboxNavigationCore/Map/NavigationMapView+Gestures.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _MapboxNavigationHelpers
import Foundation
import MapboxDirections
import MapboxMaps
@_spi(Experimental) import MapboxMaps
import Turf
import UIKit

Expand Down Expand Up @@ -130,10 +130,30 @@ extension NavigationMapView {
}

private func mapPoint(at point: CGPoint) async -> MapPoint {
let options = RenderedQueryOptions(layerIds: mapStyleManager.poiLayerIds, filter: nil)
let rectSize = poiClickableAreaSize
let rect = CGRect(x: point.x - rectSize / 2, y: point.y - rectSize / 2, width: rectSize, height: rectSize)

/// POI featureset in Standard contains poi, transit, and airport labels.
/// To make sure that we can use POI featureset we check that that featureset exists,
/// and POI are not hidden via showPointOfInterestLabels.
/// After Standard Style 3.0 we can remove the `basemapPOIsAreVisible` check as
/// POI featureset will be always used.
let hasPoiFeatureset = mapView.mapboxMap.featuresets.contains { $0.converted() == .standardPoi }
let showPoiValue = try? mapView.mapboxMap.getStyleImportConfigProperty(
for: "basemap",
config: "showPointOfInterestLabels"
).value
let basemapPOIsAreVisible = showPoiValue as? Bool ?? true
if hasPoiFeatureset,
basemapPOIsAreVisible,
let features = try? await mapView.mapboxMap.queryRenderedFeatures(with: rect, featureset: .standardPoi),
let poi = features.first
{
return MapPoint(name: poi.name, coordinate: poi.coordinate)
}

let options = RenderedQueryOptions(layerIds: mapStyleManager.poiLayerIds, filter: nil)

let features = try? await mapView.mapboxMap.queryRenderedFeatures(with: rect, options: options)
if let feature = features?.first?.queriedFeature.feature,
case .string(let poiName) = feature[property: .poiName, languageCode: nil],
Expand Down
21 changes: 20 additions & 1 deletion Sources/MapboxNavigationCore/Map/Other/MapboxMap+Async.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _MapboxNavigationHelpers
import MapboxMaps
@_spi(Experimental) import MapboxMaps

extension MapboxMap {
@MainActor
Expand Down Expand Up @@ -39,6 +39,25 @@ extension MapboxMap {
state.cancel()
}
}

@MainActor
func queryRenderedFeatures<F: FeaturesetFeatureType>(
with rect: CGRect,
featureset: FeaturesetDescriptor<F>
) async throws -> [F] {
let state: CancellableAsyncState<AnyMapboxMapsCancelable> = .init()

return try await withTaskCancellationHandler {
try await withCheckedThrowingContinuation { continuation in
let cancellable = queryRenderedFeatures(with: rect, featureset: featureset) { result in
continuation.resume(with: result)
}
state.activate(with: .init(cancellable))
}
} onCancel: {
state.cancel()
}
}
}

private final class AnyMapboxMapsCancelable: CancellableAsyncStateValue {
Expand Down

0 comments on commit 1f23096

Please sign in to comment.