mapbox / mapbox/mapbox-maps-ios
queryRenderedFeatures() reports no features (e.g. contour) despite visible/rendered features are displayed
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
Xcode version: 15.3
iOS version: 17.5
Devices affected: iPhone OS 17.5 (21F5058e)
Maps SDK Version: V11.3.0
## Observed behavior and steps to reproduce
Pre-Condition:
Map with map style .outdoors; contour lines are displayed on map around puck.
map is not nil.
layerIdentifier are visible.
Write MapboxMap extension
`extension MapboxMap {
func getMapGroundElevation(map: MapboxMap?, loc: CLLocationCoordinate2D?) -> Double {
var elevation: Double = .zero
var cancellable: Cancelable? = nil
guard let map = map else {
return .nan
}
let layerIdentifier: [String] = ["contour-line", "contour-line-index", "contour-label", "contour", "contour labels"]
let queryOptions = RenderedQueryOptions(layerIds: layerIdentifier, filter: nil)
cancellable?.cancel()
cancellable = map.queryRenderedFeatures(with: map.point(for: loc), options: queryOptions) { result in
cancellable = nil
guard let queryResult = try? MapboxView.QueryResult (
features: result.get(),
coordinate: loc) else {
return
}
// At this point: queryResult.features is always empty
}
return elevation
}
}`
Action:
Call getMapGroundElevation(...) from within SwiftUI map with parameter loc: CLLocationCoordinate2D? = puck location or
map.cameraState.center
Observed:
queryResult.features is always empty
**------ UPDATE -------
When panning the map or scrolling the map (also due to moving puck and puck follow), the rendering of features is triggered, leading to search results from layers as defined in layerIdentifier. This means that the rendered features search area around the specified search location (loc) is pretty narrow. One needs to put the expected map feature more or less in the search area to produce a matched feature search result. All be it, the expected map feature is already visible on the map before panning/zooming!**
Expected:
queryResult.features is not empty, but delivers map features especially rendered ones.
**------ REQUEST FOR A WORKAROUND -------
Please extend feature search by an alternate func (parameter) allowing search around a given 2D location in order to include thin features like contour lines and be able to catch the elevation data as long as Mapbox's elevation(at: searchLoc) does not deliver such map features**
**------ REQUEST FOR A FIX -------
The mapbox's func elevation(at: searchLoc) seems to behave similarly. Alternatively to this request, please fix the plausibility of search results for elevation(at: searchLoc) to deliver a valuable map elevation data.**
## Additional links and references
Defining the exact same getMapGroundElevation(...) func from within SwiftUI map struct leads to queryResult.features not empty.
Mapbox Version < 11 allowed to query map features by region:
`mapView.mapboxMap.queryRenderedFeatures(with: region, options: queryOptions)
`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied SwiftUI example with Mapbox Maps SDK 11.3.0, focusing on queryRenderedFeatures(with:options:) and elevation(at:). Compare results before and after panning or zooming, including the region-based query behavior from versions below 11. Done means visible contour features or useful elevation data are returned without requiring map movement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100