Module: ol/style/Text




Type Definitions


Name Type Argument Default Description
font string <optional>

Font style as CSS font value, see: Default is '10px sans-serif'

maxAngle number <optional>

When placement is set to 'line', allow a maximum angle between adjacent characters. The expected value is in radians, and the default is 45° (Math.PI / 4).

offsetX number <optional>

Horizontal text offset in pixels. A positive will shift the text right.

offsetY number <optional>

Vertical text offset in pixels. A positive will shift the text down.

overflow boolean <optional>

For polygon labels or when placement is set to 'line', allow text to exceed the width of the polygon at the label position or the length of the path that it follows.

placement TextPlacement <optional>

Text placement.

repeat number <optional>

Repeat interval in pixels. When set, the text will be repeated at this interval. Only available when placement is set to 'line'. Overrides 'textAlign'.

scale number | Size <optional>


rotateWithView boolean <optional>

Whether to rotate the text with the view.

rotation number <optional>

Rotation in radians (positive rotation clockwise).

text string | Array.<string> <optional>

Text content or rich text content. For plain text provide a string, which can contain line breaks (\n). For rich text provide an array of text/font tuples. A tuple consists of the text to render and the font to use (or '' to use the text style's font). A line break has to be a separate tuple (i.e. '\n', ''). Example: ['foo', 'bold 10px sans-serif', ' bar', 'italic 10px sans-serif', ' baz', ''] will yield "foo bar baz". Note: Rich text is not supported for the immediate rendering API.

textAlign CanvasTextAlign <optional>

Text alignment. Possible values: 'left', 'right', 'center', 'end' or 'start'. Default is 'center' for placement: 'point'. For placement: 'line', the default is to let the renderer choose a placement where maxAngle is not exceeded.

justify TextJustify <optional>

Text justification within the text box. If not set, text is justified towards the textAlign anchor. Otherwise, use options 'left', 'center', or 'right' to justify the text within the text box. Note: justify is ignored for immediate rendering and also for placement: 'line'.

textBaseline CanvasTextBaseline <optional>

Text base line. Possible values: 'bottom', 'top', 'middle', 'alphabetic', 'hanging', 'ideographic'.

fill Fill <optional>

Fill style. If none is provided, we'll use a dark fill-style (#333).

stroke Stroke <optional>

Stroke style.

backgroundFill Fill <optional>

Fill style for the text background when placement is 'point'. Default is no fill.

backgroundStroke Stroke <optional>

Stroke style for the text background when placement is 'point'. Default is no stroke.

padding Array.<number> <optional>
[0, 0, 0, 0]

Padding in pixels around the text for decluttering and background. The order of values in the array is [top, right, bottom, left].

TextJustify{'left'} {'center'} {'right'}

TextPlacement{'point'} {'line'}

Default text placement is 'point'. Note that 'line' requires the underlying geometry to be a LineString, Polygon, MultiLineString or MultiPolygon.