This gives more intuitive click behavior, since we often want clicks to only apply to the topmost layer which the user can actually see.
This can be done using map.queryRenderedFeatures on the event's point, and then the first result in the returned array is the top-most. Each layer than calls this and compares the first result with itself.
The primary challenge here is to only call this once per event, across all layers. It's potentially expensive to call this multiple times per event, and each call will always return the same results, so some way of caching the result should be present. I'm hoping there's a suitable key accessible to all the layers for an event that we can use in a WeakMap, but need to research a bit. Worst case we just cache keyed on event.point, keeping only the latest, and also autoclear after a tiny delay.
This gives more intuitive click behavior, since we often want clicks to only apply to the topmost layer which the user can actually see.
This can be done using
map.queryRenderedFeatures
on the event's point, and then the first result in the returned array is the top-most. Each layer than calls this and compares the first result with itself.The primary challenge here is to only call this once per event, across all layers. It's potentially expensive to call this multiple times per event, and each call will always return the same results, so some way of caching the result should be present. I'm hoping there's a suitable key accessible to all the layers for an event that we can use in a
WeakMap
, but need to research a bit. Worst case we just cache keyed onevent.point
, keeping only the latest, and also autoclear after a tiny delay.cf #45