I have a leaflet map that consists of various wms layers representing different years.
I am trying to add a legend to my leaflet map but with my own custom hex colours instead of trying to use a layer in the map (as my legend is more broad) This is the sample code from leaflets website.
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, 10, 20, 50, 100, 200, 500, 1000],
labels = [];
// loop through our density intervals and generate a label with a colored square for each interval
for (var i = 0; i < grades.length; i++) {
div.innerHTML +=
'<i style="background:' + getColor(grades[i] + 1) + '"></i> ' +
grades[i] + (grades[i + 1] ? '–' + grades[i + 1] + '<br>' : '+');
}
return div;
};
legend.addTo(map);
Is there anyway to adapt this to my own 5 class hex(colors) legend?