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.
// Limit the draw modes to rectangles.
// Add an empty layer to hold the drawn rectangle.
// Set the geometry type to be rectangle.
// Enter drawing mode.
var getAOI = Map.drawingTools().draw();

var getAOI = function(){

var AOI = Map.drawingTools().onDraw(getAOI);

Here is a link to the full script: https://code.earthengine.google.com/11a77302259a6d99c3a561a2a723fca0


onDraw() takes a callback function, which according to docs:

The callback to fire when a shape is drawn. The callback is passed three parameters: the added ee.Geometry, the GeometryLayer to which the geometry was added, and the ui.Map.DrawingTools widget that the event listener is bound to.

This means, you get a reference to the geometry like this:

Map.drawingTools().onDraw(function (geometry) {
  // Do something with the geometry
  Map.addLayer(geometry, null, 'a drawn geometry')
  • Thank you @Daniel Wiell for clarifying that. – moez.labiadh May 6 '20 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.