I am trying to create an interactive map using python folium package. The feature I am looking for is, for a given list of locations, there are icons on the map, and a draggable legend (so that one can reposition the legend by dragging it using the mouse) for each of the locations, and one can click on one of the items in the legend to zoom into the corresponding location on the map.

Could you show me a minimum script (say for two locations, New York and Boston) so that I can get started?

Many thanks! Sam

I am not familiar with the API, and I searched over the internet, but did not get useful information to get started. So I am asking if someone can give a minimum example to give me a jump start.

1

There are 1 best solutions below

0
Sam Sam On

I have so far the following scripts which give me the icons and legend, but not the draggable function nor the clickable legend item zooming-in function.

import folium

# create map object centered at New York City
m = folium.Map(location=[40.7128, -74.0060], zoom_start=10)

# add marker for New York City with icon
folium.Marker(
    location=[40.7128, -74.0060],
    popup='New York City',
    icon=folium.Icon(icon='star')
).add_to(m)

# add marker for Boston with icon
folium.Marker(
    location=[42.3601, -71.0589],
    popup='Boston',
    icon=folium.Icon(icon='cloud')
).add_to(m)

# create legend and add to map
legend_html = """
     <div style='position: fixed; 
                 bottom: 50px; left: 50px; width: 150px; height: 90px; 
                 border:2px solid grey; z-index:9999; font-size:14px;
                 background-color:white; padding: 10px;'>
         <b>Legend</b><br>
         <i class='fa fa-star fa-2x' style='color:blue'></i> New York City<br>
         <i class='fa fa-cloud fa-2x' style='color:green'></i> Boston
     </div>
"""

m.get_root().html.add_child(folium.Element(legend_html))