这实际上是我的第一个 JS 代码,所以请多多包涵,我设法改编了 Deck.Gl 中的示例示例以显示散点图,现在我不确定如何根据“状态”列的值更改颜色,我知道如何为 1 个值执行此操作,但不确定如何在此处使用 if then else 执行其余操作
getFillColor: d => (d[2] === '1-pile' ? [0, 128, 255] : [255, 100, 128])
这是一个完整的可重复示例
<html>
<head>
<title>deck.gl solar Farm Example</title>
<script src="https://unpkg.com/deck.gl@^7.0.0/dist.min.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js"></script>
</head>
<body>
<div id="container"></div>
</body>
<script type="text/javascript">
const {DeckGL, ScatterplotLayer} = deck;
new DeckGL({
mapboxApiAccessToken: 'xxxxx',
mapStyle: 'mapbox://styles/mapbox/satellite-streets-v9',
longitude: 5.2,
latitude: 35.49,
zoom: 15,
minZoom: 5,
maxZoom: 20,
pitch: 40.5,
layers:[
new ScatterplotLayer({
id: 'scatter-plot',
data: 'https://raw.githubusercontent.com/djouallah/interactivie_map/master/data.json',
radiusScale: 3,
radiusMinPixels: 0.25,
getPosition: d => [d[0], d[1], 0],
getFillColor: d => (d[3] === '1-pile' ? [0, 128, 255] : [255, 100, 128])
})
]
});
</script>
</html>