Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

javascript - How to customize leaflet labels? and when I change the opacity, it changes opacity of the fonts as well

let myIcon = L.icon({
iconUrl: 'images/Province_Center.png',
iconSize: [9.2, 9],
});

L.marker([34.537205, 69.191150],{icon:myIcon}).bindTooltip("Kabul",{permanent: true, direction: 
'right'}).addTo(map),
L.marker([34.349708, 62.203600],{icon:myIcon}).bindTooltip("Herat",{permanent: true, direction: 
'right'}).addTo(map),
L.marker([34.427256, 70.457220],{icon:myIcon}).bindTooltip("Nangarhar",{permanent: true, direction: 
'right'}).addTo(map),
L.marker([36.708842, 67.110785],{icon:myIcon}).bindTooltip("Balk",{permanent: true, direction: 
'right'}).addTo(map),

I want to change the font color, background color and the label position.

question from:https://stackoverflow.com/questions/65850953/how-to-customize-leaflet-labels-and-when-i-change-the-opacity-it-changes-opaci

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can add html to the tooltip instead of plain text:

L.marker([34.537205, 69.191150]).bindTooltip("<span style='font-size: 40px'>Kabul</span>",{permanent: true, direction: 'right'}).addTo(map);

Also you can add your own css style to the tooltip:

.leaflet-tooltip {
    background-color: #f00;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...