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

getLayer returns a layer but queryRenderedFeatures given a layer returns empty #4375

Closed
Carpetfizz opened this issue Mar 6, 2017 · 5 comments

Comments

@Carpetfizz
Copy link

I've added a few layers to the map and now I want to extract some features from it. I've made sure the layer exists by using this call

console.log(this.map.getLayer(focus_key+"-point"));

which prints:

t {id: "8b4bc65b-4f60-43fd-bcde-fa63fa936479-point", metadata: undefined, type: "circle", source: "8b4bc65b-4f60-43fd-bcde-fa63fa936479", sourceLayer: undefined…}

Right after, I want to get all the features in the layer so I'm calling:

console.log(this.map.queryRenderedFeatures({layers: [focus_key+"-point"]}));

This returns an empty array [].

How can it be that the layer exists but querying for a feature in that layer, returns empty?

@peterqliu
Copy link
Contributor

peterqliu commented Mar 6, 2017

How can it be

It can be, when:

  • the layer has no features, or
  • the layer has no features within the rendered view, at time of query

Note that queryRenderedFeatures queries for features, not layers.

@Carpetfizz Are you sure that there is a feature from that layer in the current view, when you do the query? a test case would be useful here.

@Carpetfizz
Copy link
Author

Carpetfizz commented Mar 6, 2017

I see a feature on my map, and the layer.layout.visibility=="visible"

Could it possibly be an async issue?

@jfirebaugh
Copy link
Contributor

@Carpetfizz Can you provide a minimal, self-contained example that demonstrates the issue?

@Carpetfizz
Copy link
Author

@jfirebaugh @peterqliu here's a small demo where the bug occurs:

http://codepen.io/anon/pen/XMjPwd?editors=1011

@jfirebaugh
Copy link
Contributor

Adding a layer is an asynchronous operation with respect to queryRenderedFeatures; see the discussion in #4222 and in particular #4222 (comment).

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

3 participants