How to open the popup automatically when a search is found for a GeoJson layer?
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript, python
調査の方向性
plugins/search.py と plugin-Search.ipynb の例から始め、続いて提供されている GeoPandas と Folium の再現コードをブラウザで実行します。search:locationfound ハンドラーと報告された e.layer._popup の値を調べます。期待される Leaflet の例と同様に、検索した GeoJSON の州が自動的にポップアップを開けば完了です。
索引モデルが 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
- 平均マージ
- 17時間 22分
- マージ済み PR(30日)
- 11
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-visualization/folium のほかの issue
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
python-visualization/folium#2092 · コメント 5 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
python-visualization/folium#2278 · コメント 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
python-visualization/folium#2259 ·
-
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 · コメント 5 件 · リアクション 1 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
python-visualization/folium#2219 · コメント 2 件 ·
python-visualization/folium の issue をすべて見る
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
syfoud/Simulated_Scepter#174 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Giskard-AI/giskard-oss#2840 · コメント 1 件 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success オープンarea: repo bug perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
yeti-platform/yeti#1380 ·