Here is a workaround for accessing the results from aggregate_stats()
using the Python API.
def summary_statistics(collection, column):
stats = collection.aggregate_stats(column).getInfo()
return eval(str(stats)).get('values')
results = summary_statistics(your_collection, column_name)
print(results.get('sum'))
print(results.get('mean'))
It would be possible to do it the way you're trying, using the same map as the left side and the un-split view, but it will be a bit simpler to avoid trying to give a widget two different parents (which will never work) if you create three separate ui.Map
s: one for the unsplit view and one for each side of the split. Since you can link all three this still works as you want except for some extra tile loading (unless you want to have the layer toggles in sync between the two versions).
// Create and link maps
var singleMap = ui.root.widgets().get(0);
var leftMap = ui.Map();
var rightMap = ui.Map();
var linker = ui.Map.Linker([singleMap, leftMap, rightMap]);
var splitPanel = ui.SplitPanel({
firstPanel: leftMap,
secondPanel: rightMap,
orientation: 'horizontal',
wipe: false,
});
var checkbox = ui.Checkbox('Show SRTM layer', false);
checkbox.onChange(function(checked) {
if (checked) {
ui.root.widgets().reset([splitPanel]);
} else {
ui.root.widgets().reset([singleMap]);
}
});
print(checkbox);
// Configure maps
singleMap.addLayer(ee.Image('CGIAR/SRTM90_V4'));
leftMap.addLayer(ee.Image('CGIAR/SRTM90_V4'));
var image = ee.Image('LANDSAT/LC08/C01/T1_RT_TOA/LC08_045033_20171011');
// Make another map and add a color-NIR composite to it.
rightMap.addLayer(image, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'color-NIR');
// Add a thermal image to the map.
rightMap.addLayer(image, {
bands: ['B11'],
min: 290,
max: 310,
palette: ['gray', 'white', 'yellow', 'red']
}, 'Thermal');
https://code.earthengine.google.com/99b4af724b717a8cfc9cd92bb81186ec
I tried making a version that uses the same map for the left and unsplit views. In order to do this, we have to replace the left panel in the SplitPanel
with a dummy panel to remove the map from it so the map can be used by itself.
Unfortunately, there seems to be a layout glitch when the map is restored to the root, so that it is no longer the width of the window but very narrow, so it isn't actually usable. I will pass on this information to the Earth Engine Code Editor developers and hopefully this script will start working.
var singleOrLeftMap = ui.root.widgets().get(0);
var rightMap = ui.Map();
var linker = ui.Map.Linker([singleOrLeftMap, rightMap]);
var splitPanel = ui.SplitPanel({
firstPanel: ui.Panel(),
secondPanel: rightMap,
orientation: 'horizontal',
wipe: false,
});
var checkbox = ui.Checkbox('Show SRTM layer', false);
checkbox.onChange(function(checked) {
if (checked) {
ui.root.widgets().reset([splitPanel]);
splitPanel.setFirstPanel(singleOrLeftMap);
} else {
// Replace the split's left panel so that the map,
// which used to be the left panel, can be reused elsewhere
splitPanel.setFirstPanel(ui.Panel());
ui.root.widgets().reset([singleOrLeftMap]);
}
});
print(checkbox);
https://code.earthengine.google.com/d32319aea94e893d68be67d5e5764aae
Best Answer
I believe this should solve your problem. See comments in the code below.