How to open the popup automatically when a search is found for a GeoJson layer?
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- javascript, python
研究方向
先從 plugins/search.py 和 plugin-Search.ipynb 範例開始,然後在瀏覽器中執行提供的 GeoPandas 和 Folium 重現程式。檢查 search:locationfound 處理常式以及回報的 e.layer._popup 值;當搜尋到的 GeoJSON 州能像預期的 Leaflet 範例中那樣自動開啟其彈出視窗時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Please add a code sample or a nbviewer link, copy-pastable if possible
# Your code here
import folium
import branca
import geopandas
from folium.plugins import Search
print(folium.__version__)
states = geopandas.read_file(
'https://rawcdn.githack.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json',
driver='GeoJSON'
)
min, max = states['density'].quantile([0.05,0.95]).apply(lambda x: round(x, 2))
colormap = branca.colormap.LinearColormap(
colors=['#f2f0f7','#cbc9e2','#9e9ac8','#756bb1','#54278f'],
index=states['density'].quantile([0.2,0.4,0.6,0.8]),
vmin=min,
vmax=max
)
colormap.caption="Population Density in the United States"
m = folium.Map(location=[38,-97], zoom_start=4)
style_function = lambda x: {
'fillColor': colormap(x['properties']['density']),
'color': 'black',
'weight':2,
'fillOpacity':0.5
}
stategeo = folium.GeoJson(
states,
name='US States',
style_function=style_function,
popup=folium.GeoJsonPopup(
fields=['name', 'density'],
aliases=['State', 'Density'],
localize=True
)
).add_to(m)
statesearch = Search(
layer=stategeo,
geom_type='Polygon',
placeholder='Search for a US State',
collapsed=False,
search_label='name'
).add_to(m)
folium.LayerControl().add_to(m)
colormap.add_to(m)
m
Problem description
I was trying to make the popup open automatically when a search is found in a GeoJson layer. My code is modified from an example code "plugin-Search.ipynb". I am using the "master" version of folium on the github. Right now, my code cannot open the popup when a search is found. I checked the source code "search.py" in "plugins" folder. The code is:
{{this.layer.get_name()}}searchControl.on('search:locationfound', function(e) {
{{this.layer.get_name()}}.setStyle(function(feature){
return feature.properties.style
})
{% if this.options %}
e.layer.setStyle({{ this.options|tojson }});
{% endif %}
if(e.layer._popup)
e.layer.openPopup();
})
I think the code should open popup if location is found but it did not.
I manually added console.log(e.layer._popup) in front of if(e.layer._popup) in the html file. When I searched one state on the web page, the console outputs "undefined" for e.layer._popup. It's confusing to me.
Expected Output
I expect to open the popup automatically when a search is found like this leaflet search example https://labs.easyblog.it/maps/leaflet-search/examples/geojson-layer.html.
Output of folium.__version__
0+unknown
- 主要語言
- Python
- 星號
- 7.4k
- 分支
- 2.3k
- 平均合併
- 2 天 4 小時
- 30 天內合併 PR
- 10
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python-visualization/folium 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
python-visualization/folium#2293 · 2 則留言 ·
維護者通常 1 天內回覆
-
Make it more obvious how to add text可能已有人在做 @mosessamofficial-sys 於 227 天前認領。 未關閉documentation
難度 2/5 1-3 小時 新手友好度 68/100
python-visualization/folium#2092 · 5 則留言 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 25/100
python-visualization/folium#2259 ·
維護者通常 1 天內回覆
-
Map output from OSM returns blocked tiles, due to defective request or not following referer-policy未關閉
難度 3/5 1-2 天 新手友好度 55/100
python-visualization/folium#2236 · 8 則留言 · 2 個 reaction ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 10/100
python-visualization/folium#2219 · 2 則留言 ·
維護者通常 1 天內回覆
查看 python-visualization/folium 的全部 Issue
相似的 Issue
-
enhancement good first issue
難度 2/5 1-3 小時 新手友好度 78/100
-
python-version
難度 1/5 1 小時以內 新手友好度 88/100
-
bug
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆
-
bug javascript P2-medium python release:v3.1
難度 2/5 1-3 小時 新手友好度 68/100
adrirubio/claude-deck#546 ·
維護者通常 1 天內回覆
-
area: desktop area: website priority: P2 type: feature
難度 2/5 1-3 小時 新手友好度 62/100
appandflow/stim#3411 · 1 則留言 ·
維護者通常 1 天內回覆