var myCustomColour = '#334455d0', // d0 -> alpha value
lat = 5.5,
lon = 5.5;
var caption = '', // '<i class="fa fa-eye" />' or 'abc' or ...
size = 10, // size of the marker
border = 2; // border thickness
var markerHtmlStyles = ' \
background-color: ' + myCustomColour + '; \
width: '+ (size * 3) +'px; \
height: '+ (size * 3) +'px; \
display: block; \
left: '+ (size * -1.5) +'px; \
top: '+ (size * -1.5) +'px; \
position: relative; \
border-radius: '+ (size * 3) +'px '+ (size * 3) +'px 0; \
transform: rotate(45deg); \
border: '+border+'px solid #FFFFFF;\
';
var captionStyles = '\
transform: rotate(-45deg); \
display:block; \
width: 100%;'+ (size * 3) +'px; \
text-align: center; \
line-height: '+ (size * 2.53) +'px; \
';
var icon = L.divIcon({
className: "color-pin-" + myCustomColour.replace('#', ''),
// on another project this is needed: [0, size*2 + border/2]
iconAnchor: [border, size*2 + border*2],
labelAnchor: [-(size/2), 0],
popupAnchor: [0, -(size*3 + border)],
html: '<span style="' + markerHtmlStyles + '"><span style="'+captionStyles+'">'+ caption + '</span></span>'
});
var marker = L.marker([lat, lon], {icon: icon})
.addTo(mymap);
// caption could be: '<i class="fa fa-eye" />',
function makeMarkerIcon(color, caption) {
let myCustomColour = color + 'd0';
let size = 10, // size of the marker
border = 2; // border thickness
let markerHtmlStyles = `
background-color: ${myCustomColour};
width: ${size * 3}px;
height: ${size * 3}px;
display: block;
left: ${size * -1.5}px;
top: ${size * -1.5}px;
position: relative;
border-radius: ${size * 3}px ${size * 3}px 0;
transform: rotate(45deg);
border: ${border}px solid #FFFFFF;
`;
let captionStyles = `
transform: rotate(-45deg);
display:block;
width: 100%;${size * 3}px;
text-align: center;
line-height: ${size * 2.53}px;
`;
let icon = L.divIcon({
className: 'color-pin-' + myCustomColour.replace('#', ''),
iconAnchor: [border, size*2 + border*2],
labelAnchor: [-(size/2), 0],
popupAnchor: [0, -(size*3 + border)],
html: `<span style="${markerHtmlStyles}"><span style="${captionStyles}">${caption || ''}</span></span>`
});
return icon;
}
var marker = L.marker([lat, lon], {icon: makeMarkerIcon('#123456d0', '?')})
.addTo(mymap);