Skip to content

writeTextToCanvas() background longer than rendered text #11705

@AnonymousSausage77

Description

@AnonymousSausage77

I am trying to draw text to a label and rotate it. I also want to give the rotated text a background. I found this function:
Cesium.writeTextToCanvas() which does this, except it always appends whitespace to the beginning of the word leaving an ugly 'padding'. In the sandcastle, I have illustrated this behaviour by creating two examples, one with a single character '3' and a longer word, both with this whitespace appended.

image
image

What I would expect to happen: I expect that the background (in the sandcastle, rendered as blue) would be the same length as the word that you enter and not any longer/shorter.

Sandcastle example:
https://sandcastle.cesium.com/#c=xZRdb5swFIb/yhE3JRIxEJIpydJoWxZpF50qLbQ3pRcOnASrxka2SZZW+e8zkI8q7aRdTBsIYx/O+9rnsUUqhTawYbhFBdcgcAsz1KwqyH0TcxMnbcYzKQxlAlXidD4mIhGthqAwzDDUhGaZ+5IIgPoppbZRKcZHtxlVxvaoiMhKyeIrrhWi/qwU3X1Dts6Ndh9qYX2F0ZB8CINwFHkA3ahPRr1w1Ot50AvgsfMQPHpt5pJxvpRUZWN4OWpZQdd4mnWrmMEYf5pYzqjYUG3LiRLHO+cDrGxhY0icsF8auLotUcCCCn3lgbavrkbFVlZyFixp+rRWshLZTHKpziXWI/Ll5m5+St53Tl0lDW2J9AdNcG/b/T9BGfTfogz/Bsp4bs9OPF/EF83/JhwGl4Tr2/dhgQZMjpDSAhVtjv2JfhsjK76LZUs/Q22YoH8A3205D70D4+HAg0EQtGuTitmdPdgcsORIMybWJ9vv1OTEyB82apG4Vgl2uXOqjQdCKpN7UJWvnVqbkpk0/51JNwqOcJTkfAwBCRosDRXHcyba7DhOj/w+saK0U0GluEuIb7AoObXF+ssqfUJDUq1rmHXqxH8tnWRsAyy7fudXASmnWtsvq4rzBXvGxJlOfJv/RsplQ+R2g4rTXZ2Wh9ObNkgImfh2+L7SSMmXVF04/wI

Browser: Chrome Version 120.0.6099.109 (Official Build) (arm64)

Operating System: MacOS Ventura 13.4 (22F66)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions