folium时间轴不能移除先前添加到地图中的标记

5
我正在尝试使用时间滑块绘制标记。 我已创建了时间戳的GeoJSON,如下所示:
def create_geojson_features(df):

    features = []
    for lat,lan,intensity,time in zip(df['latitude'],df['longitude'],df['intensity'],df['timestamp']): 
        time = str(time)
        feature = {
            'type': 'Feature',
            'geometry': {
                'type':'Point', 
                'coordinates':[lan,lat]
            },
            'properties': {
                'time': time,
                'style': {'Color' : color(intensity)},
                'icon': 'Marker',
                'color':color(intensity),
                'iconstyle':{
                    'Color': color(intensity),
                    'fillOpacity': 0.8,
                    'stroke': 'true',
                    'radius': 7
                }
            }
        }
        features.append(feature)
    return features
features = create_geojson_features(df)

这是我用来绘制标记的代码

from folium.plugins import TimestampedGeoJson
m = folium.Map([latmean,lonmean], zoom_start=11)

TimestampedGeoJson(
        {'type': 'FeatureCollection',
        'features': features}
        , period='PT1H'
        , add_last_point=False
        , auto_play=False
        , loop=False
        , max_speed=1
        , loop_button=True
        , date_options='YYYY/MM/DD HH:mm:ss'
        , time_slider_drag_update=True
    ).add_to(m)

我将期间指定为PT1H,当我滑动滑块时,新的点会不断添加。如何去除旧点并仅显示新点?请帮助。

这里也有同样的问题,希望能找到解决方案。 - Wboy
我找到了一个解决方法,修改timestamped_geojson.py的参数。 - gokyori
@gokyori,你能分享一下在timestamped_geojson.py的参数中做了哪些更改才能够在时间戳之间清除绘图吗?谢谢。 - infinity911
1个回答

1

有一个专门的参数用于此操作:duration = 'P1D'

使用您的示例,仅按时间戳显示:

TimestampedGeoJson(
        {'type': 'FeatureCollection',
        'features': features}
        , period='PT1H'
        , duration='PT1H'
        , add_last_point=False
        , auto_play=False
        , loop=False
        , max_speed=1
        , loop_button=True
        , date_options='YYYY/MM/DD HH:mm:ss'
        , time_slider_drag_update=True
    ).add_to(m)

还有一件事要补充:在使用持续时间时,我遇到了一些情况,前一天仍然会出现。例如,如果您的周期设置为“P1D”,持续时间设置为“P1D”,则仍将显示来自前一天的某些数据。为避免这种情况,请使用: 周期=“P1D”, 持续时间=“P0D”。 - Jerry Heo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接