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

Fix bug preventing "queryRenderedFeatures" from returning all features #2647

Closed
cammanderson opened this issue Jun 1, 2016 · 12 comments
Closed
Assignees
Labels

Comments

@cammanderson
Copy link
Contributor

Hi Guys,

Love your work.

I think that we may have a bug to contribute. Something that is unexpected and unpredictable behaviour around the queryRenderedFeatures API call on map. We observe occasions where the map markers are returned, and then other occasions that they are not - despite them still being rendered and no changes to layers/sources - just moving/zooming the map.

Please see the following code pen showing the issue;
http://codepen.io/cammanderson/pen/bc7ceb108e340cb30fa524ff982e761d?editors=1010

mapbox-gl-js version: 0.19.0

Steps to Trigger Behavior

  1. Open your browser console
  2. Position the map viewport over Barcelona map marker (so it is only visible)
  3. Zoom in and out over this marker while the marker is still in view
  4. Watch the features that are console.logged/returned by the calling queryRenderedFeatures method

Expected Behavior

The console should always show the map marker for Barcelona while you zoom in and zoom out. queryRenderedFeatures should always return the markers that are rendered on screen.

Actual Behavior

There are occasions where the marker will not be returned while zooming in and out. It is like at some stages the marker is no longer present, even though it is rendered on screen at that time.

This can sometimes happen on dragging the map around, like it shows up in the top-right quadrant of the screen, but then disappears from being returned when on the bottom right. This seems to change as you move around the map.

Let me know if my example has errors, if so, it's been a long day sorry. But I observed this on our application, then was able to reproduce this using codepen (just trying to make sure it wasn't just our code implementation in our app).

Thanks guys,
Cheers
Cam

@lucaswoj
Copy link
Contributor

lucaswoj commented Jun 1, 2016

I can confirm that queryRenderedFeatures is broken in the way you describe in this example.

I had to modify the example slightly to get it to run without crashing my browser. I added {layers: ['markers']} as a parameter to queryRenderedFeatures. http://codepen.io/lucaswoj/pen/oLgqyL

@lucaswoj lucaswoj changed the title queryRenderedFeatures fails to always return map markers on screen Fix bug preventing "queryRenderedFeatures" from returning all features Jul 29, 2016
@jasonpepper
Copy link
Contributor

I'm also affected by this bug. I took the "Highlight features within a bounding box" example, and changed it to show the bug. I find that it only happens with symbol layers and only when you change from the initial zoom level. So, with the attached program, hold down shift to drag a rectangle and you will see that only some of the points are selected (they are colored red when selected). But it only happens after you have zoomed in or out.

map.zip

sleepycat added a commit to sleepycat/old_usesthis that referenced this issue Aug 19, 2016
The idea here is that if the current bounds are contained within the
previous bounds, mapbox-gl-js still contains the data and will display
it without another server roundtrip.

The insight that springs from this is that there are two event handlers
that need to be given to the map component:
onBoundsChange: called every time the bounds change. This would be used
to update the url.

onMissingData: called when the current map bounds are outside of
previous bounds. We then have area within the map bounds for which
we need data.

These two callbacks seem to form the basis of a saner API for the map
component.

TODO: Currently we recalculate the summary, after loading data for the
current bounds. If we are now longer hitting the server for each change
of bounds, we now need to ask the map which elements of data are
currently visible and recalculate the summary based on that.

The function that does that is `queryRenderedFeatures`:

`map.queryRenderedFeatures(map.getBounds().toArray(), {layers: [ "markers" , "selected" ]})`

The problem here is that it returns nothing, duplicates or the right
thing seemingly at random.

issue: mapbox/mapbox-gl-js#2647

When that issue is resolved, revisit this.
@jmcazaux
Copy link

jmcazaux commented Sep 2, 2016

We are affected as well here.

Is there a workaround we can use until this is solved ?

@stephenlacy
Copy link

I initially thought that the issue was solved by #2988, but after upgrading I can confirm that the issue still exists.

@jasonpepper
Copy link
Contributor

This may require a different issue, but if I zoom out and features are hidden behind each other, or another layer is on top of the features from the layer I'm selecting from, the hidden features are not selected.

@benjamintd
Copy link

I ran into this bug too. From what I understand, I traced it to this tilesIn method behaving weirdly on non-integer zoom levels. This bug appears here: when points are in the right-most or bottom-most tiles, they do not get queried at intermediary zoom levels.

@lucaswoj lucaswoj added this to the Frankfurt milestone Oct 14, 2016
@1ec5
Copy link
Contributor

1ec5 commented Oct 18, 2016

Possibly related to mapbox/mapbox-gl-native#6055.

@brunoabinader
Copy link
Member

There is an issue affecting symbol feature queries that we've already fixed in GL native (see mapbox/mapbox-gl-native#6773). I'm going to port that into GL JS.

@cammanderson
Copy link
Contributor Author

Super cool issue comments. Thanks for that Bruno!
On Tue., 25 Oct. 2016 at 10:37 pm, Bruno de Oliveira Abinader <
notifications@github.com> wrote:

There is an issue affecting symbol feature queries that we've already
fixed in GL native (see mapbox/mapbox-gl-native#6773
mapbox/mapbox-gl-native#6773). I'm going to
port that into GL JS.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#2647 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAjVHoc9wNJMbzgB1QGsEvQMbM8H2Xn5ks5q3enigaJpZM4IrPy6
.

@mourner
Copy link
Member

mourner commented Oct 25, 2016

Can anyone confirm if #3459 fixes this issue?

@benjamintd
Copy link

It did for me. Thanks a lot @brunoabinader @mourner !

@brunoabinader
Copy link
Member

Thank you all - closing for now.

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

No branches or pull requests

10 participants