jsonleafletmarkerclusterermkcoordinateregionleaflet.markercluster

Leaflet markercluster: How can I change the bounds of the markercluster?


For university I create a webmap using leaflet - it´s about migration in Iraq. In the map I have one choropleth-layer with coordinates from a json (Iraq with its gouvernorates) with a value for each gouvernorate. Additionally I added a layer with markers from another json to the map. This json only contains the coordinates for markers with a value for each marker. I implemented a leaflet markerclustering where all child markers are summarized and the sum is shown in the parent-icon - although the sum isn´t correct until now, I think it is working, so far... I am allready looking for the mathematical error...

Now, I would like to change the bounds for the marker-clustering (currently I think they are built automatically and randomly by leaflet) to the bounds of the gouvernorates in the first json of Iraq. The aim is a regionbound clustering for the gouvernorates of Iraq. There are some examples on the web and I have tried a lot, but it doesn´t work... maybe somebody here can help me.. If you have any questions or need further explanation, just tell me!

Sources: - json code in an js-file "iraq_09_14.js" with the gouvernorate-polygon-coordinates of Iraq

this is the js-code where I create the leaflet map

this is the js-code where I create the markerclusters with the sum of the values


Solution

  • I would like to change the bounds for the marker-clustering [...] to the bounds of the gouvernorates in the first json of Iraq.

    Then create one instance of MarkerClusterGroup per governorate, and add each marker to the corresponding cluster group.

    This json only contains the coordinates for markers with a value for each marker.

    You should really pre-process the data, so each marker has information about what governorate it belongs to. You might want to do point-in-polygon geoprocessing, via Turf or otherwise.

    (currently I think [the clusters] are built automatically and randomly by leaflet)

    They are not random, the hierarchical greedy clustering algorithm is deterministic. You can read more at https://www.mapbox.com/blog/supercluster/