How to change font weight for labels?

1. A concise explanation of the problem you’re experiencing.

I’m using Roboto font in my html page, with different weights: 300, 400, 500, 700, previuosly loaded as

I’d like to draw some labels with weigt 500, others with weight 700.

Unfortunately I cant’ find a way to choose the weight for the font.

if I use

font: ‘500 18px Roboto’

as described here

https://html.spec.whatwg.org/multipage/canvas.html#text-styles

it does not work, and it fall back to default font

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

viewer.entities.add({

position: Cesium.Cartesian3.fromDegrees(longitude, latitude),

label: {

text: “AAAAA”,

font: ‘500 18px Roboto’,

fillColor: Cesium.Color.WHITE,

outlineColor: Cesium.Color.BLACK,

outlineWidth: 2,

style: Cesium.LabelStyle.FILL_AND_OUTLINE,

verticalOrigin: Cesium.VerticalOrigin.BOTTOM,

heightReference: Cesium.HeightReference.NONE,

pixelOffset: new Cesium.Cartesian2(0, -5),

translucencyByDistance: new Cesium.NearFarScalar(minDistance, 1.0,

maxDistance, 0.0),

disableDepthTestDistance: Number.POSITIVE_INFINITY,

}

});

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

To have different font weights, with the same font, for my labels

4. The Cesium version you’re using, your operating system and browser.

1.66

1 Like

it’s working for me :grinning: