Python Forum
Folium FastMarkerCluster - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Folium FastMarkerCluster (/thread-10699.html)



Folium FastMarkerCluster - OgnjanD - Jun-01-2018

I am plotting gun violence incidents in the U.S. with folium FastMarkerCluster. The code bellow does the job rather well.

lats2018 = guns2018['latitude'].tolist()
lons2018 = guns2018['longitude'].tolist()

locations = list(zip(lats2018, lons2018))
popups = ['lon:{}<br>lat:{}'.format(lons2018, lats2018) for (lats2018, 
lons2018) in locations]
icon_create_function = """\
function(cluster) {
return L.divIcon({
html: '<b>' + cluster.getChildCount() + '</b>',
className: 'marker-cluster marker-cluster-large',
iconSize: new L.Point(20, 20)
});
}"""

b = folium.Map(
location=[np.mean(lats2018), np.mean(lons2018)],
tiles='Cartodb Positron',
zoom_start=1
)

marker_cluster = MarkerCluster(
locations=locations, popups=popups,
overlay=True,
control=True,
icon_create_function=icon_create_function
)

marker_cluster.add_to(b)
folium.LayerControl().add_to(b)

b.save(outfile= "2018.html")
I'm looking for a way to add text to the markers - this is text I have scrapped from articles. I have been at this for nearly a week and feel like I've exhausted all resources. Any and all help about how to go about this is much appreciated. The texts are stored in the pandas df where the lon and lat also come from.