mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

queryRenderedFeatures() reports no features (e.g. contour) despite visible/rendered features are displayed

Open jumbopilot opened this issue 1 year ago • 1 comments

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)

jumbopilot avatar May 17 '24 14:05 jumbopilot

Any first analysis results?

jumbopilot avatar May 28 '24 08:05 jumbopilot