python-visualization / python-visualization/folium
Features not displayed with style_function
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 7.4k
- Fork
- 2.3k
- Merge medio
- 17h 22m
- PR unite (30g)
- 11
Descrizione
Describe the bug
When loading a set of GeoJSON LineString features, they are not displayed on the Folium map in my Jupyter Notebook (GColab, as well) when using style_function. If style_function=style_functions is removed from the following code, the features are displayed correctly, even though without styling.
To Reproduce
import folium
import json
# Load the GeoJSON file
with open('demo.json') as f:
data = json.load(f)
# Create a Folium map centered on a location of your choice
m = folium.Map(location=[37.982759260869564, 23.901986296376812], zoom_start=18)
# Define a style function that changes the color of LineString features
def style_functions(feature):
color = 'red' # Change the color to your desired color or use a custom logic
return {
'color': 'blue',
'weight': 3,
'opacity': 0.7,
'dashArray': [5, 10]
}
# Add the GeoJSON data to the map with the style function applied
folium.GeoJson(data, style_function=style_functions).add_to(m)
# Display the map
m
Demo GeoJSON has been attached. Please remove the .txt extension for it to load.
demo.json.txt
Expected behavior
style_function should not hide the features, but display them with the styling specified.
Environment (please complete the following information):
- Browser [e.g. firefox]
- Jupyter Lab & Google Colab
- Python 3.10.12
- folium 0.14.0
- branca 0.6.0
Additional context
In a similar test, PointString features were correctly displayed, with or without the style_function argument.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo la riproduzione GeoJSON dell'issue in Jupyter Notebook con e senza style_function, utilizzando i dati demo.json allegati. Traccia il percorso di styling di Folium GeoJson e verifica il completamento quando le feature LineString vengono renderizzate con il colore, lo spessore, l'opacità e il dashArray richiesti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- jupyter-notebook, python
- Ambito
- data-visualization
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100