Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved symbol placement on polygon layers #5042

Open
russss opened this issue Nov 13, 2024 · 2 comments
Open

Improved symbol placement on polygon layers #5042

russss opened this issue Nov 13, 2024 · 2 comments
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed

Comments

@russss
Copy link

russss commented Nov 13, 2024

Labelling an area is a common task when designing maps. However, if you try and use a symbol style on a polygon layer, the results are suboptimal, with labels appearing in multiple random places on the polygon:

image

I understand this is because one symbol is placed on each tile the polygon appears in.

The usual solution to this problem is to calculate the label placement on the server and include it as a point layer in the tiles. This isn't ideal - it complicates map development, increases tile size and schema complexity, and it also breaks the vector tiles abstraction by having a rendering decision made on the server.

Someone has tried to fix this in Javascript but this is a fairly hacky solution.

Ideally, a symbol placement algorithm would:

  • Dissolve all the constituent polygons into one polygon
  • Clip that polygon to the viewport
  • Place the symbol at the centroid of the clipped polygon, perhaps with an area cutoff to prevent labels being displayed on a polygon which is only just visible on the edge of the viewport

This is an old problem which is also present in Mapbox GL, so I assume there's a very good reason why it hasn't already been fixed, but it would be a substantial improvement if it could be done.

@HarelM HarelM added enhancement New feature or request PR is more than welcomed Extra attention is needed labels Nov 13, 2024
@HarelM
Copy link
Collaborator

HarelM commented Nov 13, 2024

Can you link to a jsbin with an example of the current situation for future reference?

@russss
Copy link
Author

russss commented Nov 13, 2024

Sure - here's the example map with the country labels rendered from the polygon layer rather than the centroid layer.

This does also result in islands being labelled separately, which is not relevant to this issue, but you can see multiple labels rendered on countries, and this worsens as you zoom in.

SomeoneElseOSM pushed a commit to SomeoneElseOSM/SomeoneElse-vector-extract that referenced this issue Nov 15, 2024
SomeoneElseOSM pushed a commit to SomeoneElseOSM/SomeoneElse-vector-web-display that referenced this issue Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants