styleTextElement()

in src/lib/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js [224:264]


  styleTextElement(element, textStyle, position) {
    const style = element.style

    style.position = "absolute"
    style.left = position.left
    style.top = position.top
    style.textAlign = "center"
    style.whiteSpace = "nowrap"

    style.fontFamily = textStyle.fontFamily
    style.fontSize = textStyle.fontSize
    style.fontWeight = textStyle.fontWeight
    style.lineHeight = textStyle.lineHeight
    style.color = textStyle.color
    style.textShadow = textStyle.textShadow

    let { width, height } = this.getElementSize(element)

    if (textStyle.icon) {
      const iconSize = textStyle.icon.size

      // Add padding to text element where icon will appear, mainly so clicks on the icon will be
      // captured on the text element
      if (textStyle.icon.position === "left") {
        style.paddingLeft = `${iconSize + textStyle.icon.padding * 2}px`
      } else if (textStyle.icon.position === "right") {
        style.paddingRight = `${iconSize + textStyle.icon.padding * 2}px`
      }

      const iconSizeHeightDiff = iconSize - height

      if (iconSizeHeightDiff > 0) {
        style.paddingTop = `${iconSizeHeightDiff / 2}px`
        style.paddingBottom = `${iconSizeHeightDiff / 2}px`
      }
    }

    style.transform = textStyle.getTransform(width, height)

    return { width, height }
  }