我有一组 geoJSON 点,它们附加了相应的标签。
var points = L.geoJson (null, {
onEachFeature: function (feature, layer) {
layer.options.riseOnHover=true; //tried adding this
layer.options.riseOffset=9999; //as well as this
layer.bindLabel(feature.properties["name"], {className: 'map-label'});
L.setOptions(layer, {riseOnHover: true}); //this as well
}
});
这是遍历 JSON 文件中的每个功能并创建点集的代码。现在,向地图添加标记的实际函数如下所示:
var addJsonMarkers = function() {
map.removeLayer(markers);
points.clearLayers();
markers = new L.layerGroup();
points.addData(dataJson);
markers.addLayer(points);
map.addLayer(markers);
return false;
};
我遇到的问题是,无论我尝试添加什么(您可以看到我的评论),标签始终位于标记后面,这不是预期的行为。
我希望标签位于其顶部。我尝试手动更改z-index
in the map-label
类,以及众多解决方案riseOnHover
这似乎是解决方案,但标签仍然落后。有人看到我做错了什么吗?
完整代码可见here http://pastebin.com/2iH3U0a7
Specify popupPane
as pane
in bindLable
选项:
layer.bindLabel(
feature.properties["name"],
{
className: 'map-label',
pane:'popupPane'
}
);
在Leaflet中,popupPane高于markerPane,因此您的标签将显示在标记的顶部。
Leaflet.label 有一个小文档,其中包含选项描述https://github.com/Leaflet/Leaflet.label https://github.com/Leaflet/Leaflet.label
另请检查这个 jsfiddle:http://jsfiddle.net/L6kqu54a/ http://jsfiddle.net/L6kqu54a/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)