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

Design Proposal: Adjust Text size / Glyphs based on latitude #857

Closed
zerda-ocm opened this issue Oct 14, 2024 · 17 comments
Closed

Design Proposal: Adjust Text size / Glyphs based on latitude #857

zerda-ocm opened this issue Oct 14, 2024 · 17 comments
Labels
enhancement New feature or request

Comments

@zerda-ocm
Copy link

zerda-ocm commented Oct 14, 2024

Motivation

For a topological map in globe projection a consistent text size would improve the visual appeareance.

text_scale_example

Texts appear smaller the closer they get to the poles. This can result in tapered labels, when a feature runs from north to south. For example a mountain range. This effect gets stronger closer to the poles.

Proposed Change

"layout": {
    "text-projection": "globe" // or "mercator" as default
}

Each letter needs to be invidually scaled depending on latitude.

@HarelM HarelM changed the title Adjust Text size / Glyphs based on latitude Design Proposal: Adjust Text size / Glyphs based on latitude Oct 15, 2024
@HarelM HarelM added the enhancement New feature or request label Oct 15, 2024
@HarelM
Copy link
Collaborator

HarelM commented Oct 15, 2024

How would this proposal work with the other text manipulation abilities?
Mainly with map and viewport definition of text-pitch-aligment and other text alignment and offsets?

@zerda-ocm
Copy link
Author

Layout properties that would result in individual letters to stay at a specific longitude/latitude should scale according to latitude:

Properties where this behaviour should apply:

  • "text-rotation-alignment": "viewport-glyph" / "map"
  • "text-pitch-alignment": "map"

Properties where this behaviour should not apply:

  • "text-rotation-alignment": "viewport"
  • "text-pitch-alignment": "viewport"

text alignments and offsets are affected depending on the properties above. For example with "text-pitch-alignment": "map":

  • "text-justify": "right" (which might result in a shift north) -> glyphs get scaled up
  • "text-offset": [1,1] -> a shift in latitude should scale the letters

@HarelM
Copy link
Collaborator

HarelM commented Oct 22, 2024

It is still not clear (to me) how this would behave in all kind of possible scenarios.
Can you provide some visuals of how you'd expect this proposal to behave given the current possible configurations?

@zerda-ocm
Copy link
Author

Is there a specific combination that is unclear?

@HarelM
Copy link
Collaborator

HarelM commented Oct 22, 2024

For me, all of them...

@zerda-ocm
Copy link
Author

zerda-ocm commented Oct 22, 2024

Well, "all of them" might be a bit too much to visualize. Essentially, it boils down to one key point: if the text is projected on the map, it should maintain the same size regardless of its position on the map. Let’s take an extreme case with the current implementation:

  • Left image: A text placed on a line at the equator with a text size of 14 is perfectly readable. However, the same text size on Greenland becomes unreadable.

  • Center image: I had to increase the text size to 60 just to make it readable. Notice how the individual letters still shrink significantly as they approach the poles, and the spacing between the letters also decreases.

  • Right image: Although the text size is back to 14, the text maintains a consistent, readable size with uniform spacing (for this behaviour, I propose "text-projection": "globe").

text-projection

@HarelM
Copy link
Collaborator

HarelM commented Oct 22, 2024

Can you please share a jsbin that reproduces this. I tend to think there are ways currently to achieve what you want or something close to it. If not, then we should be able to add some property to the existing one instead of adding yet another confusing property.

@zerda-ocm
Copy link
Author

@zerda-ocm
Copy link
Author

I don't think it's possible to achieve this look without modifying the code. To get the result shown above, I had to calculate distances using the Haversine formula instead of Mercator (in placeGlyphAlongLine). Without this, I couldn't achieve consistent spacing and would also get slightly different anchor centers. Additionally, I had to slightly modify symbol_sdf.vertex.glsl to adjust the glyph sizes.

So, instead of "text-projection": "globe", would you prefer something like "text-pitch-alignment": "globe-map"? (I'm open to other suggestions.)

@HarelM
Copy link
Collaborator

HarelM commented Oct 22, 2024

Is the following what you are after?
image
I've added "text-pitch-alignment": "viewport", to your example basically.
https://jsbin.com/gabexamaga/1/edit?html,output

@HarelM
Copy link
Collaborator

HarelM commented Oct 22, 2024

It's also worth noting, due to how globe works that when panning the map closes to the poles the zoom changes, so if you want to style something that will work for poles and everywhere else you need to be cautious about how you use the zoom.
See here:
https://github.com/maplibre/maplibre-gl-js/blob/main/developer-guides/globe.md

@zerda-ocm
Copy link
Author

Is the following what you are after? ) I've added "text-pitch-alignment": "viewport", to your example basically. https://jsbin.com/gabexamaga/1/edit?html,output

It is close, but not quite there. I need the text to align with the map and not with the viewport:

Screenshot 2024-10-22 221135

@HarelM
Copy link
Collaborator

HarelM commented Oct 22, 2024

CC: @kubapelc - it is possible that there's an issue with the text close to the poles?
I'm not sure a new definition is actually needed here, feels like more in the realm of a bug...
I think that if the text size is defined as constant it should apply for text close to the poles as well...
But it might be something else.
If this is a bug I'll move it to the maplibre-gl-js repo.

@zerda-ocm
Copy link
Author

Whether it's an issue or a bug depends on your perspective:

It’s a feature if you want to maintain visual consistency between the Mercator and globe projections (the text may appear distorted, but its position remains consistent).

It’s a bug if you expect the text size to remain constant.

(Personally, I lean towards labeling this as a bug, but it's not for me to decide.)

@HarelM
Copy link
Collaborator

HarelM commented Oct 29, 2024

I think the following bug described this issue, right?

@zerda-ocm
Copy link
Author

I would say it is related because it solves the issue with the text-size. However the spacings would still need some work;

Screenshot 2024-10-29 162525

@HarelM
Copy link
Collaborator

HarelM commented Oct 29, 2024

I would suggest continueing the discussion in the other repo.
Closing this proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants