import PointLayer from './point'

class Label extends PointLayer {
  constructor(layer, scene, zIndex) {
    super(layer, scene, zIndex)
  }

  setShape() {
    let shape = this.layer.shape || ''
    this.layerInstance.shape(shape, 'text')
  }

  setStyle() {
    let { style } = this._mergeProperties()
    let { size, color } = style
    if (Number.isNaN(Number(size))) {
      this.layerInstance.size(size.field, size.value)
    } else {
      this.layerInstance.size(Number(size))
    }
    if (typeof color === 'string') {
      this.layerInstance.color(color)
    } else {
      this.layerInstance.color(color.field, color.value)
    }
    this.layerInstance.style({
      opacity: style.opacity,
      textAnchor: style.textAnchor,
      spacing: style.spacing || 0,
      padding: style.padding,
      stroke: style.stroke,
      strokeWidth: style.strokeWidth,
      strokeOpacity: style.strokeOpacity,
      fontWeight: style.fontWeight,
      fontFamily: style.fontFamily,
      textOffset: style.textOffset,
      textAllowOverlap: style.textAllowOverlap
    })
  }
}

export default Label
