Search code examples
pythonpython-3.xhttpfolium

Add folder links into python geocoder with folium


I want to scan archived data (listed dics) with individual geofiles and add the file path as link into the popup:

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)

to open in browser:

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

the output gives me /MyMagnumMint/Archive-Mapping/file_dir, instead of /MyMagnumMint/Archive-Mapping/data/test 6/ and /MyMagnumMint/Archive-Mapping/data/TEST4a/.

I tried with different quotes ("<a href='file_dir'>open</a>") and the "https" feature for RegularPolygonMarkers.


Solution

  • solved:

    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)
    

    thx to this post!