Search code examples
pythonfolium

AssertionError: You cannot render this Element if it is not in a Figure


I wrote the following code:

import folium
map = folium.Marker(location=[80, -100], zoom_start=6, tiles="Mapbox Bright")
fg = folium.FeatureGroup(name="My map")
fg.add_child(folium.Marker(location=[80, -100], popup="Marker Here", icon=folium.Icon(color="green")))

map.save("Map.html")

and i keep getting this error message:

Traceback (most recent call last):
  File "c:/Users/king/Desktop/applications/mapping/maps.py", line 6, in <module>
    map.save("Map.html" )
  File "C:\Users\king\AppData\Local\Programs\Python\Python38-32\lib\site-packages\branca\element.py", line 169, in save
    html = root.render(**kwargs)
  File "C:\Users\king\AppData\Local\Programs\Python\Python38-32\lib\site-packages\branca\element.py", line 614, in render
    assert isinstance(figure, Figure), ('You cannot render this Element '
AssertionError: You cannot render this Element if it is not in a Figure.

i am trying to save the progress of the map i'm building and it keeps bringing up the error message


Solution

  • According to the docs the Marker should be added to a Map

    map = folium.Map(
            location=[80, -100],
            zoom_start=6,
            tiles="Mapbox Bright"
          )
    
    fg = folium.FeatureGroup(name="My map")
    
    folium.Marker(
        location=[80, -100],
        popup="Marker Here",
        icon=folium.Icon(icon='green')
    ).add_to(map)