In order to publish my code as a Google Earth Engine App, I need to interactively set the Area of Interest (AOI) of the analysis based on the users's drawing (Rectangle in this case). I'm trying to use the .onDraw()
method as described in the ui.Map.DrawingTools
and ui.Map.GeometryLayer
documentation examples but I cannot seem to make it work. I'm trying the following:
// Don't make imports that correspond to the drawn rectangles.
Map.drawingTools().setLinked(false);
// Limit the draw modes to rectangles.
Map.drawingTools().setDrawModes(['rectangle']);
// Add an empty layer to hold the drawn rectangle.
Map.drawingTools().addLayer([]);
// Set the geometry type to be rectangle.
Map.drawingTools().setShape('rectangle');
// Enter drawing mode.
var getAOI = Map.drawingTools().draw();
var getAOI = function(){
Map.drawingTools().layers().get(0).toGeometry();
};
var AOI = Map.drawingTools().onDraw(getAOI);
Here is a link to the full script: https://code.earthengine.google.com/11a77302259a6d99c3a561a2a723fca0