我正在使用带有 Leaflet.js 的 geoJson 层,在此处显示国家/地区。
我正在添加具有以下内容的国家/地区标签:
L.marker(layer.getBounds().getCenter(), {
icon: L.divIcon({
className: 'countryLabel',
html: feature.properties.name,
iconSize: [0, 0]
})
}).addTo(map);
问题是,此应用的标记会阻碍每个国家/地区的鼠标悬停,从而导致鼠标悬停颜色变化和可点击区域出现问题。
传单 1.0.3 中是否有更好的解决方案来提供不会阻碍国家可点击区域的标签?
我尝试过使用 Leaflet.Label 扩展的代码,如下所示:
var label = new L.Label();
label.setContent(feature.properties.name);
label.setLatLng(center);
map.showLabel(label);
或者
L.marker(center)
.bindLabel('test', { noHide: true })
.addTo(map);
但是这些会导致错误;我知道这个插件的功能在 v1 之后被合并到 Leaflet.js 本身。
这确实有效,但我宁愿使用简单的标签而不是工具提示:
var marker = new L.marker(center, { opacity: 0.00 }); //opacity may be set to zero
marker.bindTooltip(feature.properties.name, { permanent: true, className: "my-label", offset: [0, 0] });
marker.addTo(map);
任何想法都会受到欢迎。