I have a Google Earth Engine app that displays multiple image layers from an image collection. The user uses checkboxes to pick what layers to display. I want to add a feature that adds a ee.Geometry.Point layer to the map wherever the user clicks and I want it so that everytime the user clicks somewhere new, it replaces the last point (so there is only 1 point on the map at a time).
I tried making it so that when adding the point, it uses the size() of the image collection as the Map.layers() index to add, but it returns this weird error saying: "ee.Number({.....})" is not a valid list index.
Map.onClick(function(coordinate) {
var point = ee.Geometry.Point(coordinate.lon, coordinate.lat);
// imgCol is the image collection containing all the user's selected images
Map.layers().set(imgCol.size(), ui.Map.Layer(point, {color: 'FF0000'}, "Point"));
});
Keep in mind in the real app, the user chooses the number of layers so I can't just set the index to a constant number.