2
我有一個傳單地圖,我想爲每個「功能」分配顏色。根據地理數據的變化,要素的數量可能會有所不同。我猜測有一些算法可以做到這一點。動態顏色選擇
下面是代碼:(各功能我想設置的顏色是不同的不是給定的顏色,因爲數據不具有彩色)
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。
如果您知道功能的數量,可以使用以下方法:http://blog.adamcole.ca/2011/11/simple-javascript-rainbow-color.html – dekkard