简体   繁体   中英

Leaflet Center Marker Numbers

Does anyone have an idea how to center numbers inside markers? This is the current situation.

Marker with Number

Creating a Marker

    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;
 }

This should work.


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

Add this to your CSS.

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

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

JSfiddle example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM