正在删除数据(刷新)WebGL Globe

Removing data (refreshing) WebGL Globe

本文关键字:WebGL Globe 刷新 删除 数据      更新时间:2023-09-26

我正在玩WebGL Globe(http://globe.chromeexperiments.com/)并且希望能够用新数据"刷新"它,然后将其动画化为新状态。库中提供的示例没有帮助,因为当页面加载时,它们会立即加载数据系列,但我希望动态加载新数据(例如,每30秒)

使用新的data重复执行以下操作只会额外更新地球仪的数据,因此当新数据进入时,条形图会在地球仪上"堆叠"起来:

globe.addData(data, {format: 'magnitude'});
globe.createPoints();
globe.animate();

似乎没有一种明显的方法来使用内置的API减去/清除/重置地球数据(然后动画化为新的数据状态)。这很容易实现吗?

我想明白了。在globe.js中添加以下行:

function createPoints() {
    ...
    this.points.name = "lines"; // Add this line
    scene.add(this.points);
    }
}
// Create this function
function removeAllPoints() {
    scene.remove(scene.getObjectByName("lines"));
}
// Near the bottom of the code
this.addData = addData;
this.removeAllPoints = removeAllPoints; // Add this line
this.createPoints = createPoints;
this.renderer = renderer;
this.scene = scene;

现在你可以简单地做这样的事情:

TWEEN.start();
globe.removeAllPoints();
globe.addData(data, {format: 'magnitude', name: 'results', animated: false});
globe.createPoints();

霍布斯3给出的答案真的很有帮助。但只有一个小小的改变。

您无需致电globe.animate()

我曾在一个项目中使用过它,在该项目中,我每5秒更新一次数据,并一次又一次地调用globe.animate()使渲染变得缓慢。评论出来,你就是金子。