How to open the popup automatically when a search is found for a GeoJson layer?
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- javascript, python
- Bereich
- data-visualization, frontend
Rechercherichtung
Beginne mit plugins/search.py und dem Beispiel plugin-Search.ipynb und führe dann die bereitgestellte GeoPandas- und Folium-Reproduktion in einem Browser aus. Untersuche den Handler search:locationfound und den gemeldeten Wert e.layer._popup; abgeschlossen ist die Aufgabe, wenn ein gesuchter GeoJSON-Zustand sein Popup automatisch öffnet, wie im erwarteten Leaflet-Beispiel.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 7.4k
- Forks
- 2.3k
- Ø Merge
- 17 Std. 22 Min.
- Gemergte PRs (30 T.)
- 11
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python-visualization/folium
-
documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
python-visualization/folium#2092 · 5 Kommentare ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 67/100
python-visualization/folium#2278 · 1 Kommentar ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
python-visualization/folium#2259 ·
-
Map output from OSM returns blocked tiles, due to defective request or not following referer-policy Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
python-visualization/folium#2236 · 5 Kommentare · 1 Reaktion ·
-
Touch Screen often fails Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 10/100
python-visualization/folium#2219 · 2 Kommentare ·
Alle Issues in python-visualization/folium
Ähnliche Issues
-
area: harness bug status: needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Human-Agent-Society/reef#625 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 80/100
learningequality/kolibri#15351 · 2 Kommentare ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Name consistency Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
eellak/triplestore#65 · 1 Kommentar ·