Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SourceQueryOptions filter does not work correctly #1947

Open
ad184hl opened this issue Apr 6, 2023 · 0 comments
Open

SourceQueryOptions filter does not work correctly #1947

ad184hl opened this issue Apr 6, 2023 · 0 comments
Labels
bug 🪲 Something is broken!

Comments

@ad184hl
Copy link

ad184hl commented Apr 6, 2023

Environment

  • Xcode version: 13-14 many versions
  • iOS version: 15-16 many versions
  • Devices affected: all tested iOS devices
  • Maps SDK Version: the most recent stable one

Observed behavior and steps to reproduce

I'd like to filter features from a source based on (some property) AND (distance within a radius).

I could not find a way to convert the point to the filter expression.

There is not much document about SourceQueryOptions in iOS SDK, and there is no example using that neither.
I've been struggling to make it work for the last few days. I've checked many iOS and GL-JS documents and stack overflow, none of them worked for me.

The code is pretty much like the one below

let coord = CLLocationCoordinate2D(xxx)
let point = Turf.Feature(geometry: Point(coord))
var sqo = SourceQueryOptions(sourceLayerIds: [xxx], 
                        filter: ["all", ["==", ["get", "SUMLEV"], 750], ["<", ["distance", GeoJSONObject.feature(point)], 100]])
mapboxMap.querySourceFeatures(for: layerAllPopStats.sourceData.sourceStrId, options: sqo) { xxxx }

However, the app would crash and the Xcode error log reads:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Value Turf.GeoJSONObject.feature(feature id: 
empty_features: ) of type __SwiftValue must be either NSNumber, NSString, NSArray, NSDictionary, NSNull'

I tried to replace GeoJSONObject.feature(point) to Turf.Point(coord) and many other values, none would work.

Standard Swift/iOS expression does not work for filter.

I also noticed the standard Swift/iOS way to define expression does not work for the filter case.
For example, if I use as simple as

let filter = Exp(.eq) {
      Exp(.get) { "SUMLEV"}
         750
      }
var sqo = SourceQueryOptions(sourceLayerIds: [xxx],  filter: filter)

It would not work, the Xcode would crash with error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Value [==, [get, SUMLEV], 750.0] of type __SwiftValue must be either NSNumber, NSString, NSArray, NSDictionary, NSNull'

But if I use

let filter: [Any] = ["==", "SUMLEV", 750]
var sqo = SourceQueryOptions(sourceLayerIds: [xxx],  filter: filter)

It would work.

The 'all' expression seems not working correctly

For example:

let filter: [Any] = ["==", "SUMLEV", 750]

will return me ~5k features;
But when I also used

let filter: [Any] = ["all", ["==", ["get", "SUMLEV"], 750], ["<", ["distance", "userPosition", "meters"], 100]]

It will return me >7k features and the result seems not correct. It returns many features have SUMLEV != 750.
So it looks like the "all" AND condition is not respected.

Expected behavior

I'd like to filter features from a source based on (some property) AND (distance within a radius).

Notes / preliminary analysis

Additional links and references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something is broken!
Projects
None yet
Development

No branches or pull requests

1 participant