In your link you have a section labeled PROCESSING STARTS HERE
. You could try wrapping your processing steps in a ui.Button
object:
var submit = ui.Button({
label: 'Calculate NDVI',
onClick: function() {
var date_start = startDate.getValue();
var date_end= endDate.getValue();
// ...
// The rest of your processing code here
// Be sure to add your new layer at the end
// ...
mapPanel.addLayer(NDVI_annual_recl.select("slope").clip(AOI),BandCompViz);
}
});
You should also consider whether you want previously calculated images to remain as layers on the map if the user changes the dates and calculates a new NDVI image. Multiple layers on the map can be nice for comparison but can also become cluttered quickly. If you want to clear out the previous layers, add a line at the beginning of the onClick
function:
mapPanel.clear() // Or .remove() to specify a single layer
Finally, you'll need to add your new button to the UI panel. You can do this around lines 129-130, where you add the start and end date textboxes.
mainPanel.add(startDate);
mainPanel.add(endDate);
mainPanel.add(submit);