Atlaslog / Field Notes / Styling & rendering
Field note · Styling & rendering
Long place names are truncated by a small text-max-width
Quick answer
A district label shows only its first six characters with no ellipsis and no wrapping. `text-max-width: 4` is measured in ems, so only about four Han characters fit per line and anything beyond the computed lines is cut off.
Symptom
- `Urumqi High-tech Industrial Development Zone` renders as two lines with the second line truncated
- `map.getLayer('district-label').layout['text-max-width']` is `4` with `text-size` 12
- No ellipsis and no ellipsis character appears, so the text looks clipped at the texture boundary
Checklist
- Read `layout['text-max-width']` and `text-size` for the layer
- Estimate characters per line: max-width in em roughly equals Han characters per line
- Temporarily set `text-max-width` to 20 and see whether the full name appears
- Check for a custom clip post-process or `overflow: hidden` on the container
- Measure the label texture height against the allowed number of lines
Fix
Raise `text-max-width` to 8 to 12 for Chinese, interpolate `text-size` by zoom (`['interpolate', ['linear'], ['zoom'], 8, 11, 14, 13, 17, 15]`), set `text-line-height: 1.2`, and insert a line break at a semantic boundary for names longer than about 8 characters.
Code
console.log(map.getLayer('district-label').layout['text-max-width']); // 4
console.log(map.getLayer('district-label').layout['text-size']); // 12
// 若同时 text-max-width 4 + text-size 12,字号 12px,可行宽度约 48pxmap.addLayer({
id: 'district-label',
type: 'symbol',
source: 'districts',
layout: {
'text-field': ['get', 'name'],
'text-size': ['interpolate', ['linear'], ['zoom'], 8, 11, 14, 13, 17, 15],
'text-max-width': 10, // 中文每行约 10 字
'text-line-height': 1.2,
'text-max-angle': 30,
'symbol-placement': 'point'
},
paint: {
'text-color': '#1b2733',
'text-halo-color': '#ffffff',
'text-halo-width': 1.2
}
});
Watch out
- Treating `text-max-width` as pixels or as a character count and setting it to 4 for short labels
- Fixing the width but leaving `text-size` fixed, so a long name at high zoom still exceeds the texture height
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Atlaslog (2026). Long place names are truncated by a small text-max-width. https://www.jingweizhi.com/en/cookbook/label-text-clipped.html (accessed 2026-11-03).