Convert or add hand drawn geometries to FeatureCollection as they are drawn on GEE
https://code.earthengine.google.com/7449579c661484958b44c292ff25908d
This utilizes the new GEE ui.Map.DrawingTools to interact with in-app drawn geometries. If I understand the original question correctly, this should solve it cleanly without a new app. Try it out!
// Set up colors
var colors = {'cyan': '#24C1E0', 'transparent': '#11ffee00', 'gray': '#F8F9FA'};
// Create download button panel
var downloadPanel = ui.Panel({
layout: ui.Panel.Layout.flow('vertical', true),
style: {width: '200px',
backgroundColor: colors.gray,
position: 'top-right',
shown: true
},
});
// Add it to map
Map.add(downloadPanel)
// Set up styles
var TITLE_STYLE = {
fontWeight: '100',
fontSize: '20px',
padding: '6px',
color: '#616161',
stretch: 'horizontal',
//style: {position: 'top-left'},
backgroundColor: colors.transparent,
};
// Add title to panel
var downloadTitle = ui.Label('Download Links', TITLE_STYLE);
downloadPanel.add(downloadTitle);
// Create download link once KML export is populated, set to shown:false
var urlGeom = ui.Label('Digitized Geometries', {shown: false});
downloadPanel.add(urlGeom);
// Download function
var exportData = function() {
print("Exporting data...");
//Set up download arguments
var downloadArgsGeom = {
format: 'kml'
};
// Run all imports that have been added to the script via user-digitization
//print(Map.drawingTools().layers())
// Handle user digitzed geometries
//var features = []; // reset features to empty array
if (Map.drawingTools().layers().length() > 0) {
var features = Map.drawingTools().toFeatureCollection()
var exportGeom = ee.FeatureCollection(features);
urlGeom.setUrl(exportGeom.getDownloadURL(downloadArgsGeom));
urlGeom.style().set({shown: true});
}
}
// Add download button to panel
var exportDataButton = ui.Button('Download');
exportDataButton.onClick(exportData);
downloadPanel.add(exportDataButton);