AssertionError:如果该元素不在图中,则无法呈现该元素

时间:2019-11-25 13:03:58

标签: python folium

我编写了以下代码:

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")

而且我不断收到此错误消息:

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.

我正在尝试保存正在构建的地图的进度,并且不断显示错误消息

1 个答案:

答案 0 :(得分:2)

根据docsMarker应该添加到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)