Fix temperature numbers sitting visually high on the map badges

canvas textBaseline "middle" centers on font em-box metrics, not
visible ink — digits have no descenders, so they read as sitting too
high in their boxes. Center on the actual glyph bounds instead,
matching the technique already used correctly in Ūdens's drawRanges.
Shared by Faktiskā and the older Kartes comparison map.
This commit is contained in:
b0txec
2026-08-23 13:31:17 +03:00
parent a1c2fd5d7d
commit 5c00e48bdd
+7 -2
View File
@@ -47,11 +47,16 @@ export function drawOnMap(
ctx.font = `bold ${props.fontSize}px Monda`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#000000";
const numericValue = roundValues ? Math.round(value) : value.toFixed(1);
const stringValue = numericValue.toString().replace(".", ",");
ctx.fillText(stringValue, localX, localY);
// "middle" baseline centers on font em-box metrics, not visible ink —
// digits have no descenders, so that reads as sitting too high. Center
// on the actual glyph bounds instead, matching Ūdens's drawRanges.
const metrics = ctx.measureText(stringValue);
const drawY = localY + (metrics.actualBoundingBoxAscent - metrics.actualBoundingBoxDescent) / 2;
ctx.fillText(stringValue, localX, drawY);
if (icon) {
const iconImage = getLoadedWeatherIcon(icon);