微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在deck.gl 中使用python 动画TripsLayer

如何解决在deck.gl 中使用python 动画TripsLayer

我在deck.gl 网站(this one)中看到了TripsLayer 示例,它看起来非常酷。我想完成同样的事情,但使用 pydeck,deck.gl 的 python 绑定。 pydeck 网页 (this one) 中的示例没有动画,我不确定我应该如何做才能获得如 javascript 示例中所示的流畅动画。我尝试了多种方法(传递列表、函数、具有变化值的变量等),但它们都没有奏效,而且我找不到任何关于 pydeck 的示例。

谢谢!

解决方法

这个例子确实应该包含更多的行程。下面是如何在jupyter notebook中实现多次旅行的动画。

import time
import pandas as pd
import pydeck as pdk

data = '[{"agent_id":0,"path":[[-0.63968,50.83091,0.0],[-0.78175,50.83205,0.0]],"time":[65100,65520],"color":[228,87,86]},{"agent_id":1,"time":[65940,66420],"color":[178,121,162]},{"agent_id":2,[-0.37617,50.8185,"time":[65340,66360],"color":[157,117,93]},{"agent_id":3,"color":[238,202,59]},{"agent_id":4,"time":[67740,68160],93]}]'

df = pd.read_json(data)
view = {"bearing": 0,"latitude": 50.85,"longitude": -0.16,"pitch": 0,"zoom": 9}

time_min = 65_000
time_max = 80_000

layer = pdk.Layer(
    "TripsLayer",df,get_path='path',get_timestamps='time',get_color='color',opacity=0.8,width_min_pixels=3,rounded=True,trail_length=900,current_time=0
)

# Render
r = pdk.Deck(layers=[layer],initial_view_state=view,map_style='dark_no_labels')

r.show()

# Animate
for ct in range(time_min,time_max,100):
    layer.current_time = ct
    r.update()
    time.sleep(0.1)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。