javascript - Leaflet Legend not showing -


can tell wrong code? legend, supposed easiest part in not showing , cant figure out why. maybe hidden in other layer?

following getcolor , legend code

var legend = l.control({   position: 'bottomleft' });  legend.onadd = function(map) {   var div = l.domutil.create('div', 'info legend'),     grades = [0.2, 0.26, 0.32, 0.38, 0.44, 0.5, 0.56, 0.62, 0.68, 0.74, 0.8, 0.86, 0.92, 0.98, 1.04, 1.1],     labels = [],     from, to;    (var = 0; < grades.length; i++) {     = grades[i];     = grades[i + 1];      labels.push(       '<i style="background:' + getcolor(from + 1) + '"></i> ' +       + (to ? '&ndash;' + : '+'));   }    div.innerhtml = labels.join('<br>');   return div; }; 

edit following answer comments:

use developer tools (f12 / on mac: cmd + alt + i) read potential console errors.

in case, getcolor function not defined in scope of legend.onadd.

besides, add 1 from value, resulting in values ranging in [1.2 - 2.1] whereas getcolor function uses values 0.26 1.1.

working demo using code repo: http://plnkr.co/edit/lbklxav76t6nclhqpctr?p=preview (getcolor copied in correct scope, , removed +1 in getcolor(from + 1))


original answer:

did add custom control map?

legend.addto(map); 

as side note, <i> tag legend-ed background color getcolor not have content. therefore see no colored content…

demo: http://jsfiddle.net/3v7hd2vx/34/ (with dummy content in <i> tag)


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -