【问题标题】:Issue with Pop up in Folium TimestampedGeoJson mapFolium TimestampedGeoJson 地图中的弹出问题
【发布时间】:2020-03-18 12:38:49
【问题描述】:

我正在尝试使用 Folium TimestampedGeoJson 将我的 pandas 数据框中的数据可视化到地图上。我的数据框包含纬度、经度、日期时间和其他一些信息。我能够使地图正常工作并可视化纬度、经度以及颜色编码(基于分类变量)和圆的半径(基于数值变量)在时间段内。但是我无法获得弹出窗口。

我将 pandas 数据帧转换为 Geojson 的代码是:

def create_geojson_features(df):
    print('> Creating GeoJSON features...')
    features = []
    for _, row in df.iterrows():
        feature = {
            'type': 'Feature',
            'geometry': {
                'type':'Point', 
                'coordinates':[row['long'],row['lats']]

            },
            'properties': {
                'time': row['Instruction Date Time'].date().__str__(),
                'popup':row['pop_up_info'],
                'style': {'color' : row['color']},
                'icon': 'circle',
                'iconstyle':{
                    #'Color': row['color'],
                    'fillOpacity': 0.2,
                    'fillcolor':'crimson',
                    'stroke': 'true',
                    'weight':4,
                    'radius': row['Numerical_data']*40
                }
            }
        }
        features.append(feature)

    return features

我使用 Folium TimestampedGeojson 绘制 Geojson 数据的代码是:

m_events = folium.Map(
    location=[52.45,-1.90],control_scale=True,
    zoom_start=7,
)

plugins.TimestampedGeoJson(
    {
        'type': 'FeatureCollection',
        'features': features
    },
    period='P1M',
    add_last_point=False,
    auto_play=False,
    loop=False,
    max_speed=1,
    loop_button=True,
    date_options='YYYY/MM/DD',
    time_slider_drag_update=True,
    duration='P2M'
).add_to(m_events)


m_events.save('m_events.html')
m_events

一切正常,包括时间滑块。唯一的问题是弹出窗口不起作用。

【问题讨论】:

  • 你能显示弹出窗口吗?

标签: python popup geojson folium


【解决方案1】:

尝试以 Geojson 格式使用它:'popup': str(row['pop_up_info']) 在此之后它应该可以正常工作

【讨论】:

    猜你喜欢
    • 2020-09-16
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 2019-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    相关资源
    最近更新 更多