1

我想通过以下方式向我的地图添加进度条:http: //leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.50000.html

问题是我在父集群组中使用子 featureGroups,这样我就可以在保持集群显示的同时轻松删除和添加图层。我尝试了以下两种方法:

  • Leaflet.MarkerCluster.LayerSupport:当我尝试时,加载栏根本不起作用:

    var mcgLayerSupportGroup = L.markerClusterGroup.layerSupport({ chunkedLoading: true, chunkProgress: updateProgressBar});

  • Leaflet.FeatureGroup.SubGroup:显示加载栏,但不显示添加的整体标记。相反,它是为每个标记子组计算的。加载栏可能会消失,然后再次出现,等等。

    var parentGroup = L.markerClusterGroup({ chunkedLoading: true, chunkProgress: updateProgressBar});

到目前为止,我最好的尝试是调整 updateProgressBar,但我的代码远非有效(缓慢且近似于进度条的行为):

var tot_processed=0;
//this total_markers variable is computed when I call my API endpoints and compute the total number of markers
var total_markers;

function updateProgressBar(processed, total, elapsed, layersArray) {
    tot_processed += processed;
    if (total_trees - tot_processed > 1000) {
        progress.style.display = 'block';
        progressBar.style.width = Math.round(tot_processed/total_trees*100) + '%';
    } else {
        if (processed === total) {
            // all markers processed - hide the progress bar:
            progress.style.display = 'none';
        }
    }
}

非常感谢!

4

0 回答 0