将文本添加到Folium FastMarkerCluster标记?

2024-10-06 12:25:14 发布

您现在位置:Python中文网/ 问答频道 /正文

通过下面的代码,我尝试向foliumfastmarkercluster添加文本记号笔。那个下面的代码生成一个映射,但添加文本没有成功。文本包含为与每个lon lat对相对应的字符串。在

我认为这个问题与包含文本列的df是pandas系列对象有关。据我所知,这就是在这种情况下应该如何说明的数据框列名称'. 然而,这没用。我也试着把这个专栏变成一个列表,但是这种方法也没有成功。任何建议都值得赞赏。在

xlat = guns2013['latitude'].tolist()
xlon = guns2013['longitude'].tolist()
locations = list(zip(xlat, xlon))
map2 = folium.Map(location=[38.9, -77.05], tiles='CartoDB dark_matter', 
zoom_start=1)
marker_cluster = MarkerCluster().add_to(map2)
for point in range(0, len(locations)):
   folium.Marker(locations[point], 
   popup='guns2013.texts'[point]).add_to(marker_cluster)

map2

Tags: to代码文本addmarkerpointclusterlocations
2条回答

我尝试了一下,最终您可以将弹出窗口从python传递给callback函数,如下所示:

some_map = folium.Map(location=[df['latitude'].mean(), df['longitude'].mean()], zoom_start=9) callback = ('function (row) {' 'var marker = L.marker(new L.LatLng(row[0], row[1]), {color: "red"});' 'var icon = L.AwesomeMarkers.icon({' "icon: 'info-sign'," "iconColor: 'white'," "markerColor: 'green'," "prefix: 'glyphicon'," "extraClasses: 'fa-rotate-0'" '});' 'marker.setIcon(icon);' "var popup = L.popup({maxWidth: '300'});" "const display_text = {text: row[2]};" "var mytext = $(`<div id='mytext' class='display_text' style='width: 100.0%; height: 100.0%;'> ${display_text.text}</div>`)[0];" "popup.setContent(mytext);" "marker.bindPopup(popup);" 'return marker};') some_map.add_child(FastMarkerCluster(df[['latitude', 'longitude','use_code_name']].values.tolist(), callback=callback))

和13;
和13;

果然,答案来了。也许这对面对同样问题的人有帮助。如果文本没有得到映射,请检查包含它的df不是pandas系列对象,如果是,则用第一行转换为pandas df。剩下的就行了。在

^{1}$

相关问题 更多 >