Skip to content

Vertical alignment in format expression #832

@stanislawpuda-tomtom

Description

@stanislawpuda-tomtom

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)
  • center
  • top

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" }
],

big_image_center
small_image_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" }
],

big_image_top
small_image_top

Bottom (default, current behaviour)

"text-field": [
  "format",
  ["image", "image"], 
  {},
  " ",
  {},
  "BIG yg",
  { "font-scale": 1.2 },
  " ",
  {},
  "SMALL",
  { "font-scale": 0.8 }
],

big_image_baseline
small_image_baseline

Mixed

"text-field": [
  "format",
  ["image", "image"], 
  {},
  " ",
  {},
  "BIG yg",
  { "font-scale": 1.2 },
  " ",
  {},
  "SMALL",
  { "font-scale": 0.8, "vertical-align": "center" }
],

big_image_mixed

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 format expression element

Behaviour

  • bottom default: 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 row
  • top: 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions