当标记被编码为层而不是单独构建时,自定义 Leaflet 标记?

Custom Leaflet markers when markers are coded as a layer, not built individually?

改编自 this tutorial 的传单地图构建了如下标记:

async function render_markers() {
const markers = await load_markers();
L.geoJSON(markers)
    .bindPopup((layer) => layer.feature.properties.name)
    .addTo(layerGroup);
}

我想将此地图的标记更改为 this good thread 中推荐的任何解决方案。但我不知道如何处理它们,因为所有标记似乎都是单独构建的,例如:

L.marker([51.5, -0.09], {icon: greenIcon}).addTo(map);

Leaflet documentation also only seems to show how to change markers individually. How can we get a solution like this 使用我们的地图构建方式?我们缺少什么?

您正在搜索此 Leaflet-Tutorial

要自定义标记或圆圈,您需要添加 pointToLayer 函数:

L.geoJSON(markers, {
    pointToLayer: function (feature, latlng) {
        return L.marker(latlng, {icon: greenIcon} );
    }
})
    .bindPopup((layer) => layer.feature.properties.name)
    .addTo(layerGroup);