-
Notifications
You must be signed in to change notification settings - Fork 60
/
primitive.js
92 lines (82 loc) · 2.58 KB
/
primitive.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* @Author: hijiangtao ([email protected])
* @Date: 2019-03-09 14:51:42
* @Desc: Hexagon Primitive Layer
* @Last Modified time: 2019-03-09 14:51:42
*/
import {HexagonCellLayer, CompositeLayer} from 'deck.gl';
const DEFAULT_COLOR = [255, 0, 255, 255];
// const COLOR_MAP = [
// [35, 255, 222],
// [75, 255, 35],
// [164, 255, 35],
// [255,140,0],
// [255,56,0],
// [255,0,0],
// ];
const MOCK_DATA = [
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
{ COORDINATES: [-122.4, 37.7], COLOR: [255, 0, 0], SPACES: 100 },
]
class HexagonPrimitiveLayer extends CompositeLayer {
renderLayers() {
const {
radius = 20000,
angle = 0,
upperPercentile = 100,
coverage = 1,
extruded,
elevationScale = 100,
data = MOCK_DATA,
colorRange,
showAnimation,
...otherProps
} = this.props;
// calculate the maximum value for item.SPACES
data.sort((a, b) => {
return b.SPACES - a.SPACES;
});
let max = data[0].SPACES;
let filterDataset = data.slice(0, Math.max(Number.parseInt(data.length*coverage), data.length));
const layerProps = {
...otherProps,
id: `${this.id}-hp-child`,
data: filterDataset,
radius,
angle,
elevationScale,
getColor: x => x.COLOR
}
return [
new HexagonCellLayer(layerProps),
];
}
}
HexagonPrimitiveLayer.layerName = 'HexagonPrimitiveLayer';
HexagonPrimitiveLayer.defaultProps = {
...HexagonCellLayer.defaultProps,
getColor: {type: 'accessor', value: DEFAULT_COLOR},
getElevation: {type: 'accessor', value: x => x.SPACES},
getCentroid: {type: 'accessor', value: x => x.COORDINATES},
lightSettings: {
type: 'accessor',
value: {
lightsPosition: [-0.144528, 49.739968, 8000, -3.807751, 54.104682, 8000],
ambientRatio: 0.4,
diffuseRatio: 0.6,
specularRatio: 0.2,
lightsStrength: [0.8, 0.0, 0.8, 0.0],
numberOfLights: 2,
},
},
radius: {type: 'number', min: 0, value: 20000},
};
export default HexagonPrimitiveLayer;