How to get a label bold in open layers 3?
Asked Answered
P

1

7

I'm labelling markers in a vector layer.

TextOptions of a ol.style.Text object include arrording to the docs (http://ol3js.org/en/v3.0.0-beta.1/apidoc/ol.style.html#TextOptions) no option to change font-weight.

In ol2 I used:

fontWeight: "bold"

This doesn't seem to work in ol3.

How can this be done?

Pustulate answered 27/6, 2014 at 19:54 Comment(0)
P
16

I found a solution by looking at the example here: https://openlayers.org/en/master/examples/vector-labels.html:

font = weight + ' ' + size + ' ' + font

for instance:

font: 'bold 11px Arial, Verdana, Helvetica, sans-serif'

I don't think there is an explanation in the official docs yet - it only says:

  • Type: string
  • Description: Font
Pustulate answered 27/6, 2014 at 20:17 Comment(2)
The docs are always behind the source code/examples in OpenLayers, which I think is reasonable, given how good the examples and how readable the source.Kevyn
Useful answer. Of course the examples are good, but it can take times to find exactly what you want !Cheadle

© 2022 - 2024 — McMap. All rights reserved.