timwis/leaflet-choropleth

Invert legend

Stophface opened this issue · 2 comments

Is there a way to invert the legend?

[...]

// Add min & max
div.innerHTML = '<div class="labels"><div class="min">' + limits[0] + '</div> \
        <div class="max">' + limits[limits.length - 1] + '</div></div>'

limits.forEach(function (limit, index) {
  labels.push('<li style="background-color: ' + colors[3 - index] + '"></li>')
})

[...]

@Stophface you can also use javascript's Array.prototype.reverse() function. For example, you could just add labels.reverse() on this line to reverse the array before they're put into the <ul>. Another alternative would be to use .unshift instead of .push to prepend the <li>s instead of appending them.