python-visualization / python-visualization/folium

Features not displayed with style_function

Abierto
#1,782 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
7.4k
Forks
2.3k
Merge medio
17 h 22 min
PR fusionados (30 d)
11

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza ejecutando la reproducción GeoJSON del issue en Jupyter Notebook con y sin style_function, utilizando los datos demo.json adjuntos. Sigue la ruta de estilos de Folium GeoJson y verifica que se complete cuando las features LineString se rendericen con el color, grosor, opacidad y dashArray solicitados.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
jupyter-notebook, python
Área
data-visualization
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.