Atlaslog
Atlaslog / OpenLayers / API reference / Text
OpenLayers · API reference

Text

Quick answer

Text is ol.style.Text, the label style controlling content, font, fill, stroke, offsets, alignment, rotation, scale and background. Use text for the string, font for a CSS shorthand, offsetX and offsetY for pixel nudges, plus backgroundFill, backgroundStroke and padding for legible boxes. Give it to Style.text inside a style function.

Last verified 2026-11-03 · OpenLayers 10.3.1 · Cite this page
new ol.style.Text( options )
Key points
Example
var label = new ol.style.Text({
  text: '王府井',
  font: '600 12px "PingFang SC", sans-serif',
  fill: new ol.style.Fill({ color: '#16181d' }),
  stroke: new ol.style.Stroke({ color: '#ffffff', width: 3 }),
  offsetY: -16,
  overflow: true
});
var labelTemplate = new ol.style.Text({
  font: '500 12px sans-serif',
  fill: new ol.style.Fill({ color: '#16181d' }),
  stroke: new ol.style.Stroke({ color: '#ffffff', width: 3 }),
  offsetY: -15
});

function styleFunction(feature) {
  var text = labelTemplate.clone();
  text.setText(feature.get('name') + ' · ' + feature.get('code'));

  return new ol.style.Style({
    image: new ol.style.Circle({ radius: 5 }),
    text: text
  });
}
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). Text. https://www.jingweizhi.com/en/openlayers/api/text.html (accessed 2026-11-03).