Leaflet - Adding a Legend Name

I am new to Leaflet, and now I am struggling with textbooks. So far I have managed to create an interactive clorophet map, as in the example http://leafletjs.com/examples/choropleth.html .

I have a question: is it possible to add a heading (plain text, not dynamic) to the foot located in the lower right corner of the page? Can someone tell me how by simply referring to a related example?

Thanks a lot G.

+6
source share
2 answers

You just need to add your title in the "TITLE" section ...

var legend = L.control({position: 'topleft'}); legend.onAdd = function (map) { var div = L.DomUtil.create('div', 'info legend'), grades = [50, 100, 150, 200, 250, 300], labels = ['<strong> THE TITLE </strong>'], from, to; for (var i = 0; i < grades.length; i++) { from = grades [i]; to = grades[i+1]-1; labels.push( '<i style="background:' + getColor(from + 1) + '"></i> ' + from + (to ? '&ndash;' + to : '+')); } div.innerHTML = labels.join('<br>'); return div; }; 
+6
source

Francisco Vargas: getColor is a function that determines the density:

 function getColor(d) { return d > 1000 ? '#800026' : d > 500 ? '#BD0026' : d > 200 ? '#E31A1C' : d > 100 ? '#FC4E2A' : d > 50 ? '#FD8D3C' : d > 20 ? '#FEB24C' : d > 10 ? '#FED976' : '#FFEDA0'; } 
+1
source

All Articles