2
我正在使用mapbox羣集。我想根據另一個函數的某些邏輯更改羣集顏色。我試圖改變移動的顏色。我會像理想是這樣的....Mapbox - 動態更改羣集顏色
map.on('load', function(){
//data
map.addSource("surveydata", {
type: "geojson",
data: "/surveydata/"+lastweek+"/"+today+"",
cluster: true,
clusterRadius: 20
});
map.addLayer({
"id": "cluster",
"type": "circle",
"source": "surveydata",
"paint": {
'circle-color': 'rgba(0,0,200,0.2)',
'circle-radius': 20
},
"filter": [">=", "point_count", 2]
});
});
//recolor clusters
map.on('moveend', function (e) {
var colors = ['#ff0000', '#00ff00', '#0000ff'];
var cluster = map.queryRenderedFeatures({ layers: ["cluster"] });
//HERE
for(i = 0; i < cluster.length; i++){
console.log(cluster[i]); //THIS RETURNS ALL THE CLUSTERS SUCCESSFULLY
cluster[i].setcolor(randomcolor) //this I am not sure how to do
}
});
據我所知,有對圖層名稱的唯一ID將是理想的,但我不認爲我有這樣的奢侈。任何想法將不勝感激。