Skip to content

How to make a python folium interactive map with draggable legend and clickable items to zoom into the corresponding locations #1753

@xiaozheshen

Description

@xiaozheshen

Is your feature request related to a problem? Please describe.
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

This is what I have so far
`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, it seems the preview function is not compatible with html script here, so it does not display the full script. If you can look at the raw script you can see clearer. But basically here is to add html for the legend.
legend_html = """


Legend

New York City

Boston

"""

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

Describe the solution you'd like
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.

Describe alternatives you've considered
Not yet.

Additional context
N/A

Implementation
If there is convenient function to implement the features I asked for, I definitely would be happy to write a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions