tangram-es icon indicating copy to clipboard operation
tangram-es copied to clipboard

Multi-feature versions of PickMaker, PickLabel, etc.

Open warpedgeoid opened this issue 4 years ago • 4 comments
trafficstars

Have you thought about providing versions of these methods that return all objects at a point instead of just the topmost one?

I have an application where almost every layer needs interactive styles, and a PickLabelsAt would make my life a lot easier.

warpedgeoid avatar Mar 04 '21 16:03 warpedgeoid

I can definitely see how this would be useful for some applications. However, selecting multiple features from a single point is at odds with Tangram's approach to feature picking.

When you query a pick location, Tangram re-renders all of the objects in the scene using a solid color that maps to a feature ID for the object. Then it finds the pixel corresponding to the pick location, reads the color from that pixel, and looks up the feature ID that corresponds to that color. This approach is nice because it means the picking uses the exact same geometry that's used for rendering - what you see is what you pick. However, because it is based on a rendering technique, only the top-most color will be written in the pick buffer, and so only one feature can be picked from a single point.

It's possible that we find a way to implement this with a modification to the approach - or some different approach altogether - but hopefully this explains why it's not a simple change.

matteblair avatar Mar 04 '21 22:03 matteblair

deck.gl uses a similar approach (docs), and you can also see some ideas for applying it to multiple objects that they developed here: https://github.com/visgl/deck.gl/blob/master/dev-docs/RFCs/v5.3/picking-overlapping-objects-rfc.md. As @matteblair said, not straightforward, but wanted to add these for interest.

bcamper avatar Mar 04 '21 22:03 bcamper

Oh very nice! The multi-pass approach in that RFC is the first thing that came to mind, good to see that it can actually work.

matteblair avatar Mar 04 '21 22:03 matteblair

Thanks for the information @matteblair and @bcamper. It's an interesting approach and I didn't realize this was how Tangram handled picking behind the scenes.

A simpler solution for my application might be to keep track of all object locations in a separate index and query that when a tap gesture is recognized. I can easily do that for markers added after the map loads, but I'll have to think about the best way of doing this for stuff included in the map tiles.

warpedgeoid avatar Mar 05 '21 03:03 warpedgeoid