Replies: 4 comments 9 replies
-
Yes, I've done this in a precise way before where I precompute the exact minzoom to show labels at so there is no client-side collision detection at all. I have a fork of maplibre that uses an attribute to drive minzoom feature comparison in the shaders and proposed maplibre/maplibre-gl-js#1867 to pull that capability into maplibre without needing a fork. The result is super smooth but only if you disable tilting and rotating. It also requires a global index of all points that you insert points into in order of importance to determine the min zoom at which there is no collision with other labels - although I wonder if that same calculation could be done on a per-tile basis...? You could do a more coarse version of this that doesn't compute the exact label size based on text but instead comes up with a rectangle to use for a point and only emits it if there are less than a certain number of collisions with other points to limit density. That would work for points in addition to labels, like the density limiting that tippecanoe can do. |
Beta Was this translation helpful? Give feedback.
-
One could even precalculate label placement along lines |
Beta Was this translation helpful? Give feedback.
-
That’s a lot of assumptions. This optimization could be quite useful for some cases, especially static image rendering, while others like navigation would absolutely need to consider rotation and pitch (and therefore the map viewport’s dimensions). Another confounding factor would be 3D terrain. It could be worth the trouble if it’s disabled by default but developers have the option to enable it. |
Beta Was this translation helpful? Give feedback.
-
Currently, I am using How could I calculate collisions in Planetiler? |
Beta Was this translation helpful? Give feedback.
-
Planetiler has a functionality to limit the number of point labels in a given area. Something with
setSortKey()
andsetLabelGridSizeAndLimit()
I think. This is nice because it reduces the number of point labels that go into the tiles and MapLibre GL JS has to handle fewer collisions in the frontend.I wonder if we could take this one step further and compute frontend label collisions when generating tiles and remove points that anyway would not render because other points are more important?
The approach would assume some frontend rendering style, pitch and rotation of the map, and screen resolution.
Beta Was this translation helpful? Give feedback.
All reactions