tangram icon indicating copy to clipboard operation
tangram copied to clipboard

No way to get features that are displayed on the screen

Open goleary opened this issue 5 years ago • 3 comments
trafficstars

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?

goleary avatar Dec 04 '19 00:12 goleary

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 avatar Dec 04 '19 00:12 bcamper

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?

goleary avatar Dec 04 '19 01:12 goleary

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 avatar Dec 04 '19 01:12 bcamper