-
-
Notifications
You must be signed in to change notification settings - Fork 93
Description
Design Proposal: Add vertical alignment to format expression
Motivation
Format expression can facilitate multiple text and image elements of different sizes. At the moment all of them are aligned to the font baseline. It is not possible to change the vertical alignment. Having a possibility to change the alignment, eg. center, would allow us to create rich labels.
If following design would be accepted I would like to make contributions to this repo and MapLibre GL JS with the implementation.
Proposed Change
We would like to introduce vertical-align property to style override in format expression. vertical-align property can take three options:
bottom(default)centertop
Examples
Center
"text-field": [
"format",
["image", "image"],
{ "vertical-align": "center" },
" ",
{},
"BIG yg",
{ "font-scale": 1.2, "vertical-align": "center" },
" ",
{},
"SMALL",
{ "font-scale": 0.8, "vertical-align": "center" }
],Top
"text-field": [
"format",
["image", "image"],
{ "vertical-align": "top" },
" ",
{},
"BIG yg",
{ "font-scale": 1.2, "vertical-align": "top" },
" ",
{},
"SMALL",
{ "font-scale": 0.8, "vertical-align": "top" }
],Bottom (default, current behaviour)
"text-field": [
"format",
["image", "image"],
{},
" ",
{},
"BIG yg",
{ "font-scale": 1.2 },
" ",
{},
"SMALL",
{ "font-scale": 0.8 }
],Mixed
"text-field": [
"format",
["image", "image"],
{},
" ",
{},
"BIG yg",
{ "font-scale": 1.2 },
" ",
{},
"SMALL",
{ "font-scale": 0.8, "vertical-align": "center" }
],API Modifications
Add new property to style override object of format expression:
vertical-align:
- type:
enum - default:
bottom - possible values:
bottom,center,top - effect: change vertical alignment of
formatexpression element
Behaviour
bottomdefault: text baseline and image bottom are in line (current behaviour)center: image center and text center (line between baseline and top) are in line with center of the highest element in the rowtop: image top and text top (line determined by the highest character in the font) are in line
It is possible to set vertical-align for each element in format expression separately.
Migration Plan and Compatibility
There is no breaking change. Rendering of existing styles is unchanged. Only if style has new property vertical-align with non-default value, there is a difference in label rendering.






