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

For polygon labels or when placement is set to 'line', allow text to exceed the width of the polygon at the 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.

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.

Methods

clone(){ol.style.Text}

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

Clones the style.

Returns:
The cloned style.

getExceedLength(){boolean}

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

Get the exceedLength configuration.

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

getFill(){ol.style.Fill}

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

Get the fill style for the text.

Returns:
Fill style.

getFont(){string|undefined}

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

Get the font name.

Returns:
Font.

getMaxAngle(){number}

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

Get the maximum angle between adjacent characters.

Returns:
Angle in radians.

getOffsetX(){number}

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

Get the x-offset for the text.

Returns:
Horizontal text offset.

getOffsetY(){number}

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

Get the y-offset for the text.

Returns:
Vertical text offset.

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

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

Get the label placement.

Returns:
Text placement.

getRotateWithView(){boolean|undefined}

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

Determine whether the text rotates with the map.

Returns:
Rotate with map.

getRotation(){number|undefined}

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

Get the text rotation.

Returns:
Rotation.

getScale(){number|undefined}

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

Get the text scale.

Returns:
Scale.

getStroke(){ol.style.Stroke}

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

Get the stroke style for the text.

Returns:
Stroke style.

getText(){string|undefined}

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

Get the text to be rendered.

Returns:
Text.

getTextAlign(){string|undefined}

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

Get the text alignment.

Returns:
Text align.

getTextBaseline(){string|undefined}

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

Get the text baseline.

Returns:
Text baseline.

setExceedLength(exceedLength)

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

Set the exceedLength property.

Name Type Description
exceedLength boolean

Let text exceed the path that it follows.

setFill(fill)

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

Set the fill.

Name Type Description
fill ol.style.Fill

Fill style.

setFont(font)

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

Set the font.

Name Type Description
font string | undefined

Font.

setMaxAngle(maxAngle)

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

Set the maximum angle between adjacent characters.

Name Type Description
maxAngle number

Angle in radians.

setOffsetX(offsetX)

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

Set the x offset.

Name Type Description
offsetX number

Horizontal text offset.

setOffsetY(offsetY)

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

Set the y offset.

Name Type Description
offsetY number

Vertical text offset.

setPlacement(placement)

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

Set the text placement.

Name Type Description
placement ol.style.TextPlacement | string

Placement.

setRotation(rotation)

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

Set the rotation.

Name Type Description
rotation number | undefined

Rotation.

setScale(scale)

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

Set the scale.

Name Type Description
scale number | undefined

Scale.

setStroke(stroke)

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

Set the stroke.

Name Type Description
stroke ol.style.Stroke

Stroke style.

setText(text)

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

Set the text.

Name Type Description
text string | undefined

Text.

setTextAlign(textAlign)

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

Set the text alignment.

Name Type Description
textAlign string | undefined

Text align.

setTextBaseline(textBaseline)

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

Set the text baseline.

Name Type Description
textBaseline string | undefined

Text baseline.