Get a list of leaflet marker clusters within current map bounds in Leaflet

Viewed 310

I am using leaflet.markercluster plugin to show clusters on my map and getting information about each cluster on hover/click event.

What I'd like to do now is set it up so that if a user zooms or pans the map, it returns list of clusters within the current map bounds.

    var option = {
        useCanvas: true,
        anchorWidth: 20,
        anchorHeight: 40,
        canvasPadding: 0.0,
        map: map
    };
    var clusterMarkers = L.markerClusterGroup(options, { chunkedLoading: true });

    for(var i = 0;i<pakData.length;i++){
      option.lat = pakData[i][0];
      option.lng = pakData[i][1];    
    var marker = TPLMaps.overlays.point(option);
    clusterMarkers.addLayer(marker);
    
    }
    map.addLayer(clusterMarkers);
    clusterMarkers.addEventListener('clusterclick', (e)=>{
        console.log(e); // I want list of these e.target within current bounds
    })
0 Answers
Related