Situation: My colleague and I have made our first script in Google Earth Engine Code Editor that will be published as an Earth Engine App. The script shows 33 basin-polygons that the user can click on, and a chart will appear for the chosen basin. The data in the chart is coming from a csv file and the basins are imported as shapefile.
Problem:
We have troubles with the script running slow when clicked on a basin-polygon, we suspect that it is because .getInfo()
is being used in 6 different places in the script.
Solutions we have tried:
We tried .evaluate()
, which we had difficulties with in our script, since we are not used to GEE coding.
Question:
- How can we avoid using
.getInfo()
?
The whole script is shown here in this link: Link to whole script
Pieces of codes that contains .getInfo()
:
// First place where .getInfo() appears
// Register a click handler for the map that adds the clicked polygon to the updated map overlay
function handleMapClick(location) {
selectedPoints = []; //list of points that the selected polygon contains
selectedPoints.push([location.lon, location.lat]); // adds clicked polygon to selection
var myBasin = getSelectedBasin;
// if statement for showing a chart when clicking on a polygon and not showing a chart when clicked somewhere else
var basinSize=false;
basinSize=(myBasin().size().getInfo() >0);
if (basinSize){
var p=theyCLickedOnABasin(myBasin);
} else {
var ps=theyClickedAwayFromABasin();
}
}
// Second place where .getInfo() appears
// Finding a common maximum value
var max_val = max_val_3.max(max_val_4.max(min_val_3.max(min_val_4)));
// Defining the y-axis limits
var ylim = max_val.divide(ee.Number(20)).ceil().multiply(ee.Number(20)).getInfo();
// Defining the 4 data that will be shown on y-axis on chart
var myY=[SSI_W3RA_data.getInfo(),SSI_MCMC_data.getInfo(),GW_W3RA_data.getInfo(),GW_MCMC_data.getInfo()];