传单中心标记号

Leaflet Center Marker Numbers

有谁知道如何将标记内的数字居中?这是目前的情况。

Marker with Number

创建标记

    return L.divIcon({
  className: "green-icon",
  iconSize: [25, 41],
  iconAnchor: [10, 44],
  popupAnchor: [3, -40],
  html: markerNumber,
});

CSS

.green-icon {
 background-image: url("../GreenIcon.png");
 background-repeat: no-repeat;
 margin: 0 auto;
 text-align: center;
 color: white;
 font-weight: bold;
 }

这应该有效。


 return L.divIcon({
  className: "green-icon",
  iconSize: [25, 41],
  iconAnchor: [10, 44],
  popupAnchor: [3, -40],
  html: `<span class="icon-text">${markerNumber}</span>`
})

将此添加到您的 CSS。

.icon-text {
  text-align: center;
}

.green-icon {
  display: grid;
  align-items: center;
}

JSfiddle example