Clustering markers to improve our map
As we already saw, creating markers and adding them to a map is not a difficult task at all. There are circumstances in which creating the markers one by one may work; however, what happens if the data we want to visualize has thousands of records?
Populating the map with large amounts of data is inefficient performance-wise, and the lag dominates the user experience. The user will not be able to distinguish the markers and have a clear picture of what is going on in this crowded map. Surely, this is a poor user experience.
In this recipe, you will learn how to use clustering to present data in a more efficient and clean way.
How to do it…
Perform the following steps:
Import the Leaflet.markercluster plugin.
Create a new
featureLayer
and add the data you want to use as features.Once the data in the
featureLayer
is loaded, create aclusterGroup
and add the features layer to it.
Creating markers
Perform the following steps:
Open the
chapter-4-example6-starter
...