2015-05-16 36 views
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。

+0

如果您知道功能的数量,可以使用以下方法:http://blog.adamcole.ca/2011/11/simple-javascript-rainbow-color.html – dekkard

回答