python-visualization / python-visualization/folium

Features not displayed with style_function

未关闭
#1,782 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
7.4k
派生
2.3k
平均合并
17 小时 22 分钟
30 天内合并 PR
11

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,在 Jupyter Notebook 中使用附带的 demo.json 数据,分别运行带有和不带有 style_function 的 issue GeoJSON 复现。跟踪 Folium GeoJson 的样式处理路径,并在 LineString 要素以请求的颜色、线宽、不透明度和 dashArray 完成渲染时验证完成情况。

由索引模型根据 Issue 内容生成。

评估

技术栈
jupyter-notebook, python
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。