【问题标题】:legend chropleth map leaflet didn't show the getColor value图例 choropleth 地图传单未显示获取颜色值
【发布时间】:2019-12-19 16:50:24
【问题描述】:

我一直在尝试在我的传单地图中添加一个图例。我正在使用本教程https://leafletjs.com/examples/choropleth/ 但是图例没有显示 getColor() 的正确值 这是我项目中显示的图例 this is my project screenshot

已经包含了 css 和 getColor 值。 这是图例代码

    var legend = L.control({
        position: 'bottomright'
    });

    legend.onAdd = function(map) {

        var div = L.DomUtil.create('div', 'info legend'),
            grades = [0, 2.3, 2.4, 2.8],
            labels = [];

        for (var i = 0; i < grades.length; i++) {
            from = grades[i];
            to = grades[i + 1];

            labels.push(
                '<i style="background:' + getColor(from + 1) + '"></i> ' +
                from + (to ? '&ndash;' + to : '+'));
        }

        div.innerHTML = labels.join('<br>');
        return div;
    };

    legend.addTo(map);

如何解决这个问题?

【问题讨论】:

    标签: javascript leaflet choropleth


    【解决方案1】:

    我认为,问题在于您的小值 [0, 2.3, 2.4, 2.8],而您正在调用函数 getColor(from + 1)。您可以尝试更改附加值 getColor(from + 0.01)

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 2015-08-19
      • 2022-06-29
      • 2017-12-20
      • 2020-09-01
      相关资源
      最近更新 更多