Skip to content

Draw basemap labels in their styled fonts - #519

Open
simplifaisoul wants to merge 1 commit into
masterfrom
fix/basemap-font-stacks
Open

simplifaisoul wants to merge 1 commit into
masterfrom
fix/basemap-font-stacks

Conversation

@simplifaisoul

Copy link
Copy Markdown
Owner

Summary

Basemap place names were drawn in the wrong typeface. The style asks for font stacks such as Montserrat SemiBold, Open Sans Bold, Noto Sans Regular, where each character should come from the first font that has it. The tile server's own font merging ignores that order, so labels came out in Noto Sans instead of Montserrat and looked noticeably different from CARTO's map.

/api/basemap now merges font stacks itself, so place names match CARTO's lettering.

Changes

  • New src/lib/basemap/glyphs.ts: reads and writes glyph files (protobuf) and merges them in stack order. Each character comes from the first font that has it; glyph bytes are copied unchanged.
  • /api/basemap/fonts/{fontstack}/{range} requests each font of the stack from the tile server on its own and merges the result.
    • A font the tile server doesn't have is skipped, so the next font stands in.
    • If any font request fails, the response is 502 and uncached, so an incomplete stack is never cached for a month.

Testing

  • npx vitest run: 180 files and 1,827 tests pass (27 skipped, as on master).
    • 7 new tests cover the merge order, glyph bytes kept intact, per-font requests, and the 502 and 404 cases.
  • npx tsc --noEmit: no errors. ESLint: no findings in changed files.
  • next build: completes with exit code 0.
  • Glyphs compared directly. For the city-label stack, letter advances for "KALAMAZOO" from /api/basemap/fonts now match CARTO's own glyph server exactly (previously they matched Noto Sans). The Arabic range still returns 253 glyphs from the Noto fallback fonts.
  • Production build in headless Chrome: Kalamazoo at zooms 9 and 11 draws its label in Montserrat, and all style, font, icon and tile requests answered 200.

🤖 Generated with SIMPLIFAI

The tile server's own font merging ignores a stack's order, so labels styled
"Montserrat SemiBold, Open Sans Bold, Noto Sans Regular" were drawn in Noto
Sans. /api/basemap now asks for each font on its own and merges the glyphs
itself, each character from the first font that has it, as map styles
expect. A stack with a font that failed to load answers 502 uncached rather
than being cached incomplete.
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
osiris Ready Ready Preview Nov 25, 2026 11:43pm UTC

This branch was successfully deployed

1 active deployment
Preview – osiris — 0b5e89a9 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant