-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Unable to get results from querySourceFeatures() #13983
Comments
As an added data point, I copied the code from this example to create another test but am getting the same result:
Still gives me an empty array. |
Hey @Yermo, I think your issue might be connected with a fact, that the renderer is asynchronous. What this means is, that whenever you update the map, the work is switched to a GL thread that processes and renders the data. Having above in mind, when you update the map and try to query it right away, the data might not be ready and rendered yet. To work around this, you can use the In general, queries are better suited for external interaction or as a reaction to new data rather than initialization flow. Let us know if this helps! |
Oh. I see. I had been under the impression that Sources were just data in the background. That makes sense. I will give that a try. In my original code, I was trying to use querySourceFeatures() after the line had been drawn in an event callback. Is my understanding of how to draw an animated line correct? Get the sources. Get the geometry. Update the geometry with a new point. After that is there anything else I need to do? (Currently I am deleting and redrawing the entire line which is quite wasteful when there are many points.) |
Yes, you need to call the |
Ah. Thank you for all the time you've taken to answer my questions. I greatly appreciate it. |
I am trying to get querySourceFeatures() working on a GeoJSON Source in a NativeScript app with the intention of drawing an animated line by updating the underlying line geometry.
I posted issue #13972 because the documentation is not clear. I attempted to implement the suggestion posted in that issue but there is still something that I am missing. I am still getting an empty array.
To eliminate the possibility that there's some NativeScript bridge/marshalling issue, I decided to try to get querySourceFeatures() to work directly in Java.
I was unable to get the Mapbox-Android-Demo to compile so I have created a fresh Java project following the getting started tutorial.
Working with the Draw a GeoJSON Line example as a base, after quite a bit of trial and error, I have successfully gotten a geojson line to draw on the map.
The reason that I want to query the source of the GeoJSON line is that I want to update it as I get new locations for the user thereby drawing a nice animated line of the user's track on the map.
My understanding is that I have to query the underlying source, get the feature, add the point to the feature geometry, and ... the line should redraw with the additional point?
Just in case it's relevant I'm using the following GeoJSON:
to load the GeoJSON asset I am using this method I ripped off from one of the examples:
What am I doing incorrectly?
The text was updated successfully, but these errors were encountered: