Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing data (refreshing) WebGL Globe

I'm playing with the WebGL Globe (http://globe.chromeexperiments.com/) and would like to be able to "refresh" it with new data and then animate it to the new state. The examples provided in the library don't help because they load data series at once when the page loads, but I'd like to load in new data dynamically (say, every 30 seconds)

Repeatedly executing the following with new data only updates the globe's data additively, so the bars "stack up" on the globe when new data comes in:

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

There doesn't seem to be an obvious way to subtract / clear / reset the globe's data using the built in API (and then animate to a new state of data). Is this easily doable?

like image 908
CraexIt Avatar asked Dec 05 '25 13:12

CraexIt


2 Answers

I figured it out. In your globe.js add the following lines:

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;

Now you can simply do something like:

TWEEN.start();
globe.removeAllPoints();
globe.addData(data, {format: 'magnitude', name: 'results', animated: false});
globe.createPoints();
like image 191
hobbes3 Avatar answered Dec 12 '25 12:12

hobbes3


The answer given by hobbes3 really helped. But just one small change.

You need not call globe.animate().

I had used it in a project in which i update data every 5 seconds and calling globe.animate() over and over again brought rendering to a crawl. Comment that out and you are gold.

like image 40
Anand Varma Avatar answered Dec 12 '25 11:12

Anand Varma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!