/**** Start of imports. If edited, may not auto-convert in the playground. ****/
var ca_forest_fire_mag = ee.Image("projects/sat-io/open-datasets/CA_FOREST/CA_Forest_Wildfire_dNBR_1985_2020");
/***** End of imports. If edited, may not auto-convert in the playground. *****/

// Define a dictionary which will be used to make legend and visualize image on map
var dict = {
  "names": [ 
    "1", "2","3","4","5","6","7","8","9","10","11","12","13","14","15","16",
    "17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32",
    "33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48",
    "49","50","51","52","53","54","55","56","57","58","59","60","61","62","63","64",
    "65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80",
    "81","82","83","84","85","86","87","88","89","90","91","92","93","94","95","96",
    "97","98","99","100","101","102","103","104","105","106","107","108","109","110 - 199",

  ],
    "colors": [
    "#0c1cad", "#171fb0", "#1f1db2", "#271db5", "#2f1db8", "#341cba",
    "#391cba", "#421cbd", "#481dbf", "#4a1bc2", "#511bc4", "#561ac7", "#5d1ac9", "#641bcc",
    "#6819cf", "#6f19d1", "#7217d4", "#7a18d6", "#7c15d6", "#8416d9", "#8814db", "#8d14de",
    "#9512e0", "#9910e3", "#9e0ee6", "#a60ce8", "#ab09eb", "#b007ed", "#b407ed", "#bf07ed",
    "#c707ed", "#ce07ed", "#d807f0", "#e007f0", "#ec07f0", "#f007ec", "#f007e4", "#f207df",
    "#f207d3", "#f207cb", "#f207c3", "#f505bd", "#f505b5", "#f505a9", "#f505a1", "#f50599",
    "#f70592", "#f70586", "#f7057e", "#f70576", "#fa056f", "#fa0567", "#fa055b", "#fa0553",
    "#fa054a", "#ff1500", "#ff2200", "#ff3300", "#ff3c00", "#ff4400", "#ff5100", "#ff5900",
    "#ff6200", "#ff6a00", "#ff7300", "#ff7b00", "#ff8400", "#ff8c00", "#ff9000", "#ff9900",
    "#ffa200", "#ffaa00", "#ffb200", "#ffbb00", "#ffc300", "#ffcc00", "#ffd400", "#ffd900",
    "#ffe100", "#ffea00", "#fff200", "#fffb00", "#ffff0a", "#ffff14", "#ffff21", "#ffff29",
    "#ffff2e", "#fffc36", "#fffc3d", "#fcf942", "#fcf947", "#fcfa4c", "#fcfa51", "#fcfa56",
    "#fcfa5d", "#fcfa60", "#faf764", "#faf56b", "#faf56e", "#faf575", "#faf67a", "#f7f37c",
    "#f7f383", "#f7f488", "#f7f48d", "#f5f190", "#f5f395", "#f5f39a", "#f2f19d", "#f2f1a2",

  ]};

Map.setCenter(-97.61655457157725,55.6280720462063,4)


// Add image to the map
Map.addLayer(ca_forest_fire_mag, {min:1, max:110, palette:dict['colors']}, 'Wildfire Change Magnitude dNBR')

/////////////////////////////////////////////////////////////////////////

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

// Create and add the legend title.
var legendTitle = ui.Label({
  value: 'Wildfire Change Magnitude dNBR',
  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);
