-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 result sort #6266
Comments
From the docs for
Regarding "topmost rendered feature" see also #6184 (comment) :
|
@pathmapper Thanks for the clarification ! So if the order depend only on the initial rendering order of features, is there a way using the API to get the prominent feature in that feature array ? |
@theochampion I'm very sure this isn't possible. The "prominent feature" is also dependent on how you are defining prominent, because the term itself is not distinct. E.g for a polygon it could be the area or the length of the boundary or something else. I don't know your specific data and use case, but maybe you are able to calculate your "prominent value" beforehand (e.g. calculate the area of the polygons) and include it in the feature properties to be able to sort (with JavaScript) the array returned by Or you could calculate such a value at runtime with Turf.js for the features in your returned array. |
@pathmapper By prominent I mean prominent by area in the bounding box an the use case is to get which city the user is probably looking at even if it isn't perfectly hovering it. I will look at TurfJs and make a few benchmark for the solution I come up with as this need to be fast (onMove handler) ;) |
Hi @theochampion, thanks for using Mapbox! As @pathmapper indicated, there's already a specific sort order for Using Turf for finding the area of a polygon should be pretty fast, but it will depend on the number of sides in the polygon. If it proves to be too slow, you could try either simplifying your polygons, or else precomputing the area and attaching it as a property to each feature. |
mapbox-gl@0.44.0:
I'm experimenting with
queryRenderedFeatures
to select the feature currently prominent in view. I noticed that the resulting features correspond well to what is in the bounding box but are not sorted by prominence and wondered if this is normal behaviour.Steps to Trigger Behavior
queryRenderedFeatures
with a bounding box(here i'm using a bounding box from the center of the map)
queryRenderedFeature
with this bounding box on a layer sourced from GEOjson data that highlight cities (in darker pink in my example).features[0]
) to show what is selected(here the bounding box is represented by the gray square and the selected feature is the one with dotted borders)
![screen shot 2018-03-02 at 10 13 28](https://user-images.githubusercontent.com/14275989/36891572-675e36ae-1e02-11e8-90de-119dea1099c6.png)
Expected Behavior
The first feature in the result array is the one prominent in the bounding box
Actual Behavior
The first feature in the result array is not the one prominent in the bounding box
The text was updated successfully, but these errors were encountered: