0
我正在試圖爲我創建的一些CircleMarkers添加一個靜態標籤。這些標記被添加到LayerGroup中,然後添加到地圖中。我讀過我需要在將對象添加到地圖後調用.showLabel()。但是由於我先構建LayerGroup,然後將其添加到地圖中,我不確定如何執行此操作。如何顯示LayerGroup中的對象的Leaflet靜態標籤?
我想過使用L.LayerGroup.eachLayer,但我不確定哪個對象實際上會調用.showLayers()。我的代碼如下,任何幫助表示感謝,謝謝!
var jsonLayers = new L.LayerGroup();
jsonLayers.addLayer(L.geoJson(mapFeature.features[i], {
style: function (feature) {
return feature.properties && feature.properties.style;
},
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
var newCircle = L.circleMarker(latlng, {
radius: 5,
fillColor: fColor,
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
});
newCircle.bindLabel(feature.properties.name, { noHide: true });
return newCircle;
}
}));
map.addLayer(jsonLayers);
當我嘗試: jsonLayers.eachLayer(功能(層){ layer.showLabel(); }); 我得到一個showLabel不是函數的錯誤。 – alecdhuse
根據https://github.com/Leaflet/Leaflet.label/issues/31,CircleMarker似乎不支持此功能。 – alecdhuse
你見過https://github.com/Leaflet/Leaflet.label嗎? – gibbocool