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
- json code in an js-file "target-location_09_14.js" with marker-polygones and value for each marker
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
Then create one instance of
MarkerClusterGroupper governorate, and add each marker to the corresponding cluster group.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.
They are not random, the hierarchical greedy clustering algorithm is deterministic. You can read more at https://www.mapbox.com/blog/supercluster/