Class: Text

ol/style/Text~Text


import Text from 'ol/style/Text';

Set text style for vector features.

new Text(opt_options)

style/Text.js, line 53
Name Type Description
options

Options.

Name Type Default Description
font string

Font style as CSS 'font' value, see: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/font. Default is '10px sans-serif'

maxAngle number

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 0

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

offsetY number 0

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

overflow boolean false

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 module:ol/style/TextPlacement | string

Text placement.

scale number

Scale.

rotateWithView boolean false

Whether to rotate the text with the view.

rotation number 0

Rotation in radians (positive rotation clockwise).

text string

Text content.

textAlign string

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.

textBaseline string 'middle'

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

fill module:ol/style/Fill~Fill

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

stroke module:ol/style/Stroke~Stroke

Stroke style.

backgroundFill module:ol/style/Fill~Fill

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

backgroundStroke module:ol/style/Stroke~Stroke

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

padding Array.<number> [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].

Methods

clone(){module:ol/style/Text~Text}

style/Text.js, line 170

Clones the style.

Returns:
The cloned style.

getBackgroundFill(){module:ol/style/Fill~Fill}

style/Text.js, line 322

Get the background fill style for the text.

Returns:
Fill style.

getBackgroundStroke(){module:ol/style/Stroke~Stroke}

style/Text.js, line 331

Get the background stroke style for the text.

Returns:
Stroke style.

getFill(){module:ol/style/Fill~Fill}

style/Text.js, line 250

Get the fill style for the text.

Returns:
Fill style.

getFont(){string|undefined}

style/Text.js, line 205

Get the font name.

Returns:
Font.

getMaxAngle(){number}

style/Text.js, line 214

Get the maximum angle between adjacent characters.

Returns:
Angle in radians.

getOffsetX(){number}

style/Text.js, line 232

Get the x-offset for the text.

Returns:
Horizontal text offset.

getOffsetY(){number}

style/Text.js, line 241

Get the y-offset for the text.

Returns:
Vertical text offset.

getOverflow(){boolean}

style/Text.js, line 196

Get the overflow configuration.

Returns:
Let text overflow the length of the path they follow.

getPadding(){Array.<number>}

style/Text.js, line 340

Get the padding for the text.

Returns:
Padding.

getPlacement(){module:ol/style/TextPlacement|string}

style/Text.js, line 223

Get the label placement.

Returns:
Text placement.

getRotateWithView(){boolean|undefined}

style/Text.js, line 259

Determine whether the text rotates with the map.

Returns:
Rotate with map.

getRotation(){number|undefined}

style/Text.js, line 268

Get the text rotation.

Returns:
Rotation.

getScale(){number|undefined}

style/Text.js, line 277

Get the text scale.

Returns:
Scale.

getStroke(){module:ol/style/Stroke~Stroke}

style/Text.js, line 286

Get the stroke style for the text.

Returns:
Stroke style.

getText(){string|undefined}

style/Text.js, line 295

Get the text to be rendered.

Returns:
Text.

getTextAlign(){string|undefined}

style/Text.js, line 304

Get the text alignment.

Returns:
Text align.

getTextBaseline(){string|undefined}

style/Text.js, line 313

Get the text baseline.

Returns:
Text baseline.

setBackgroundFill(fill)

style/Text.js, line 480

Set the background fill.

Name Type Description
fill module:ol/style/Fill~Fill

Fill style.

setBackgroundStroke(stroke)

style/Text.js, line 490

Set the background stroke.

Name Type Description
stroke module:ol/style/Stroke~Stroke

Stroke style.

setFill(fill)

style/Text.js, line 410

Set the fill.

Name Type Description
fill module:ol/style/Fill~Fill

Fill style.

setFont(font)

style/Text.js, line 360

Set the font.

Name Type Description
font string | undefined

Font.

setMaxAngle(maxAngle)

style/Text.js, line 370

Set the maximum angle between adjacent characters.

Name Type Description
maxAngle number

Angle in radians.

setOffsetX(offsetX)

style/Text.js, line 380

Set the x offset.

Name Type Description
offsetX number

Horizontal text offset.

setOffsetY(offsetY)

style/Text.js, line 390

Set the y offset.

Name Type Description
offsetY number

Vertical text offset.

setOverflow(overflow)

style/Text.js, line 350

Set the overflow property.

Name Type Description
overflow boolean

Let text overflow the path that it follows.

setPadding(padding)

style/Text.js, line 500

Set the padding ([top, right, bottom, left]).

Name Type Description
padding Array.<number>

Padding.

setPlacement(placement)

style/Text.js, line 400

Set the text placement.

Name Type Description
placement module:ol/style/TextPlacement | string

Placement.

setRotation(rotation)

style/Text.js, line 420

Set the rotation.

Name Type Description
rotation number | undefined

Rotation.

setScale(scale)

style/Text.js, line 430

Set the scale.

Name Type Description
scale number | undefined

Scale.

setStroke(stroke)

style/Text.js, line 440

Set the stroke.

Name Type Description
stroke module:ol/style/Stroke~Stroke

Stroke style.

setText(text)

style/Text.js, line 450

Set the text.

Name Type Description
text string | undefined

Text.

setTextAlign(textAlign)

style/Text.js, line 460

Set the text alignment.

Name Type Description
textAlign string | undefined

Text align.

setTextBaseline(textBaseline)

style/Text.js, line 470

Set the text baseline.

Name Type Description
textBaseline string | undefined

Text baseline.