Leaflet.js markerCluster Performace Issue

Viewed 43

I drew markers on the map by using leaflet.js library (It's about 8500 markers). But the performance was so poor that I used markerCluster. But It also takes too much time to draw the markers. Is there any way to improve performance?

let _handler = this;

//get marker data
let data = _handler.getData();

//create markerCluster
let markers = L.markerClusterGroup({
            chunkedLoading:true, 
            removeOutsideVisibleBounds:true, 
            animate:false, 
            showCoverageOnHover:false,
            disableClusteringAtZoom:17,
            iconCreateFunction:function(cluster){
                let className = count >= 100 ? 'max-cluster-icon' : count < 100 && count >= 20 ? 'med-cluster-icon' : 'min-cluster-icon'; 
                let icon = L.divIcon({
                    html:`<div class="cluster-icon ${className}"><div><span>${cluster._childCount}</span></div></div>`
                });
                return icon;
            }});

var markerList = [];

data.forEach((val)=>{
            let {lat, lng} = val;
            if(lat && lng){
                        let icon = _handler.icons.get("icon-normal");
                        icon.options.iconSize = [30,30];
                        
                        let marker = L.marker([lat, lng], {icon:icon});
                        let html = getPopup(val);
                        marker.bindPopup(html);
                        markerList.push(marker);
            }
});

//add marker list to the markerCluster
markers.addLayers(markerList);
//add markerCluster to the map
map.addLayer(markers);
0 Answers
Related