Mapbox deciding overlap order
Asked Answered
T

1

5

I have some features on the map displayed as icons. I want to decide which icons should be hidden and which should be displayed when they collide on a numeric field, that each feature on my map has (see picture). I've found a mapbox property called "symbol-sort-key", but I can't figure out if it's the right thing. symbol-sort-key takes a number, but I don't know to what this number should refer to. Any ideas how to solve this problem? enter image description here

Time answered 29/11, 2019 at 9:28 Comment(0)
S
6

Yes, symbol-sort-key is probably what you want. It's used to determine the order in which symbols are drawn, which affects which one is drawn on top if they overlap and collisions are allowed (highest number wins) or which is the only one drawn if collisions aren't allowed (lowest number wins).

The number in the documentation refers to a numeric type. So if if you have a property called "priority", which is numeric, you'd specify something like:

"symbol-sort-key": ["to-number", ["get", "priority"]],
Sisterinlaw answered 29/11, 2019 at 11:2 Comment(3)
Hello Steve, I realized, that this feature works for each layer separately. Suppose that two symbols belong to two different layers, but contain the same symbol-sort-key. Is it possible to decide the order in which the symbols are drawn only on the symbol-sort-key and ignore the order of the layers?Time
No, that's inherent in how layers work. You should combine them into one layer if that's what you want.Sisterinlaw
That worked well. I didn't know that it's possible to set the name of the icon dynamically per mapbox expressions, that allows me to display different POIs in one layers. Thank you!Time

© 2022 - 2024 — McMap. All rights reserved.