2

MarkerClusterGroup is a function that clusters points and return their aggregation.

See: example

In my case I have some polygons to which I calculated the centroids. Instead of returning the lines between centroids when hovering on the cluster. I want to return the polygons associated to those centroids. which means that I'll have a highlight on the polygons that have been clustered.

Basically, this is what I did for the time being, it will create the cluster and return the volume. But I want Onhover to highlight the polygons assiciated with the markers(centroids in my case):

var clusters = L.markerClusterGroup({

              iconCreateFunction: function(cluster) {
                var markers = cluster.getAllChildMarkers();
                var volume = 0;
                for (var i = 0; i<markers.length;i++){
                  if (!isNaN(markers[i].value)){
                    volume += markers[i].value
                  }                     
                }

                return L.divIcon({ html: '<b> Total Volume: ' + volume + '</b>' });
              }
            });

how can I achieve it ?

0

I found it: First we pass the identifier of our Geojson polygon as an option in the marker by extending it.

Then we need to add another option in the MarkerClusterGroup that will take the geojson variable.

third, Modify the showCoverageOnHover Property in the library and adapt it with your needs.

I hope this helps !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.