mapbox-maps-ios
mapbox-maps-ios copied to clipboard
queryRenderedFeatures not returning features, result is empty
I want to query features in a layer but it is returning nothing.
Environment
- Xcode version: 14.3
- iOS version: iOS 14
- Devices affected: iPhone
- Maps SDK Version: 10.14.0
Observed behavior and steps to reproduce
let cameraOptions = CameraOptions(cameraState: map.mapView.mapboxMap.cameraState, anchor: nil)
let cameraBounds = map.mapView.mapboxMap.coordinateBounds(for: cameraOptions)
//create CGRect points from the camerabounds
let point1 = CLLocationCoordinate2D(latitude: cameraBounds.northwest.latitude, longitude: cameraBounds.northwest.longitude)
let point2 = CLLocationCoordinate2D(latitude: cameraBounds.northeast.latitude, longitude: cameraBounds.northeast.longitude)
let point3 = CLLocationCoordinate2D(latitude: cameraBounds.southwest.latitude, longitude: cameraBounds.southwest.longitude)
let point4 = CLLocationCoordinate2D(latitude: cameraBounds.southeast.latitude, longitude: cameraBounds.southeast.longitude)
//build the CGRect
let pointRect = map.mapView.mapboxMap.points(for: [point1, point2, point3, point4])
//layerID taken from mapbox studio style layer ID
let options = RenderedQueryOptions(layerIds: ["seating-locations"], filter: nil)
//query map layer
map.mapView.mapboxMap.queryRenderedFeatures(with: pointRect, options: options) { results in
switch results {
case .failure(let error):
print(error.localizedDescription)
case .success(let features):
print("Querying bench layer went to success object. There are \(features) features")
}
}
There are no results printing to console.
Expected behavior
Returns properties of queried features.
https://github.com/mapbox/mapbox-maps-ios/blob/69e9d106028090929340b717776c3e9f4ccb1750/Apps/Examples/Examples/All%20Examples/FeaturesAtPointExample.swift
Notes / preliminary analysis
I used the DataAPI to query the source "Seating-Locations". Data is there.
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"stsendist":"26","@computed_region_yeji_bk3q":"4","siteid":"980.0","street":"Canal Street","geocodeadd":"431 Canal Street","ntaname":"SoHo-Little Italy-Hudson Square","@computed_region_sbqj_enih":"1","comdist":"102.0","femafldt":null,"busroute":"Not Applicable","@computed_region_92fq_4b7q":"32","borocd":"102","congdist":"10","coundist":"1","latitude":"40.7229308992","borough":"Manhattan","hrcevac":"2","objectid_1":"946.0","seatingtyp":"BACKED 1.0","@computed_region_efsh_h5xi":"12076","assemdist":"66","femafldz":"AE","longitude":"-74.0066503437","crossstree":"Varick Street & Hudson Street","@computed_region_f5dn_yrer":"57","address":"431 Canal Street","boroname":"Manhattan","borocode":"1","installati":"2012-07-03T00:00:00.000","bid":"Hudson Square Connection","category":"BID"},"geometry":{"coordinates":[-74.00665,40.72293],"type":"Point"},"id":"00341ac879759708135cf75a96ab8a94"}]}%
I removed and added back the layer in studio. The data is within the map style.
Hi @szewah, thank you for writing in. From a quick look at your code, it seems to me that you are trying to get QRF of the current visible map's coordinate bounds on screen. In that case it can be as simple as
let points = [
CGPoint(x: mapView.bounds.minX, y: mapView.bounds.minY), // top-left
CGPoint(x: mapView.bounds.maxX, y: mapView.bounds.minY), // top-right
CGPoint(x: mapView.bounds.minX, y: mapView.bounds.maxY), // bottom-left
CGPoint(x: mapView.bounds.maxX, y: mapView.bounds.maxY), // bottom-right
]
mapView.mapboxMap.queryRenderedFeatures(with: points) { result in
// Handle QRF result here
}