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

No way to get features that are displayed on the screen #736

Open
goleary opened this issue Dec 4, 2019 · 3 comments
Open

No way to get features that are displayed on the screen #736

goleary opened this issue Dec 4, 2019 · 3 comments

Comments

@goleary
Copy link

goleary commented Dec 4, 2019

TANGRAM VERSION:
0.19.1

ENVIRONMENT:

Windows 10 firefox

TO REPRODUCE THE ISSUE, FOLLOW THESE STEPS:

  let layer = Tangram.leafletLayer({
    scene: scene_obj,
    leaflet: L});

  let scene = layer.scene;
  let features = await  scene.queryFeatures();

RESULT:

The above code results in an array of features stored in features that includes features that are not visible on the screen

EXPECTED RESULT:

I'd hope there is a way to get a list of all features which are shown on the map so that I can display some stats/metrics alongside the map without confusing the user by talking about features of the screen. I understand that scene.queryFeatures(...) returns features in the tiles that are used to render the currently visible map which often includes features that are not actually shown on the screen. Is there some other way of accomplishing this?

@bcamper
Copy link
Member

bcamper commented Dec 4, 2019

You can do scene.queryFeatures({ visible: true }) to get only the features that were rendered. However, this includes all features in tiles intersecting the viewport that matched layers/styling and were rendered by WebGL -- it does not account for viewport culling, so it will include features in tiles that are only partially visible on screen. No way around that at the moment.

You can also do scene.queryFeatures({ visible: false }) if you want a list of features that didn't match styling.

See https://tangrams.readthedocs.io/en/latest/API-Reference/Javascript-API/#queryfeatures.

@bcamper bcamper closed this as completed Dec 4, 2019
@goleary
Copy link
Author

goleary commented Dec 4, 2019

I've looked through the docs extensively and tried using visible but as you mention, it doesn't solve my problem (I get features that are out of view). I see you closed the issue, is there somewhere else to log feature requests?

Do y'all plan to support this at some point in the future?

@bcamper
Copy link
Member

bcamper commented Dec 4, 2019

Sorry, you're right, this should be open as a feature request.

That said, it's not straightforward to add as requested. It probably requires some form of ray-casting outside of the WebGL rendering pipeline, but that's a lot of code for this specific feature, and the engine currently discards the geometry CPU-side for memory/performance reasons. I can think of a potential approach that only includes things that are "truly" visible (based on the rendered framebuffer), meaning it would not include features occluded by other objects (behind buildings) or discarded by collision detection. That's useful in its own right, but has a different set of trade-offs.

@bcamper bcamper reopened this Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants