Skip to content

Commit

Permalink
Remove low-level QRF and FeaturesetQueryTarget from public API
Browse files Browse the repository at this point in the history
  • Loading branch information
persidskiy committed Nov 7, 2024
1 parent e7b4fe7 commit 1cdf682
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@
- ``MapboxMap/beginGesture()``
- ``MapboxMap/endGesture()``

### Quering map features
### Querying map features

- ``MapboxMap/queryRenderedFeatures(with:options:completion:)``
- ``MapboxMap/queryRenderedFeatures(with:targets:completion:)``
- ``MapboxMap/querySourceFeatures(for:options:completion:)``
- ``MapboxMap/querySourceFeatures(for:completion:)``
- ``MapboxMap/getGeoJsonClusterLeaves(forSourceId:feature:limit:offset:completion:)``
- ``MapboxMap/getGeoJsonClusterChildren(forSourceId:feature:completion:)``
- ``MapboxMap/getGeoJsonClusterExpansionZoom(forSourceId:feature:completion:)``
Expand Down
57 changes: 5 additions & 52 deletions Sources/MapboxMaps/Foundation/MapboxMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1061,42 +1061,11 @@ extension MapboxMap: MapFeatureQueryable {
concreteErrorType: MapError.self))
}

/// Queries the map for rendered features using featureset descriptors.
///
/// This method allows to query both featureset from imported styles and user layers in the root style.
/// The results can be additionally filtered per-featureset.
///
/// ```swift
/// let targets = [
/// FeaturesetQueryTarget(
/// featureset: .layer("my-layer"),
/// filter: Exp(.eq) {
/// Exp(.get) { "type" }
/// "hotel"
/// }
/// ),
/// FeaturesetQueryTarget(featureset: .featureset("poi", importId: "basemap"))
/// ]
/// mapView.mapboxMap.queryRenderedFeatures(with: CGPoint(x: 0, y: 0),
/// targets: targets) { result in
/// // handle features in result
/// }
/// ```
///
/// - Important: This is a low-level method. If you need to handle basic gestures on map content, please prefer to use Interactions API (see ``MapboxMap/addInteraction(_:)``) or ``MapboxMap/queryRenderedFeatures(with:featureset:filter:completion:)``.
///
/// - Parameters:
/// - geometry: A screen geometry to query. Can be a `CGPoint`, `CGRect`, or an array of `CGPoint`.
/// - targets: An array of targets to query with.
/// - completion: Callback called when the query completes.
@_spi(Experimental)
@_documentation(visibility: public)
@discardableResult
public func queryRenderedFeatures(with geometry: some RenderedQueryGeometryConvertible,
targets: [FeaturesetQueryTarget],
completion: @escaping (Result<[QueriedRenderedFeature], Error>) -> Void) -> Cancelable {
private func queryRenderedFeatures(with geometry: some RenderedQueryGeometryConvertible,
targets: [CoreFeaturesetQueryTarget],
completion: @escaping (Result<[QueriedRenderedFeature], Error>) -> Void) -> Cancelable {
return __map.__queryRenderedFeatures(for: geometry.geometry.core,
targets: targets.map(\.core),
targets: targets,
callback: coreAPIClosureAdapter(for: completion,
type: NSArray.self,
concreteErrorType: MapError.self))
Expand Down Expand Up @@ -1133,7 +1102,7 @@ extension MapboxMap: MapFeatureQueryable {
queryRenderedFeatures(
with: geometry,
targets: [
FeaturesetQueryTarget(featureset: featureset, filter: filter)
CoreFeaturesetQueryTarget(featureset: featureset.core, filter: filter?.asCore, id: nil)
]) { result in
completion(result.map({ features in
features.compactMap {
Expand Down Expand Up @@ -1187,22 +1156,6 @@ extension MapboxMap: MapFeatureQueryable {
concreteErrorType: MapError.self))
}

/// Queries the source features for a given featureset.
///
/// - Parameters:
/// - target: A featureset query target.
/// - completion: Callback called when the query completes.
@_spi(Experimental)
@_documentation(visibility: public)
@discardableResult
public func querySourceFeatures(for target: FeaturesetQueryTarget,
completion: @escaping (Result<[QueriedSourceFeature], Error>) -> Void) -> Cancelable {
return __map.__querySourceFeatures(for: target.core,
callback: coreAPIClosureAdapter(for: completion,
type: NSArray.self,
concreteErrorType: MapError.self))
}

/// Returns all the leaves (original points) of a cluster (given its cluster_id) from a GeoJSON source, with pagination support: limit is the number of leaves
/// to return (set to Infinity for all points), and offset is the amount of points to skip (for pagination).
///
Expand Down

This file was deleted.

37 changes: 0 additions & 37 deletions Sources/MapboxMaps/Interactions/FeaturesetQueryTarget.swift

This file was deleted.

45 changes: 0 additions & 45 deletions Tests/MapboxMapsTests/Foundation/FeaturesetsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,49 +232,4 @@ final class FeaturesetsTests: IntegrationTestCase {
let featureset = try XCTUnwrap(mapView.mapboxMap.featuresets.first)
XCTAssertEqual(FeaturesetDescriptor.standardPoi(importId: "nested"), featureset.converted())
}

func testLowLevelQRF() {
let coord = CLLocationCoordinate2D(latitude: 0.01, longitude: 0.01)
let point = map.point(for: coord)

let expectation = expectation(description: "Low-level QRF")

let featuresetFilter = Exp(.eq) {
Exp(.get) { "type" }
"B"
}
let layerFilter = Exp(.eq) {
Exp(.get) { "filter" }
true
}
mapView.mapboxMap.queryRenderedFeatures(
with: point,
targets: [
FeaturesetQueryTarget(featureset: .featureset("poi", importId: "nested"), filter: featuresetFilter, id: 1),
FeaturesetQueryTarget(featureset: .layer("circle-2"), filter: layerFilter, id: 2)
]) { result in
switch result {
case .success(let features):
XCTAssertEqual(features.count, 2)
XCTAssertEqual(features[safe: 0]?.queryTargets.count, 1)
XCTAssertEqual(features[safe: 0]?.queryTargets.last?.id, 2) // from circle target
XCTAssertEqual(features[safe: 0]?.queryTargets.last?.featureset, .layer("circle-2"))
XCTAssertEqual(features[safe: 0]?.queryTargets.last?.filter, nil)
XCTAssertEqual(features[safe: 0]?.queriedFeature.feature.identifier, .number(2))
XCTAssertEqual(features[safe: 0]?.queriedFeature.feature.properties?["name"]??.string, "qux")

XCTAssertEqual(features[safe: 0]?.queryTargets.count, 1)
XCTAssertEqual(features[safe: 1]?.queryTargets.last?.id, 1) // from featureset
XCTAssertEqual(features[safe: 1]?.queryTargets.last?.featureset, .featureset("poi", importId: "nested"))
XCTAssertEqual(features[safe: 1]?.queryTargets.last?.filter, nil)
XCTAssertEqual(features[safe: 1]?.queriedFeature.feature.identifier, .number(12))
XCTAssertEqual(features[safe: 1]?.queriedFeature.feature.properties?["class"]??.string, "poi")
XCTAssertEqual(features[safe: 1]?.queriedFeature.feature.properties?["name"]??.string, "nest2")
case .failure:
XCTFail("Shouldn't fail")
}
expectation.fulfill()
}
wait(for: [expectation], timeout: 1)
}
}
6 changes: 6 additions & 0 deletions scripts/api-compatibility-check/breakage_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1927,3 +1927,9 @@ Extension FeaturesetDescriptor is no longer open for subclassing

// Docs for styleGlyphURL
Var MapboxMap.styleGlyphURL is now with @_documentation

// Remove experimental FeaturesetQueryTarget
Func MapboxMap.queryRenderedFeatures(with:targets:completion:) has been removed
Func MapboxMap.querySourceFeatures(for:completion:) has been removed
Struct FeaturesetQueryTarget has been removed
Var QueriedRenderedFeature.queryTargets has been removed

0 comments on commit 1cdf682

Please sign in to comment.