传单标记工具提示居中

0x4*_*x45 5 javascript css markers leaflet

我想在标记的中心(内部)显示工具提示。

背景

我想显示每个标记的计数(第一个 - > 最后一个),我发现我可以用工具提示来做到这一点(任何更好的建议)

所以我的标记现在看起来像这样,

var marker = L.marker(latlng, {icon: blueIcon}).bindTooltip(feature.properties.count, 
                    {
                permanent: true, 
                direction: 'right'
            });
Run Code Online (Sandbox Code Playgroud)

我找不到任何关于方向centered或类似的进一步文档。

工具提示提供了查看第一个和最后一个标记的功能,但这似乎不是最佳实践。

所以我的问题:

  • 有没有比工具提示更好的解决方案?
  • 如何显示以标记为中心的计数?

例子

当前的: 在此处输入图片说明

通缉: 在此处输入图片说明

(在这里,我将背景设置为隐形,以便我可以看到文本。)

0x4*_*x45 4

我发现你可以添加direction: center. 参考: http: //leafletjs.com/reference-1.0.0.html#tooltip-direction

我已经用DivIcon解决了我的问题

var numberIcon = L.divIcon({
                    className: "number-icon-default",
                    iconSize: [25, 41],
                    iconAnchor: [10, 44],
                    popupAnchor: [3, -40],
                    html: feature.properties.count        
              });
Run Code Online (Sandbox Code Playgroud)

像这样的CSS

    .number-icon-default
{
    background-image: url("#{request.contextPath}/lib/leaflet/images/marker-icon.png");
    text-align:center;
    color:Black;   
    text-shadow: 1px 1px #000000;
    font-size: large;
    font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)

结果

在此输入图像描述