/**** Start of imports. If edited, may not auto-convert in the playground. ****/
var globcoverv23 = ee.Image("projects/sat-io/open-datasets/ESA/GLOBCOVER_L4_200901_200912_V23"),
    globcoverv22 = ee.Image("projects/sat-io/open-datasets/ESA/GLOBCOVER_200412_200606_V22_Global_CLA");
/***** End of imports. If edited, may not auto-convert in the playground. *****/
var dict = {
  "names": [
    "Post-flooding or irrigated croplands (or aquatic)",
    "Rainfed croplands",
    "Mosaic cropland (50-70%) / vegetation (grassland/shrubland/forest) (20-50%)",
    "Mosaic vegetation (grassland/shrubland/forest) (50-70%) / cropland (20-50%)",
    "Closed to open (>15%) broadleaved evergreen or semi-deciduous forest (>5m)",
    "Closed (>40%) broadleaved deciduous forest (>5m)",
    "Open (15-40%) broadleaved deciduous forest/woodland (>5m)",
    "Closed (>40%) needleleaved evergreen forest (>5m)",
    "Open (15-40%) needleleaved deciduous or evergreen forest (>5m)",
    "Closed to open (>15%) mixed broadleaved and needleleaved forest (>5m)",
    "Mosaic forest or shrubland (50-70%) / grassland (20-50%)",
    "Mosaic grassland (50-70%) / forest or shrubland (20-50%)",
    "Closed to open (>15%) (broadleaved or needleleaved, evergreen or deciduous) shrubland (<5m)",
    "Closed to open (>15%) herbaceous vegetation (grassland, savannas or lichens/mosses)",
    "Sparse (<15%) vegetation",
    "Closed to open (>15%) broadleaved forest regularly flooded (semi-permanently or temporarily) - Fresh or brackish water",
    "Closed (>40%) broadleaved forest or shrubland permanently flooded - Saline or brackish water",
    "Closed to open (>15%) grassland or woody vegetation on regularly flooded or waterlogged soil - Fresh, brackish or saline water",
    "Artificial surfaces and associated areas (Urban areas >50%)",
    "Bare areas",
    "Water bodies",
    "Permanent snow and ice",
    "No data (burnt areas, clouds,…)"
  ],
  "colors": [
  "#aaf0f0",
    "#ffff64",
    "#dcf064",
    "#cdcd66",
    "#006400",
    "#00a000",
    "#aac800",
    "#003c00",
    "#286400",
    "#788200",
    "#8ca000",
    "#be9600",
    "#966400",
    "#ffb432",
    "#ffebaf",
    "#00785a",
    "#009678",
    "#00dc82",
    "#c31400",
    "#fff5d7",
    "#0046c8",
    "#ffffff",
    "#000000"
  ]};

var legend = ui.Panel({
  style: {
    position: 'middle-right',
    padding: '8px 15px'
  }
});

// Create and add the legend title.
var legendTitle = ui.Label({
  value: 'GlobCover 2009',
  style: {
    fontWeight: 'bold',
    fontSize: '18px',
    margin: '0 0 4px 0',
    padding: '0'
  }
});
legend.add(legendTitle);

var loading = ui.Label('Loading legend...', {margin: '2px 0 4px 0'});
legend.add(loading);

  // Creates and styles 1 row of the legend.
  var makeRow = function(color, name) {
    // Create the label that is actually the colored box.
    var colorBox = ui.Label({
      style: {
        backgroundColor: color,
        // Use padding to give the box height and width.
        padding: '8px',
        margin: '0 0 4px 0'
      }
    });

  // Create the label filled with the description text.
  var description = ui.Label({
    value: name,
    style: {margin: '0 0 4px 6px'}
  });

  return ui.Panel({
    widgets: [colorBox, description],
    layout: ui.Panel.Layout.Flow('horizontal')
  });
};
  var palette = dict['colors'];
  var names = dict['names'];
  loading.style().set('shown', false);

  for (var i = 0; i < names.length; i++) {
    legend.add(makeRow(palette[i], names[i]));
  }

// Print the panel containing the legend
print(legend);

var remapped_image = globcoverv22.remap([11,14,20,30,40,50,60,70,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])

var visualization = {min:1,max:23,palette:["#aaf0f0","#ffff64","#dcf064","#cdcd66","#006400","#00a000","#aac800","#003c00","#286400","#788200","#8ca000","#be9600","#966400","#ffb432","#ffebaf","#00785a","#009678","#00dc82","#c31400","#fff5d7","#0046c8","#ffffff","#000000"]}
Map.addLayer(remapped_image,visualization,'GLOBCOVER 2004-2006',false)

var remapped_image = globcoverv23.remap([11,14,20,30,40,50,60,70,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])

var visualization = {min:1,max:23,palette:["#aaf0f0","#ffff64","#dcf064","#cdcd66","#006400","#00a000","#aac800","#003c00","#286400","#788200","#8ca000","#be9600","#966400","#ffb432","#ffebaf","#00785a","#009678","#00dc82","#c31400","#fff5d7","#0046c8","#ffffff","#000000"]}
Map.addLayer(remapped_image,visualization,'GLOBCOVER 2009')