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

queryRenderedFeatures Does Not Return Hidden Text Symbols #3744

Closed
jasonpepper opened this issue Dec 5, 2016 · 11 comments
Closed

queryRenderedFeatures Does Not Return Hidden Text Symbols #3744

jasonpepper opened this issue Dec 5, 2016 · 11 comments

Comments

@jasonpepper
Copy link
Contributor

When I call queryRenderedFeatures on vector symbols which use text, it will not return any features that are hidden due to overlapping. I would expect it to return all symbols even if they are not visible.

Example: https://jsfiddle.net/x9xjdzz9/jpb8krc3/

@peterqliu
Copy link
Contributor

peterqliu commented Dec 5, 2016

@x9xjdzz9 the way we've thought about this so far:

  • features hidden due to overlapping are not rendered
  • queryRenderedFeatures() queries only rendered features
  • therefore, queryRenderedFeatures() would not query non-rendered features, like your overlapping symbols

It sounds like you want to use querySourceFeatures.

@jasonpepper
Copy link
Contributor Author

querySourceFeatures does not allow you to specify a geometry. I need a way to query text based features based on a geometry.

@peterqliu
Copy link
Contributor

peterqliu commented Dec 6, 2016

@x9xjdzz9 if you read the documentation linked above, querySourceFeatures returns in geojson format. geojson contains the geometry type of each feature, with which you can filter accordingly.

If by "query text based features based on a geometry" you mean searching within a bounding box, you can also filter the results by whether they lie within the bounding box you desire.

@jasonpepper
Copy link
Contributor Author

@peterqliu, I was hoping to use a spatially indexed query. Right now, I'm keeping my points in a separate spatial index with which I perform my queries. But I am assuming MapBox-GL already has the points in a spatial index and uses that for queryRenderedFeatures, and so I feel that my separate index is redundant.

How can I filter the results based on a bounding box? I don't see anything about that in the API. All I see are the existential, comparison, and set membership filters in the API.

@kronick
Copy link

kronick commented Dec 6, 2016

@x9xjdzz9 You can use turf.js to do the bounding box filter: http://turfjs.org/docs/#inside or http://turfjs.org/docs/#within . It should work with the geojson objects you get fromquerySourceFeatures. Note that it's not doing any spatial indexing, so if you have your own spatial index set up that might be worthwhile to keep around if you have a lot of data.

@kronick
Copy link

kronick commented Dec 6, 2016

@x9xjdzz9 Another option is to add a second layer to your style referencing the same source that has paint: {text-opacity: 0} and layout: {text-allow-overlap: true}. Using queryRenderedFeatures() on this layer should then return all points even though they are all fully transparent on the map. This way, as you rightly assumed, you get the benefit of spatial indexing built in.

You might think of queryRenderedFeatures() more as a UI feature than a data-query feature, but it can be coerced into behaving like the latter with a trick like this.

@andrewharvey
Copy link
Collaborator

querySourceFeatures does not allow you to specify a geometry. I need a way to query text based features based on a geometry.

@x9xjdzz9 That's proposed in #3666

@jasonpepper
Copy link
Contributor Author

I can't figure out what units/projection the feature geometry coordinates are in when I call querySourceFeatures. Using a vector tile source, the feature geometry objects have coordinates like (-154.34, 80.99) for a location near the lat/lon (-77.37, 38.98).

@jfirebaugh
Copy link
Contributor

@x9xjdzz9 The result of querySourceFeatures is an array of GeoJSON Feature objects, so the coordinates are intended to be GeoJSON lon/lat pairs. If you're seeing something else, please open a ticket, preferably with code that demonstrates the issue. Thanks!

@peterqliu
Copy link
Contributor

@x9xjdzz9 note that querySourceFeatures uses the geoJSON specification (specifically, lng-lat order), and returns coordinates in world-wrapped format (i.e. 0 longitude is the same geographic location as 360, 720, etc)

@jasonpepper
Copy link
Contributor Author

Added a bug report: #4011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants