-
Notifications
You must be signed in to change notification settings - Fork 60
/
index.js
58 lines (52 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* @Author: hijiangtao ([email protected])
* @Date: 2019-01-14 17:45:07
* @Description: Screengrid display layer.
* @Last Modified time: 2019-01-14 17:45:07
*/
import {ScreenGridLayer, CompositeLayer} from 'deck.gl';
class PreConfigScreenGridLayer extends CompositeLayer {
renderLayers() {
const {data, getPosition, colorRange, getWeight, cellSize = 5, gpuAggregation = true, coverage = 1, ...otherProps} = this.props;
/**
* Sort data by descending order with coverage (0~1) condition
*/
let splitData = data;
if (typeof data !== 'string') {
data.sort((a, b) => {
return b.SPACES - a.SPACES;
});
const coverageLen = data.length * coverage - 1 >= 0 ? parseInt(data.length * coverage - 1, 10) : 0;
splitData = data.slice(0, coverageLen);
}
return [
new ScreenGridLayer({
...otherProps,
id: `${this.id}-sg-child`,
data: splitData,
getPosition,
getWeight,
cellSizePixels: cellSize,
colorRange,
}),
];
}
}
PreConfigScreenGridLayer.layerName = 'PreConfigScreenGridLayer';
PreConfigScreenGridLayer.defaultProps = {
...ScreenGridLayer.defaultProps,
getPosition: {type: 'accessor', value: x => x.COORDINATES},
getWeight: {type: 'accessor', value: x => x.SPACES},
colorRange: {
type: 'accessor',
value: [
[255, 255, 178, 25],
[254, 217, 118, 85],
[254, 178, 76, 127],
[253, 141, 60, 170],
[240, 59, 32, 212],
[189, 0, 38, 255],
]
}
};
export default PreConfigScreenGridLayer;