Class: Text

ol.style.Text


import Text from 'ol/style/text';

Set text style for vector features.

new ol.style.Text(opt_options)

src/ol/style/text.js, line 16
Name Type Description
options

Options.

Name Type Description
exceedLength boolean | undefined

Deprecated. Use the overflow option instead.

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. Default is false.

font string | undefined

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 | undefined

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 | undefined

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

offsetY number | undefined

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

overflow boolean | undefined

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. Default is false.

placement ol.style.TextPlacement | undefined

Text placement.

scale number | undefined

Scale.

rotateWithView boolean | undefined

Whether to rotate the text with the view. Default is false.

rotation number | undefined

Rotation in radians (positive rotation clockwise). Default is 0.

text string | undefined

Text content.

textAlign string | undefined

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 | undefined

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

fill ol.style.Fill | undefined

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

stroke ol.style.Stroke | undefined

Stroke style.

backgroundFill ol.style.Fill | undefined

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

backgroundStroke ol.style.Stroke | undefined

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

padding Array.<number> | undefined

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

Methods

clone(){ol.style.Text}

src/ol/style/text.js, line 143

Clones the style.

Returns:
The cloned style.

getBackgroundFill(){ol.style.Fill}

src/ol/style/text.js, line 308

Get the background fill style for the text.

Returns:
Fill style.

getBackgroundStroke(){ol.style.Stroke}

src/ol/style/text.js, line 318

Get the background stroke style for the text.

Returns:
Stroke style.

getFill(){ol.style.Fill}

src/ol/style/text.js, line 228

Get the fill style for the text.

Returns:
Fill style.

getFont(){string|undefined}

src/ol/style/text.js, line 178

Get the font name.

Returns:
Font.

getMaxAngle(){number}

src/ol/style/text.js, line 188

Get the maximum angle between adjacent characters.

Returns:
Angle in radians.

getOffsetX(){number}

src/ol/style/text.js, line 208

Get the x-offset for the text.

Returns:
Horizontal text offset.

getOffsetY(){number}

src/ol/style/text.js, line 218

Get the y-offset for the text.

Returns:
Vertical text offset.

getOverflow(){boolean}

src/ol/style/text.js, line 168

Get the overflow configuration.

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

getPadding(){Array.<number>}

src/ol/style/text.js, line 328

Get the padding for the text.

Returns:
Padding.

getPlacement(){ol.style.TextPlacement|string}

src/ol/style/text.js, line 198

Get the label placement.

Returns:
Text placement.

getRotateWithView(){boolean|undefined}

src/ol/style/text.js, line 238

Determine whether the text rotates with the map.

Returns:
Rotate with map.

getRotation(){number|undefined}

src/ol/style/text.js, line 248

Get the text rotation.

Returns:
Rotation.

getScale(){number|undefined}

src/ol/style/text.js, line 258

Get the text scale.

Returns:
Scale.

getStroke(){ol.style.Stroke}

src/ol/style/text.js, line 268

Get the stroke style for the text.

Returns:
Stroke style.

getText(){string|undefined}

src/ol/style/text.js, line 278

Get the text to be rendered.

Returns:
Text.

getTextAlign(){string|undefined}

src/ol/style/text.js, line 288

Get the text alignment.

Returns:
Text align.

getTextBaseline(){string|undefined}

src/ol/style/text.js, line 298

Get the text baseline.

Returns:
Text baseline.

setBackgroundFill(fill)

src/ol/style/text.js, line 482

Set the background fill.

Name Type Description
fill ol.style.Fill

Fill style.

setBackgroundStroke(stroke)

src/ol/style/text.js, line 493

Set the background stroke.

Name Type Description
stroke ol.style.Stroke

Stroke style.

setFill(fill)

src/ol/style/text.js, line 405

Set the fill.

Name Type Description
fill ol.style.Fill

Fill style.

setFont(font)

src/ol/style/text.js, line 350

Set the font.

Name Type Description
font string | undefined

Font.

setMaxAngle(maxAngle)

src/ol/style/text.js, line 361

Set the maximum angle between adjacent characters.

Name Type Description
maxAngle number

Angle in radians.

setOffsetX(offsetX)

src/ol/style/text.js, line 372

Set the x offset.

Name Type Description
offsetX number

Horizontal text offset.

setOffsetY(offsetY)

src/ol/style/text.js, line 383

Set the y offset.

Name Type Description
offsetY number

Vertical text offset.

setOverflow(overflow)

src/ol/style/text.js, line 339

Set the overflow property.

Name Type Description
overflow boolean

Let text overflow the path that it follows.

setPadding(padding)

src/ol/style/text.js, line 504

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

Name Type Description
padding Array.<number>

Padding.

setPlacement(placement)

src/ol/style/text.js, line 394

Set the text placement.

Name Type Description
placement ol.style.TextPlacement | string

Placement.

setRotation(rotation)

src/ol/style/text.js, line 416

Set the rotation.

Name Type Description
rotation number | undefined

Rotation.

setScale(scale)

src/ol/style/text.js, line 427

Set the scale.

Name Type Description
scale number | undefined

Scale.

setStroke(stroke)

src/ol/style/text.js, line 438

Set the stroke.

Name Type Description
stroke ol.style.Stroke

Stroke style.

setText(text)

src/ol/style/text.js, line 449

Set the text.

Name Type Description
text string | undefined

Text.

setTextAlign(textAlign)

src/ol/style/text.js, line 460

Set the text alignment.

Name Type Description
textAlign string | undefined

Text align.

setTextBaseline(textBaseline)

src/ol/style/text.js, line 471

Set the text baseline.

Name Type Description
textBaseline string | undefined

Text baseline.