Google Earth Engine – Passing Values Acquired from User Interface

google-earth-engine

This is a text box used to input the end time.

How do I use the input values outside of the ui.Textbox function?

var endDate = ''; 
var endTextbox = ui.Textbox({
          placeholder: "End time: yyyy-mm-dd",
          onChange: function(value) {
            print("End time: " + value);
            endDate = value;
          }
        });
print(endTextbox);
print(endDate);

Best Answer

Using UI widgets means your code has to be contained in functions that can be called in the onChange callbacks.

For instance: https://code.earthengine.google.com/d08b5514949d330aea0fe87389531e7f

function doWork() {
   var date = endTextbox.getValue()
   var collection = ee.ImageCollection("COPERNCIUS/S2_SR")
      .filterDate(date, date.advance(1, 'week')
   Map.addLayer(collection
}

var endTextbox = ui.Textbox({
    placeholder: "End time: yyyy-mm-dd",
    onChange: doWork
});
print(endTextbox)