timwis / leaflet-choropleth

Choropleth plugin for Leaflet (color scale based on value)
http://timwis.com/leaflet-choropleth/examples/basic
MIT License
182 stars 233 forks source link

Invert legend #14

Closed Stophface closed 8 years ago

Stophface commented 8 years ago

Is there a way to invert the legend?

Stophface commented 8 years ago

[...]

// 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>')
})

[...]

timwis commented 8 years ago

@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.