function createLabel(layer, text) {
  // remove label if exists
  removeLabel(layer);

  // create label
  const icon = createStaticLabelIcon(text);
  const testspan = document.createElement("span");

  // add testspan to body to get width
  document.body.appendChild(testspan);

  // add marker to map
  const label = L.marker(layer.getLatLng(), { icon }).addTo(map);

  // get width of label
  const getLabel = document.querySelector(`.${icon.options.className}`);
  const width = getLabel.offsetWidth;
  // set new iconAnchor
  icon.options.iconAnchor = [width / 2, -4];

  // set label to layer with new iconAnchor
  label.setIcon(icon);

  // remove testspan
  document.body.removeChild(testspan);
}
Create label

@param {object} layer
@param {string} text