export function getTextOffsetByRadius()

in src/layers/layer-text-label.js [27:53]


export function getTextOffsetByRadius(radiusScale, getRadius, mapState) {
  return textLabel => {
    const distanceScale = getDistanceScales(mapState);
    const xMult = textLabel.anchor === 'middle' ? 0 : textLabel.anchor === 'start' ? 1 : -1;
    const yMult = textLabel.alignment === 'center' ? 0 : textLabel.alignment === 'bottom' ? 1 : -1;

    const sizeOffset =
      textLabel.alignment === 'center'
        ? 0
        : textLabel.alignment === 'bottom'
        ? textLabel.size
        : textLabel.size;

    const pixelRadius = radiusScale * distanceScale.pixelsPerMeter[0];
    const padding = defaultPadding;

    return typeof getRadius === 'function'
      ? d => [
          xMult * (getRadius(d) * pixelRadius + padding),
          yMult * (getRadius(d) * pixelRadius + padding + sizeOffset)
        ]
      : [
          xMult * (getRadius * pixelRadius + padding),
          yMult * (getRadius * pixelRadius + padding + sizeOffset)
        ];
  };
}