1

多くの場合、markercluster が必要です。クラスターの子の数ではなく、マップ内のマーカーの総数の割合 (% の形式) を表示すると非常に興味深いでしょう。したがって、そのクラスターに 20 のメーカーがあり、マップ内の合計が 200 の場合、マップのその地域で 20 ではなく 10% を表示したいと思います。

誰でもそれを実装する方法について何か考えがありますか?

ありがとうございました


ソリューションをありがとう、それは非常にシンプルでうまく機能します。ソリューションのコードは次のとおりです。

    $.getJSON(link, function(data) {
        var total_number = data.features.length; //Here I get the total number of markers
        var others = L.geoJson(data, {
            onEachFeature: function (feature, layer) {
                layer.bindPopup('Number: ' + feature.properties.Nr+' Residency:'+ feature.properties.Lives);
            },
         })
    var markers = L.markerClusterGroup({
        iconCreateFunction: function(cluster) {
            var markers = cluster.getAllChildMarkers();
            var n = ((markers.length/total_number)*100).toFixed(1);;
            return L.divIcon({ html: n+'%', className: 'mycluster', iconSize: L.point(40, 40) });
        },
    });

「myclusters」の CSS は次のとおりです。

    .mycluster {
        width: 150px;
        height: 15px;
        background-color: greenyellow;
        text-align: center;
        font-size: 18px;
    }

ありがとうございました

4

1 に答える 1