簡體   English   中英

如何在 geojson 彈出窗口中顯示信息 - Python

[英]How to display information in geojson popup - Python

我在從 JSON 文件檢索信息的 folium 彈出窗口中顯示信息時遇到問題。 目前,我的代碼只從我的 JSON 文件中檢索最后一條信息並將其插入到所有彈出窗口中,因此我所有的彈出窗口只顯示一條信息。 我似乎無法弄清楚每個節點在其彈出窗口中都有自己獨特的信息。 任何幫助表示贊賞。

# reading JSON file
with open('exportBuilding.geojson') as access_json:
    read_content = json.load(access_json)

feature_access = read_content['features']

# Creating Folium Map
m = folium.Map(location=[1.400150, 103.910172], titles="Punggol", zoom_start=17)
nodeData = os.path.join('exportBuilding.geojson')
geo_json = folium.GeoJson(nodeData)

# retrieve all names and store in popup
for feature_data in feature_access:
    property_data = feature_data['properties']
    geo_json.add_child(folium.Popup(property_data['name'))

geo_json.add_to(m)

對於與我面臨相同問題的任何人,最新的 folium 中有一個名為“GeoJsonPopup”的函數,它將從 JSON 文件中檢索您指定的所有信息並將其顯示在彈出窗口中,從而解決所有節點都將擁有其擁有獨特的個人信息。

而不是創建一個 for 循環來循環整個 JSON,

# reading JSON file
with open('exportBuilding.geojson') as access_json:
    read_content = json.load(access_json)

feature_access = read_content['features']

# Creating Folium Map
m = folium.Map(location=[1.400150, 103.910172], titles="Punggol", zoom_start=17)
nodeData = os.path.join('exportBuilding.geojson')

# This is retrieve all information, in this case is name from my JSON file 
# and display it into my popup, such that all nodes 
# will have its own unique information.
geo_json = folium.GeoJson(nodeData, popup=folium.GeoJsonPopup(fields=['name']))

geo_json.add_to(m)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM