/**** Start of imports. If edited, may not auto-convert in the playground. ****/
var soil_salinity = ee.ImageCollection("projects/sat-io/open-datasets/global_soil_salinity");
/***** End of imports. If edited, may not auto-convert in the playground. *****/
var dataset = ee.ImageCollection('MODIS/006/MOD44W')
                  .filter(ee.Filter.date('2015-01-01', '2015-05-01'));
var waterMask = dataset.select('water_mask');

// set position of panel
var legend = ui.Panel({
  style: {
    position: 'bottom-left',
    padding: '8px 15px'
  }
});
 
// Create legend title
var legendTitle = ui.Label({
  value: 'Legend',
  style: {
    fontWeight: 'bold',
    fontSize: '18px',
    margin: '0 0 4px 0',
    padding: '0'
    }
});
 
// Add the title to the panel
legend.add(legendTitle);
 
// 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 the panel
      return ui.Panel({
        widgets: [colorBox, description],
        layout: ui.Panel.Layout.Flow('horizontal')
      });
};
 
//  Palette with the colors
var palette =['00FF00', 'FFFF00','FFA500','FF0000', '8B0000'];
 
// name of the legend
var names = ['Non saline','Slightly saline','Moderately saline','Highly saline','Extremely saline'];
 
// Add color and and names
for (var i = 0; i < 5; i++) {
  legend.add(makeRow(palette[i], names[i]));
  }  
 
// add legend to map (alternatively you can also print the legend to the console)
Map.add(legend);
Map.addLayer(soil_salinity.median().updateMask(waterMask.mosaic().eq(0)),{'min':0,'max':5,'palette':palette},'Soil salinity')
