vasturiano / globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/globe.gl/example/world-population/
MIT License
1.97k stars 293 forks source link

Await for globe.labelDotRadius function #187

Closed ElviraKukhtaruk closed 6 months ago

ElviraKukhtaruk commented 6 months ago

When i use globe.labelDotRadius function to change label dot radius:

globe.labelDotRadius(d => { 
    console.log('Before');
    return ...;
});

console.log('After');
...

I get the following output (Browser console):

> After 
> (5) Before 

I have some labelsData. I want to edit label dot radius (with globe.labelDotRadius), after that i need to preform some function after globe.labelDotRadius function is executed for all elements. Is it possible to achieve this behavior?

Thank you in advance.

vasturiano commented 6 months ago

@ElviraKukhtaruk the content of labelDotRadius will run asynchronously at the first available frame. So you just have to set your "after" code to be asynchronous too, using a setTimeout, for example.

In your example:

globe.labelDotRadius(d => { 
    console.log('Before');
    return ...;
});

setTimeout(() => console.log('After'));
ElviraKukhtaruk commented 6 months ago

Thanks, that helps a lot.