'Set map id using folium?

I m using folium (Django/Python), I create a map:

def create_map():
    m = folium.Map(location=[9.934739, -84.087502], zoom_start=7 )
    .....

folium creates the map in JS this way:

   var map_e87b2e996ca04be59a5cfedabc0bf1ad = L.map(
        "map_e87b2e996ca04be59a5cfedabc0bf1ad",
        {
            center: [9.934739, -84.087502],
               .....
        }
    );

What I need is a way to set the my own id from folium(Django) instead of the on-the-fly id created by deafult: map_e87b2e996ca04be59a5cfedabc0bf1ad

I need to do this because I want to create custom events on the map that affects others part of the html file where this map is embedded .



Solution 1:[1]

The full id is a combination of map._name and map._id If you want to override it, you can use something like:

map = folium.Map()
map._name = "map_name"
map._id = "1"

then if you call it with map.get_name() it will be map_name_1

Solution 2:[2]

You could reverse the problem, and rather managing the name yourself, use the specific one folium assigns in your custom HTML/CSS/JS, which you can access via some_map.get_name().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ben Fischer
Solution 2 Herbert