python - 叶时间滑块不会删除地图中先前添加的标记
问题描述
我正在尝试使用时间滑块绘制标记。我创建了带时间戳的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,当我滚动滑块时,新点会不断添加。如何删除旧点并仅显示新点?请帮忙。
解决方案
有一个参数就是: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)
推荐阅读
- python - Python多处理-starmap_async在starmap的地方不起作用?
- html - 如何让这些括号框对齐属性?
- groovy - groovy 对版本号列表进行排序
- reactjs - 是否有一些 redux 没有在 react 上提供的功能?
- python - 正则表达式获取文本左对齐
- css - 我们如何为自适应卡编辑 CSS?Azure Bot Framework V4、nodejs、botbuilder-feedback
- java - 不了解 RxJava MaybeObserver(聊天通知不起作用)
- python - 我想将字典键从字符串更改为整数
- java - JVM如何在垃圾回收过程中发现无法访问的对象引用?
- apache - ApolloLink 到无头 CMS/跨域域(Wordpress WPGraphQL 端点)不工作:Apache 500 错误