-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 not querying current
data when styles are added / removed.
#4222
Comments
As an update I hacked a Is these a recommended approach to handle this kind of situation? |
Can you please create a minimal self-contained example that demonstrates the issue? |
@jfirebaugh Ok, fixed it, here's the JSBin with the access token removed: https://jsbin.com/binawol/edit?html,js,console,output If you click the button it will output the values I pass into the You can wrap the console log part of the click handler in a
This then returns the expected results from the Hope that makes sense, shout for more info, |
@dougajmcdonald thank you for providing the example. The reason the results of your map.addLayer(...) // make your change
map.on('render', afterChangeComplete); // warning: this fires many times per second!
function afterChangeComplete () {
if (!map.loaded()) { return } // still not loaded; bail out.
// now that the map is loaded, it's safe to query the features:
map.queryRenderedFeatures(...);
map.off('render', afterChangeComplete); // remove this handler now that we're done.
} update: As @dougajmcdonald notes below, be careful to use a named function ( |
@dougajmcdonald I'm closing this issue, but if the above suggestion does not help, please feel free to contact Mapbox Support or reopen it! |
Thanks for the info, this is what I suspected. As a work around for my use case could I just query the source with the map bounds passed in? Or would I see the same kind of issue? |
@anandthakker I just wanted to add one more note to this issue. I got caught out by using either es6 fat arrow functions OR es5 bind calls when setting up a handler for the render event from inside an es6 class If you use the following:
OR
Then the handler won't be removed as JS will create an anonomous function under the hood and the |
@anandthakker I've been working with queryRenderedFeature to iterate through an array of previously undefined intersect point coordinates upon a current layer on the map. The returned feature array is intermittent and often incomplete and varies with zoom level. Am i experiencing the same issue as above. Heres an example bl.ock of whats going on. Sorry if this is a dead issue but I'm not sure where to turn. Thanks. |
Thanks to you all, Hope this helps:
|
Hey is this hack still valid? I have the same situation where I need to update a list after a filter has been set. Checking with some logs, I can see that |
I have a map which has a filter applied to a layer. We have a function
refreshFilter(filterValue)
which clears and then re-adds the filter with the new value.e.g.
This works as expected, and the features I see rendered from the GeoJson match the
sex
provided.My problem comes when I want to return from the map, the features which match my filter.
I updated the
refreshFilter
function to return the features which were visible usingqueryRenderedFeatures
but this always returns the opposite of what I'm expecting. So if pass inmale
I visually see the features which matchsex=='male'
(expected) but thequeryRenderedFeatures
function returns features which matchsex=='female'
(unexpected).Simplified version
It seems to me that the call to
queryRenderedFeatures
hasn't waited for the layers to be changed and has queried the previous set of features to work out what to return.Am I doing something wrong here? Any pointers greatly appreciated.
The text was updated successfully, but these errors were encountered: