我有一张传单图,我想为每个“功能”分配颜色。 要素的数量可以根据更改的geojson数据而有所不同。 我猜有某种算法可以做到这一点。
这是代码:(在每个功能上,我想将颜色设置为与给定颜色不同的颜色,因为数据没有颜色)
var geomap = L.geoJson(geojson, {
//TODO: change the colors to be randomly separated and updated based on the # of features
//TODO: Should change the feature properties to be the population and zone number -- show this in the pop-up instead of the "description"
style: function (feature) {
return {color: feature.properties.color};
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.zone);
}
});
因此,如果我有5或100个功能,则我希望每个功能都有不同的颜色。 有任何提示或算法吗? 这显然是在JavaScript中。