Skip to content

fix: evaluate zoom-dependent symbol sizes at the drawn zoom - #8175

Open
mondsichtung wants to merge 2 commits into
maplibre:mainfrom
mondsichtung:camera-size-drawn-zoom
Open

fix: evaluate zoom-dependent symbol sizes at the drawn zoom#8175
mondsichtung wants to merge 2 commits into
maplibre:mainfrom
mondsichtung:camera-size-drawn-zoom

Conversation

@mondsichtung

@mondsichtung mondsichtung commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Fix labels briefly drawn too large when zooming out fast with a zoom-dependent text-size/icon-size

MR-repro

On a fast zoom-out, tiles kept on screen from the deeper zoom draw labels at the size baked for their own zoom: camera sizes were clamped into the two stops around the tile's zoom, a restriction only composite sizes need (their per-feature sizes are baked into vertex data).

camera sizes now keep the whole stop table (plain arrays, still worker-transferable) and are evaluated at the drawn zoom, capped at the size the tile's collision boxes were built from. composite, constant, and source are unchanged.

Design: evaluate camera symbol sizes at the drawn zoom

Symptom

Zoom out quickly on a style where text-size or icon-size grows with zoom, and labels flash too large for about half a second. The tiles kept on screen from the deeper zoom draw their labels at the size for their own zoom, not the camera's.

Background

A symbol bucket classifies its size property into one of four kinds. The data is baked in the worker, so it must be plain transferable values, not the expression itself:

kind depends on baked at layout time
constant nothing one size
source feature per-feature size, in vertex data
camera zoom sizes at the two stops around the tile's zoom
composite zoom + feature per-feature sizes at those two stops, in vertex data

At draw time, evaluateSizeForZoom turns the camera zoom into shader uniforms.

Cause

For composite, clamping the camera zoom into the tile's two stops is forced: each feature only carries its size at those two zooms, so blending between them is all the renderer can do.

camera has no per-feature data, but took the same clamp anyway, for symmetry (per an old comment). So a tile parsed past the function's last stop draws one fixed size at every camera zoom. That is the flash.

Fix

For camera, bake the size at every zoom stop instead of two (still plain arrays). At draw time, interpolate within the segment containing the drawn zoom. This reproduces the size expression exactly, for interpolate and step alike. One wrinkle: a step's first stop is -Infinity, which cannot be evaluated at, so its base value is sampled just below the second stop.

composite, constant, and source are unchanged.

Why the result is capped at layoutSize

Collision boxes are baked from the size at tileZoom + 1. If a retained tile drew labels larger than that, they could overlap their neighbours, trading one artifact for another. So the drawn size is capped at that baked size (layoutSize).

The cap never binds inside a tile's own zoom range, so steady state is unchanged. It does not bind on the zoom-out this fixes either, where the correct size is the smaller one. The one case it leaves as-is (today's behaviour, not a regression): zooming in on a retained parent tile still draws labels slightly small until the children arrive. Fixing that means scaling the collision boxes, a separate change to the placement path.

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • If you changed code in a file that has a benchmark file next to it (*.bench.ts), post before/after results of npm run bench (the compare workflow is in test/bench/README.md).
  • Add an entry to CHANGELOG.md under the ## main section.
  • Confirm you have read our AI policy here.

Generated-By: Claude Fable 5 (high)

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.51724% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.95%. Comparing base (ef90e66) to head (1632f31).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/symbol/symbol_size.ts 65.51% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8175      +/-   ##
==========================================
+ Coverage   93.92%   93.95%   +0.03%     
==========================================
  Files         290      290              
  Lines       24916    24924       +8     
  Branches     6575     6576       +1     
==========================================
+ Hits        23402    23417      +15     
+ Misses       1514     1507       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@HarelM

HarelM commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

I think I understand the fix, but it would be helpful to show a short design document to better explain this change.
Also, please extract some methods out and move the in method comments to be tsdoc comments.

@mondsichtung

Copy link
Copy Markdown
Contributor Author

Refactored in 1632f31, design document was added to the initial post

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.

2 participants