使用folium将文件夹链接添加到python geocoder中

2024-09-30 16:34:50 发布

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

我想用单个地理文件扫描存档数据(列出的DIC),并将文件路径作为链接添加到弹出窗口中:

locations_map = Map()
locations_map.add_child(
   Marker(location = [47.981300, 7.842700],
                     icon = folium.Icon(color = 'blue')));

file_dict = [{'file' : '/data/test 6/', 'go' : 'one', 'loc' : '47.981367, 7.842787'},
             {'file' : '/data/TEST4a/', 'go' : 'two', 'loc' : '47.981767, 7.842097'}]

for i in pd.Series(file_dict):
    name = i['go']
    file_dir = i['file']
    locations = i['loc'].split(",")
    folium.features.RegularPolygonMarker(location = [locations[0], locations[1]],
                                        tooltip = name,
                                        popup = "Name:" + name 
                                         + "Location: " + ("<a href=file_dir>open</a>")
                                         ).add_to(locations_map)

要在浏览器中打开,请执行以下操作:

locations_map.save("locations_map.html")
webbrowser.open("locations_map.html", new=2);

输出为/MyMagnumMint/Archive-Mapping/file_dir,而不是/MyMagnumMint/Archive-Mapping/data/test 6//MyMagnumMint/Archive-Mapping/data/TEST4a/

我尝试使用不同的引号("<a href='file_dir'>open</a>")和RegularPolygonMarkers的“https”特性


Tags: 文件nameaddgomapdatadirlocation
1条回答
网友
1楼 · 发布于 2024-09-30 16:34:50

已解决:

for i in pd.Series(file_dict):
     name = i['go']
     file_dir = i['file']
     hyperlink_format = '<a href="{link}">{text}</a>'
     hyperlink = hyperlink_format.format(link=directory, text='open')
     locations = i['loc'].split(",")
     folium.features.RegularPolygonMarker(location = [locations[0], locations[1]],
                                    tooltip = name,
                                    popup = "Name:" + name 
                                     + "Location: " + hyperlink
                                     ).add_to(locations_map)

谢谢这个post

相关问题 更多 >