我希望通过使用传单markercluster而不是图标为所有标记仅使用文本标签。用户无需单击每个图标,而可以直接在地图上看到这些值。
下面是我一直在玩的代码...
var marker_txt = new L.layerGroup();
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
$.getJSON("../text/text.geojson", function(json) {
var pointLayer = L.geoJSON(null, {
pointToLayer: function(feature,latlng){
label = String(feature.properties.total_sum)
return new L.marker(latlng, {icon:createLabelIcon("textLabelclassCluster",label)})
}
})
var createLabelIcon = function(labelClass,labelText){
return L.divIcon({
className: labelClass,
html: labelText
})
}
pointLayer.addData(json)
var markersText = new L.MarkerClusterGroup({
chunkedLoading: true,
maxClusterRadius: 80,
iconCreateFunction: function(cluster) {
var children = cluster.getAllChildMarkers();
var sum = 0;
for (var i = 0; i < children.length; i++) {
sum += children[i].feature.properties.total_sum;
}
//defaultIconCreate
var childCount = cluster.getChildCount()
var c = ' marker-cluster-blank';
return new L.DivIcon({ html: '<div><span>' + (round(sum,1)) + '</span></div>', className: 'marker-clusterwhite marker-clusterwhite-' + c, iconSize: new L.Point(40, 40) });
},
});
markersText.addLayer(pointLayer)
markersText.addTo(marker_txt);
});