我写信是想知道如何在 folium 的 timestempedgeojson 插件中设置自定义图标。我想知道两件事:
我试过这样做。 这是我的代码:
map = folium.Map(
location = [portici_gdf.centroid.y, portici_gdf.centroid.x],
tiles='cartodbpositron',
zoom_start= 15
)
folium.GeoJson(portici_gdf, style_function= lambda x: {'fillcolor':'blue'}).add_to(map)
这里是添加timestampgeojson插件的部分>
lines = [
{
'coordinates': f(gdf_f.loc['Piazza San Pasquale']['line']),
'dates':['2023-03-31T10:00:00']*len(f(gdf_f.loc['Piazza San Pasquale']['line'])),
'color': 'red',
},
]
features = [
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': line['coordinates']
},
'properties': {
'times': line['dates'],
'icon': 'test',
'iconstyle': {
'iconUrl': "./data/test.png",
},
'style': {
'color':line['color'],
}
}
}
for line in lines
]
TimestampedGeoJson(
{
'type':'FeatureCollection',
'features': features,
},
period='PT5M',
add_last_point=False,
).add_to(map)
第二个脚本第一行的函数f和gdf_f和portici_gdf上面的两个dataframe如下所示:
def f(frame):
xy = frame.xy
longs = xy[0].tolist()
lats = xy[1].tolist()
return [list(z) for z in zip(longs, lats)]
portici_gdf = ox.geocode_to_gdf("Portici, Italy")
gdf_f = gpd.GeoDataFrame(df, crs="EPSG:4326", geometry='geometry')
df 数据框显示为一个数据框,其中包含每个 steet 的一些 Multinistring 和一些质心坐标。
谢谢你的时间,祝你有美好的一天。