I have this callback inside the .evaluate function on google earth engine:
numberServer.evaluate(function(numberClient) {
console.log('Client-side primitive data type', typeof numberClient); // number
console.log('Client-side number', numberClient); // 10.3
console.log('Client-side number used in expression', numberClient + 10); // 20.3
})
The above will correctly output the value of numberServer to the client.
The problem is that I need to capture the value of numberClient in a variable. How can I do that?
I tried using a promise with no success.
function Test(){ return new Promise(function(resolve) {
numberServer.evaluate(function(numberClient) {
console.log('Client-side primitive data type', typeof numberClient); // number
console.log('Client-side number', numberClient); // 10.3
console.log('Client-side number used in expression', numberClient + 10); // 20.3
resolve(numberClient);
})
});
};
var test2;
async function test3() {
return test2 = await Test();
}
var test4;
(async function(){
test4 = await test3();
})();
var test5 = test4;
test5 is always undefined and that's the variable I want to have.
I also tried returning the callback:
function Test() { return numberServer.evaluate(function(numberClient) {
console.log('Client-side primitive data type', typeof numberClient); // number
console.log('Client-side number', numberClient); // 10.3
console.log('Client-side number used in expression', numberClient + 10); // 20.3
return numberClient;
})
};
var out = Test();