@deck.gl/aggregation-layers 8.8.0-alpha.6 → 8.8.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/dist.dev.js +515 -407
  2. package/dist/es5/aggregation-layer.js +19 -7
  3. package/dist/es5/aggregation-layer.js.map +1 -1
  4. package/dist/es5/contour-layer/contour-layer.js +5 -5
  5. package/dist/es5/contour-layer/contour-layer.js.map +1 -1
  6. package/dist/es5/contour-layer/contour-utils.js +1 -1
  7. package/dist/es5/contour-layer/contour-utils.js.map +1 -1
  8. package/dist/es5/contour-layer/marching-squares-codes.js.map +1 -1
  9. package/dist/es5/contour-layer/marching-squares.js.map +1 -1
  10. package/dist/es5/cpu-grid-layer/cpu-grid-layer.js +5 -3
  11. package/dist/es5/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  12. package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
  13. package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer.js +8 -12
  14. package/dist/es5/gpu-grid-layer/gpu-grid-cell-layer.js.map +1 -1
  15. package/dist/es5/gpu-grid-layer/gpu-grid-layer.js +12 -12
  16. package/dist/es5/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  17. package/dist/es5/grid-aggregation-layer.js +25 -12
  18. package/dist/es5/grid-aggregation-layer.js.map +1 -1
  19. package/dist/es5/grid-layer/grid-layer.js +18 -9
  20. package/dist/es5/grid-layer/grid-layer.js.map +1 -1
  21. package/dist/es5/heatmap-layer/heatmap-layer-utils.js.map +1 -1
  22. package/dist/es5/heatmap-layer/heatmap-layer.js +17 -6
  23. package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
  24. package/dist/es5/heatmap-layer/max-vs.glsl.js +1 -1
  25. package/dist/es5/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
  26. package/dist/es5/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
  27. package/dist/es5/heatmap-layer/triangle-layer.js +7 -7
  28. package/dist/es5/heatmap-layer/triangle-layer.js.map +1 -1
  29. package/dist/es5/heatmap-layer/weights-fs.glsl.js +1 -1
  30. package/dist/es5/heatmap-layer/weights-vs.glsl.js +1 -1
  31. package/dist/es5/hexagon-layer/hexagon-layer.js +16 -5
  32. package/dist/es5/hexagon-layer/hexagon-layer.js.map +1 -1
  33. package/dist/es5/index.js.map +1 -1
  34. package/dist/es5/screen-grid-layer/screen-grid-cell-layer.js +26 -19
  35. package/dist/es5/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  36. package/dist/es5/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
  37. package/dist/es5/screen-grid-layer/screen-grid-layer.js +18 -8
  38. package/dist/es5/screen-grid-layer/screen-grid-layer.js.map +1 -1
  39. package/dist/es5/types.js +2 -0
  40. package/dist/es5/types.js.map +1 -0
  41. package/dist/es5/utils/bin-sorter.js +9 -0
  42. package/dist/es5/utils/bin-sorter.js.map +1 -1
  43. package/dist/es5/utils/color-utils.js.map +1 -1
  44. package/dist/esm/aggregation-layer.js +12 -5
  45. package/dist/esm/aggregation-layer.js.map +1 -1
  46. package/dist/esm/contour-layer/contour-layer.js +6 -3
  47. package/dist/esm/contour-layer/contour-layer.js.map +1 -1
  48. package/dist/esm/contour-layer/contour-utils.js +1 -1
  49. package/dist/esm/contour-layer/contour-utils.js.map +1 -1
  50. package/dist/esm/contour-layer/marching-squares-codes.js.map +1 -1
  51. package/dist/esm/contour-layer/marching-squares.js.map +1 -1
  52. package/dist/esm/cpu-grid-layer/cpu-grid-layer.js +6 -3
  53. package/dist/esm/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  54. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js.map +1 -1
  55. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +1 -1
  56. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js.map +1 -1
  57. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer.js +8 -10
  58. package/dist/esm/gpu-grid-layer/gpu-grid-cell-layer.js.map +1 -1
  59. package/dist/esm/gpu-grid-layer/gpu-grid-layer.js +11 -9
  60. package/dist/esm/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  61. package/dist/esm/grid-aggregation-layer.js +13 -5
  62. package/dist/esm/grid-aggregation-layer.js.map +1 -1
  63. package/dist/esm/grid-layer/grid-layer.js +15 -8
  64. package/dist/esm/grid-layer/grid-layer.js.map +1 -1
  65. package/dist/esm/heatmap-layer/heatmap-layer-utils.js.map +1 -1
  66. package/dist/esm/heatmap-layer/heatmap-layer.js +22 -13
  67. package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
  68. package/dist/esm/heatmap-layer/max-fs.glsl.js.map +1 -1
  69. package/dist/esm/heatmap-layer/max-vs.glsl.js +1 -1
  70. package/dist/esm/heatmap-layer/max-vs.glsl.js.map +1 -1
  71. package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
  72. package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js.map +1 -1
  73. package/dist/esm/heatmap-layer/triangle-layer-vertex.glsl.js +1 -1
  74. package/dist/esm/heatmap-layer/triangle-layer-vertex.glsl.js.map +1 -1
  75. package/dist/esm/heatmap-layer/triangle-layer.js +6 -5
  76. package/dist/esm/heatmap-layer/triangle-layer.js.map +1 -1
  77. package/dist/esm/heatmap-layer/weights-fs.glsl.js +1 -1
  78. package/dist/esm/heatmap-layer/weights-fs.glsl.js.map +1 -1
  79. package/dist/esm/heatmap-layer/weights-vs.glsl.js +1 -1
  80. package/dist/esm/heatmap-layer/weights-vs.glsl.js.map +1 -1
  81. package/dist/esm/hexagon-layer/hexagon-layer.js +11 -2
  82. package/dist/esm/hexagon-layer/hexagon-layer.js.map +1 -1
  83. package/dist/esm/index.js.map +1 -1
  84. package/dist/esm/screen-grid-layer/screen-grid-cell-layer.js +16 -10
  85. package/dist/esm/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  86. package/dist/esm/screen-grid-layer/screen-grid-layer-fragment.glsl.js.map +1 -1
  87. package/dist/esm/screen-grid-layer/screen-grid-layer-vertex.glsl.js +1 -1
  88. package/dist/esm/screen-grid-layer/screen-grid-layer-vertex.glsl.js.map +1 -1
  89. package/dist/esm/screen-grid-layer/screen-grid-layer.js +15 -7
  90. package/dist/esm/screen-grid-layer/screen-grid-layer.js.map +1 -1
  91. package/dist/esm/types.js +2 -0
  92. package/dist/esm/types.js.map +1 -0
  93. package/dist/esm/utils/bin-sorter.js +16 -0
  94. package/dist/esm/utils/bin-sorter.js.map +1 -1
  95. package/dist/esm/utils/color-utils.js.map +1 -1
  96. package/dist.min.js +1 -1
  97. package/package.json +7 -5
  98. package/src/{aggregation-layer.js → aggregation-layer.ts} +32 -15
  99. package/src/contour-layer/{contour-layer.js → contour-layer.ts} +97 -16
  100. package/src/contour-layer/{contour-utils.js → contour-utils.ts} +11 -5
  101. package/src/contour-layer/{marching-squares-codes.js → marching-squares-codes.ts} +0 -0
  102. package/src/contour-layer/{marching-squares.js → marching-squares.ts} +6 -6
  103. package/src/cpu-grid-layer/cpu-grid-layer.ts +324 -0
  104. package/src/gpu-grid-layer/{gpu-grid-cell-layer-fragment.glsl.js → gpu-grid-cell-layer-fragment.glsl.ts} +0 -0
  105. package/src/gpu-grid-layer/{gpu-grid-cell-layer-vertex.glsl.js → gpu-grid-cell-layer-vertex.glsl.ts} +0 -0
  106. package/src/gpu-grid-layer/{gpu-grid-cell-layer.js → gpu-grid-cell-layer.ts} +36 -19
  107. package/src/gpu-grid-layer/{gpu-grid-layer.js → gpu-grid-layer.ts} +125 -18
  108. package/src/{grid-aggregation-layer.js → grid-aggregation-layer.ts} +25 -13
  109. package/src/grid-layer/{grid-layer.js → grid-layer.ts} +45 -14
  110. package/src/heatmap-layer/{heatmap-layer-utils.js → heatmap-layer-utils.ts} +5 -5
  111. package/src/heatmap-layer/{heatmap-layer.js → heatmap-layer.ts} +141 -30
  112. package/src/heatmap-layer/{max-fs.glsl.js → max-fs.glsl.ts} +0 -0
  113. package/src/heatmap-layer/{max-vs.glsl.js → max-vs.glsl.ts} +0 -0
  114. package/src/heatmap-layer/{triangle-layer-fragment.glsl.js → triangle-layer-fragment.glsl.ts} +0 -0
  115. package/src/heatmap-layer/{triangle-layer-vertex.glsl.js → triangle-layer-vertex.glsl.ts} +0 -0
  116. package/src/heatmap-layer/{triangle-layer.js → triangle-layer.ts} +20 -10
  117. package/src/heatmap-layer/{weights-fs.glsl.js → weights-fs.glsl.ts} +0 -0
  118. package/src/heatmap-layer/{weights-vs.glsl.js → weights-vs.glsl.ts} +0 -0
  119. package/src/hexagon-layer/{hexagon-layer.js → hexagon-layer.ts} +194 -9
  120. package/src/index.ts +9 -0
  121. package/src/screen-grid-layer/{screen-grid-cell-layer.js → screen-grid-cell-layer.ts} +33 -15
  122. package/src/screen-grid-layer/{screen-grid-layer-fragment.glsl.js → screen-grid-layer-fragment.glsl.ts} +0 -0
  123. package/src/screen-grid-layer/{screen-grid-layer-vertex.glsl.js → screen-grid-layer-vertex.glsl.ts} +0 -0
  124. package/src/screen-grid-layer/{screen-grid-layer.js → screen-grid-layer.ts} +119 -16
  125. package/src/types.ts +10 -0
  126. package/src/utils/{bin-sorter.js → bin-sorter.ts} +26 -11
  127. package/src/utils/{color-utils.js → color-utils.ts} +1 -1
  128. package/typed/aggregation-layer.d.ts +16 -11
  129. package/typed/aggregation-layer.d.ts.map +1 -1
  130. package/typed/contour-layer/contour-layer.d.ts +71 -36
  131. package/typed/contour-layer/contour-layer.d.ts.map +1 -1
  132. package/typed/contour-layer/contour-utils.d.ts +8 -9
  133. package/typed/contour-layer/contour-utils.d.ts.map +1 -1
  134. package/typed/contour-layer/marching-squares-codes.d.ts +2 -2
  135. package/typed/contour-layer/marching-squares-codes.d.ts.map +1 -1
  136. package/typed/contour-layer/marching-squares.d.ts +6 -6
  137. package/typed/contour-layer/marching-squares.d.ts.map +1 -1
  138. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts +147 -126
  139. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts.map +1 -1
  140. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts +1 -1
  141. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.d.ts.map +1 -1
  142. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts +1 -1
  143. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.d.ts.map +1 -1
  144. package/typed/gpu-grid-layer/gpu-grid-cell-layer.d.ts +30 -81
  145. package/typed/gpu-grid-layer/gpu-grid-cell-layer.d.ts.map +1 -1
  146. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts +93 -62
  147. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts.map +1 -1
  148. package/typed/grid-aggregation-layer.d.ts +19 -6
  149. package/typed/grid-aggregation-layer.d.ts.map +1 -1
  150. package/typed/grid-layer/grid-layer.d.ts +29 -91
  151. package/typed/grid-layer/grid-layer.d.ts.map +1 -1
  152. package/typed/heatmap-layer/heatmap-layer-utils.d.ts +6 -6
  153. package/typed/heatmap-layer/heatmap-layer-utils.d.ts.map +1 -1
  154. package/typed/heatmap-layer/heatmap-layer.d.ts +102 -82
  155. package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  156. package/typed/heatmap-layer/max-fs.glsl.d.ts +1 -1
  157. package/typed/heatmap-layer/max-fs.glsl.d.ts.map +1 -1
  158. package/typed/heatmap-layer/max-vs.glsl.d.ts +1 -1
  159. package/typed/heatmap-layer/max-vs.glsl.d.ts.map +1 -1
  160. package/typed/heatmap-layer/triangle-layer-fragment.glsl.d.ts +1 -1
  161. package/typed/heatmap-layer/triangle-layer-fragment.glsl.d.ts.map +1 -1
  162. package/typed/heatmap-layer/triangle-layer-vertex.glsl.d.ts +1 -1
  163. package/typed/heatmap-layer/triangle-layer-vertex.glsl.d.ts.map +1 -1
  164. package/typed/heatmap-layer/triangle-layer.d.ts +25 -8
  165. package/typed/heatmap-layer/triangle-layer.d.ts.map +1 -1
  166. package/typed/heatmap-layer/weights-fs.glsl.d.ts +1 -1
  167. package/typed/heatmap-layer/weights-fs.glsl.d.ts.map +1 -1
  168. package/typed/heatmap-layer/weights-vs.glsl.d.ts +1 -1
  169. package/typed/heatmap-layer/weights-vs.glsl.d.ts.map +1 -1
  170. package/typed/hexagon-layer/hexagon-layer.d.ts +160 -125
  171. package/typed/hexagon-layer/hexagon-layer.d.ts.map +1 -1
  172. package/typed/index.d.ts +7 -0
  173. package/typed/index.d.ts.map +1 -1
  174. package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts +34 -25
  175. package/typed/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  176. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts +1 -1
  177. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.d.ts.map +1 -1
  178. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts +1 -1
  179. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.d.ts.map +1 -1
  180. package/typed/screen-grid-layer/screen-grid-layer.d.ts +91 -30
  181. package/typed/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
  182. package/typed/types.d.ts +11 -0
  183. package/typed/types.d.ts.map +1 -0
  184. package/typed/utils/bin-sorter.d.ts +27 -21
  185. package/typed/utils/bin-sorter.d.ts.map +1 -1
  186. package/typed/utils/color-utils.d.ts +2 -2
  187. package/typed/utils/color-utils.d.ts.map +1 -1
  188. package/src/cpu-grid-layer/cpu-grid-layer.js +0 -153
@@ -0,0 +1,324 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+
21
+ import GL from '@luma.gl/constants';
22
+ import {GridCellLayer} from '@deck.gl/layers';
23
+ import {Accessor, AccessorFunction, Color, Position, Material, DefaultProps} from '@deck.gl/core';
24
+
25
+ import {defaultColorRange} from '../utils/color-utils';
26
+ import {pointToDensityGridDataCPU} from './grid-aggregator';
27
+ import CPUAggregator from '../utils/cpu-aggregator';
28
+ import AggregationLayer, {AggregationLayerProps} from '../aggregation-layer';
29
+
30
+ import Layer, {UpdateParameters} from 'modules/core/src/lib/layer';
31
+ import {GetPickingInfoParams, PickingInfo} from 'modules/core/src/lib/picking/pick-info';
32
+ import {AggregateAccessor} from '../types';
33
+
34
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
35
+ function nop() {}
36
+
37
+ const defaultProps: DefaultProps<CPUGridLayerProps> = {
38
+ // color
39
+ colorDomain: null,
40
+ colorRange: defaultColorRange,
41
+ getColorValue: {type: 'accessor', value: null}, // default value is calculated from `getColorWeight` and `colorAggregation`
42
+ getColorWeight: {type: 'accessor', value: 1},
43
+ colorAggregation: 'SUM',
44
+ lowerPercentile: {type: 'number', min: 0, max: 100, value: 0},
45
+ upperPercentile: {type: 'number', min: 0, max: 100, value: 100},
46
+ colorScaleType: 'quantize',
47
+ onSetColorDomain: nop,
48
+
49
+ // elevation
50
+ elevationDomain: null,
51
+ elevationRange: [0, 1000],
52
+ getElevationValue: {type: 'accessor', value: null}, // default value is calculated from `getElevationWeight` and `elevationAggregation`
53
+ getElevationWeight: {type: 'accessor', value: 1},
54
+ elevationAggregation: 'SUM',
55
+ elevationLowerPercentile: {type: 'number', min: 0, max: 100, value: 0},
56
+ elevationUpperPercentile: {type: 'number', min: 0, max: 100, value: 100},
57
+ elevationScale: {type: 'number', min: 0, value: 1},
58
+ elevationScaleType: 'linear',
59
+ onSetElevationDomain: nop,
60
+
61
+ gridAggregator: pointToDensityGridDataCPU,
62
+
63
+ // grid
64
+ cellSize: {type: 'number', min: 0, max: 1000, value: 1000},
65
+ coverage: {type: 'number', min: 0, max: 1, value: 1},
66
+ getPosition: {type: 'accessor', value: x => x.position},
67
+ extruded: false,
68
+
69
+ // Optional material for 'lighting' shader module
70
+ material: true,
71
+
72
+ // data filter
73
+ _filterData: {type: 'function', value: null, optional: true}
74
+ };
75
+
76
+ /** All properties supported by CPUGridLayer. */
77
+ export type CPUGridLayerProps<DataT = any> = _CPUGridLayerProps<DataT> &
78
+ AggregationLayerProps<DataT>;
79
+
80
+ /** Properties added by CPUGridLayer. */
81
+ export type _CPUGridLayerProps<DataT> = {
82
+ /**
83
+ * Size of each cell in meters.
84
+ * @default 1000
85
+ */
86
+ cellSize?: number;
87
+
88
+ /**
89
+ * Color scale domain, default is set to the extent of aggregated weights in each cell.
90
+ * @default [min(colorWeight), max(colorWeight)]
91
+ */
92
+ colorDomain?: [number, number] | null;
93
+
94
+ /**
95
+ * Default: [colorbrewer](http://colorbrewer2.org/#type=sequential&scheme=YlOrRd&n=6) `6-class YlOrRd`
96
+ */
97
+ colorRange?: Color[];
98
+
99
+ /**
100
+ * Cell size multiplier, clamped between 0 - 1.
101
+ * @default 1
102
+ */
103
+ coverage?: number;
104
+
105
+ /**
106
+ * Elevation scale input domain, default is set to between 0 and the max of aggregated weights in each cell.
107
+ * @default [0, max(elevationWeight)]
108
+ */
109
+ elevationDomain?: [number, number] | null;
110
+
111
+ /**
112
+ * Elevation scale output range.
113
+ * @default [0, 1000]
114
+ */
115
+ elevationRange?: [number, number];
116
+
117
+ /**
118
+ * Cell elevation multiplier.
119
+ * @default 1
120
+ */
121
+ elevationScale?: number;
122
+
123
+ /**
124
+ * Whether to enable cell elevation. If set to false, all cell will be flat.
125
+ * @default true
126
+ */
127
+ extruded?: boolean;
128
+
129
+ /**
130
+ * Filter cells and re-calculate color by `upperPercentile`.
131
+ * Cells with value arger than the upperPercentile will be hidden.
132
+ * @default 100
133
+ */
134
+ upperPercentile?: number;
135
+
136
+ /**
137
+ * Filter cells and re-calculate color by `lowerPercentile`.
138
+ * Cells with value smaller than the lowerPercentile will be hidden.
139
+ * @default 0
140
+ */
141
+ lowerPercentile?: number;
142
+
143
+ /**
144
+ * Filter cells and re-calculate elevation by `elevationUpperPercentile`.
145
+ * Cells with elevation value larger than the `elevationUpperPercentile` will be hidden.
146
+ * @default 100
147
+ */
148
+ elevationUpperPercentile?: number;
149
+
150
+ /**
151
+ * Filter cells and re-calculate elevation by `elevationLowerPercentile`.
152
+ * Cells with elevation value larger than the `elevationLowerPercentile` will be hidden.
153
+ * @default 0
154
+ */
155
+ elevationLowerPercentile?: number;
156
+
157
+ /**
158
+ * Scaling function used to determine the color of the grid cell, default value is 'quantize'.
159
+ * Supported Values are 'quantize', 'linear', 'quantile' and 'ordinal'.
160
+ * @default 'quantize'
161
+ */
162
+ colorScaleType?: 'quantize' | 'linear' | 'quantile' | 'ordinal';
163
+
164
+ /**
165
+ * Scaling function used to determine the elevation of the grid cell, only supports 'linear'.
166
+ */
167
+ elevationScaleType?: 'linear';
168
+
169
+ // TODO - document
170
+ gridAggregator?: (props: any, params: any) => any;
171
+
172
+ /**
173
+ * Material settings for lighting effect. Applies if `extruded: true`.
174
+ *
175
+ * @default true
176
+ * @see https://deck.gl/docs/developer-guide/using-lighting
177
+ */
178
+ material?: Material;
179
+
180
+ /**
181
+ * Defines the operation used to aggregate all data object weights to calculate a cell's color value.
182
+ * @default 'SUM'
183
+ */
184
+ colorAggregation?: 'SUM' | 'MEAN' | 'MIN' | 'MAX';
185
+
186
+ /**
187
+ * Defines the operation used to aggregate all data object weights to calculate a cell's elevation value.
188
+ * @default 'SUM'
189
+ */
190
+ elevationAggregation?: 'SUM' | 'MEAN' | 'MIN' | 'MAX';
191
+
192
+ /**
193
+ * Method called to retrieve the position of each object.
194
+ * @default object => object.position
195
+ */
196
+ getPosition?: AccessorFunction<DataT, Position>;
197
+
198
+ /**
199
+ * The weight of a data object used to calculate the color value for a cell.
200
+ * @default 1
201
+ */
202
+ getColorWeight?: Accessor<DataT, number>;
203
+
204
+ /**
205
+ * After data objects are aggregated into cells, this accessor is called on each cell to get the value that its color is based on.
206
+ * @default null
207
+ */
208
+ getColorValue?: AggregateAccessor<DataT> | null;
209
+
210
+ /**
211
+ * The weight of a data object used to calculate the elevation value for a cell.
212
+ * @default 1
213
+ */
214
+ getElevationWeight?: Accessor<DataT, number>;
215
+
216
+ /**
217
+ * After data objects are aggregated into cells, this accessor is called on each cell to get the value that its elevation is based on.
218
+ * @default null
219
+ */
220
+ getElevationValue?: AggregateAccessor<DataT> | null;
221
+
222
+ /**
223
+ * This callback will be called when bin color domain has been calculated.
224
+ * @default () => {}
225
+ */
226
+ onSetColorDomain?: (minMax: [number, number]) => void;
227
+
228
+ /**
229
+ * This callback will be called when bin elevation domain has been calculated.
230
+ * @default () => {}
231
+ */
232
+ onSetElevationDomain?: (minMax: [number, number]) => void;
233
+
234
+ /**
235
+ * (Experimental) Filter data objects
236
+ */
237
+ _filterData: null | ((d: DataT) => boolean);
238
+ };
239
+
240
+ export default class CPUGridLayer<DataT = any, ExtraPropsT = {}> extends AggregationLayer<
241
+ ExtraPropsT & Required<_CPUGridLayerProps<DataT>>
242
+ > {
243
+ static layerName = 'CPUGridLayer';
244
+ static defaultProps = defaultProps;
245
+
246
+ initializeState(): void {
247
+ const cpuAggregator = new CPUAggregator({
248
+ getAggregator: props => props.gridAggregator,
249
+ getCellSize: props => props.cellSize
250
+ });
251
+
252
+ this.state = {
253
+ cpuAggregator,
254
+ aggregatorState: cpuAggregator.state
255
+ };
256
+ const attributeManager = this.getAttributeManager()!;
257
+ attributeManager.add({
258
+ positions: {size: 3, type: GL.DOUBLE, accessor: 'getPosition'}
259
+ });
260
+ // color and elevation attributes can't be added as attributes
261
+ // they are calcualted using 'getValue' accessor that takes an array of pints.
262
+ }
263
+
264
+ updateState(opts: UpdateParameters<this>) {
265
+ super.updateState(opts);
266
+ this.setState({
267
+ // make a copy of the internal state of cpuAggregator for testing
268
+ aggregatorState: this.state.cpuAggregator.updateState(opts, {
269
+ viewport: this.context.viewport,
270
+ attributes: this.getAttributes(),
271
+ numInstances: this.getNumInstances()
272
+ })
273
+ });
274
+ }
275
+
276
+ getPickingInfo({info}: GetPickingInfoParams): PickingInfo {
277
+ return this.state.cpuAggregator.getPickingInfo({info});
278
+ }
279
+
280
+ // create a method for testing
281
+ _onGetSublayerColor(cell) {
282
+ return this.state.cpuAggregator.getAccessor('fillColor')(cell);
283
+ }
284
+
285
+ // create a method for testing
286
+ _onGetSublayerElevation(cell) {
287
+ return this.state.cpuAggregator.getAccessor('elevation')(cell);
288
+ }
289
+
290
+ _getSublayerUpdateTriggers() {
291
+ return this.state.cpuAggregator.getUpdateTriggers(this.props);
292
+ }
293
+
294
+ renderLayers(): Layer {
295
+ const {elevationScale, extruded, cellSize, coverage, material, transitions} = this.props;
296
+ const {cpuAggregator} = this.state;
297
+ const SubLayerClass = this.getSubLayerClass('grid-cell', GridCellLayer);
298
+ const updateTriggers = this._getSublayerUpdateTriggers();
299
+
300
+ return new SubLayerClass(
301
+ {
302
+ cellSize,
303
+ coverage,
304
+ material,
305
+ elevationScale,
306
+ extruded,
307
+
308
+ getFillColor: this._onGetSublayerColor.bind(this),
309
+ getElevation: this._onGetSublayerElevation.bind(this),
310
+ transitions: transitions && {
311
+ getFillColor: transitions.getColorValue || transitions.getColorWeight,
312
+ getElevation: transitions.getElevationValue || transitions.getElevationWeight
313
+ }
314
+ },
315
+ this.getSubLayerProps({
316
+ id: 'grid-cell',
317
+ updateTriggers
318
+ }),
319
+ {
320
+ data: cpuAggregator.state.layerData.data
321
+ }
322
+ );
323
+ }
324
+ }
@@ -18,19 +18,28 @@
18
18
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  // THE SOFTWARE.
20
20
 
21
- import {Layer, fp64LowPart, project32, gouraudLighting, picking} from '@deck.gl/core';
21
+ import {
22
+ Layer,
23
+ fp64LowPart,
24
+ project32,
25
+ gouraudLighting,
26
+ picking,
27
+ LayerContext,
28
+ LayerProps,
29
+ DefaultProps
30
+ } from '@deck.gl/core';
22
31
  import GL from '@luma.gl/constants';
23
- import {Model, CubeGeometry} from '@luma.gl/core';
32
+ import {Model, CubeGeometry, Buffer} from '@luma.gl/core';
24
33
  import {fp64arithmetic} from '@luma.gl/shadertools';
25
34
  import {defaultColorRange, colorRangeToFlatArray} from '../utils/color-utils';
26
-
35
+ import type {_GPUGridLayerProps} from './gpu-grid-layer';
27
36
  import vs from './gpu-grid-cell-layer-vertex.glsl';
28
37
  import fs from './gpu-grid-cell-layer-fragment.glsl';
29
38
 
30
39
  const COLOR_DATA_UBO_INDEX = 0;
31
40
  const ELEVATION_DATA_UBO_INDEX = 1;
32
41
 
33
- const defaultProps = {
42
+ const defaultProps: DefaultProps<_GPUGridCellLayerProps & LayerProps> = {
34
43
  // color
35
44
  colorDomain: null,
36
45
  colorRange: defaultColorRange,
@@ -41,19 +50,31 @@ const defaultProps = {
41
50
  elevationScale: {type: 'number', min: 0, value: 1},
42
51
 
43
52
  // grid
44
- gridSize: {type: 'array', min: 0, value: [1, 1]},
45
- gridOrigin: {type: 'array', min: 0, value: [0, 0]},
46
- gridOffset: {type: 'array', min: 0, value: [0, 0]},
53
+ gridSize: {type: 'array', value: [1, 1]},
54
+ gridOrigin: {type: 'array', value: [0, 0]},
55
+ gridOffset: {type: 'array', value: [0, 0]},
47
56
 
48
57
  cellSize: {type: 'number', min: 0, max: 1000, value: 1000},
49
- offset: {type: 'array', min: 0, value: [1, 1]},
58
+ offset: {type: 'array', value: [1, 1]},
50
59
  coverage: {type: 'number', min: 0, max: 1, value: 1},
51
60
  extruded: true,
52
61
 
53
62
  material: true // Use lighting module defaults
54
63
  };
55
64
 
56
- export default class GPUGridCellLayer extends Layer {
65
+ type _GPUGridCellLayerProps = _GPUGridLayerProps<any> & {
66
+ offset: number[];
67
+ gridSize: number[];
68
+ gridOrigin: number[];
69
+ gridOffset: number[];
70
+ colorMaxMinBuffer: Buffer;
71
+ elevationMaxMinBuffer: Buffer;
72
+ };
73
+
74
+ export default class GPUGridCellLayer extends Layer<_GPUGridCellLayerProps> {
75
+ static layerName = 'GPUGridCellLayer';
76
+ static defaultProps = defaultProps;
77
+
57
78
  getShaders() {
58
79
  return super.getShaders({
59
80
  vs,
@@ -62,9 +83,8 @@ export default class GPUGridCellLayer extends Layer {
62
83
  });
63
84
  }
64
85
 
65
- initializeState() {
66
- const {gl} = this.context;
67
- const attributeManager = this.getAttributeManager();
86
+ initializeState({gl}: LayerContext) {
87
+ const attributeManager = this.getAttributeManager()!;
68
88
  attributeManager.addInstanced({
69
89
  colors: {
70
90
  size: 4,
@@ -80,7 +100,7 @@ export default class GPUGridCellLayer extends Layer {
80
100
  this.setState({model});
81
101
  }
82
102
 
83
- _getModel(gl) {
103
+ _getModel(gl: WebGLRenderingContext): Model {
84
104
  return new Model(gl, {
85
105
  ...this.getShaders(),
86
106
  id: this.props.id,
@@ -142,7 +162,7 @@ export default class GPUGridCellLayer extends Layer {
142
162
 
143
163
  getDomainUniforms() {
144
164
  const {colorDomain, elevationDomain} = this.props;
145
- const domainUniforms = {};
165
+ const domainUniforms: Record<string, any> = {};
146
166
  if (colorDomain !== null) {
147
167
  domainUniforms.colorDomainValid = true;
148
168
  domainUniforms.colorDomain = colorDomain;
@@ -158,8 +178,8 @@ export default class GPUGridCellLayer extends Layer {
158
178
  return domainUniforms;
159
179
  }
160
180
 
161
- _setupUniformBuffer(model) {
162
- const gl = this.context.gl;
181
+ private _setupUniformBuffer(model: Model): void {
182
+ const gl = this.context.gl as WebGL2RenderingContext;
163
183
  const programHandle = model.program.handle;
164
184
 
165
185
  const colorIndex = gl.getUniformBlockIndex(programHandle, 'ColorData');
@@ -168,6 +188,3 @@ export default class GPUGridCellLayer extends Layer {
168
188
  gl.uniformBlockBinding(programHandle, elevationIndex, ELEVATION_DATA_UBO_INDEX);
169
189
  }
170
190
  }
171
-
172
- GPUGridCellLayer.layerName = 'GPUGridCellLayer';
173
- GPUGridCellLayer.defaultProps = defaultProps;
@@ -20,17 +20,28 @@
20
20
 
21
21
  import {Buffer} from '@luma.gl/core';
22
22
  import GL from '@luma.gl/constants';
23
- import {log} from '@deck.gl/core';
23
+ import {
24
+ Accessor,
25
+ AccessorFunction,
26
+ Color,
27
+ Material,
28
+ GetPickingInfoParams,
29
+ LayerContext,
30
+ log,
31
+ PickingInfo,
32
+ Position,
33
+ DefaultProps
34
+ } from '@deck.gl/core';
24
35
 
25
36
  import GPUGridAggregator from '../utils/gpu-grid-aggregation/gpu-grid-aggregator';
26
37
  import {AGGREGATION_OPERATION} from '../utils/aggregation-operation-utils';
27
38
  import {defaultColorRange, colorRangeToFlatArray} from '../utils/color-utils';
28
39
  import GPUGridCellLayer from './gpu-grid-cell-layer';
29
40
  import {pointToDensityGridDataCPU} from './../cpu-grid-layer/grid-aggregator';
30
- import GridAggregationLayer from '../grid-aggregation-layer';
41
+ import GridAggregationLayer, {GridAggregationLayerProps} from '../grid-aggregation-layer';
31
42
  import {getBoundingBox, getGridParams} from '../utils/grid-aggregation-utils';
32
43
 
33
- const defaultProps = {
44
+ const defaultProps: DefaultProps<GPUGridLayerProps> = {
34
45
  // color
35
46
  colorDomain: null,
36
47
  colorRange: defaultColorRange,
@@ -65,14 +76,113 @@ const DIMENSIONS = {
65
76
  };
66
77
  const POSITION_ATTRIBUTE_NAME = 'positions';
67
78
 
68
- export default class GPUGridLayer extends GridAggregationLayer {
69
- initializeState() {
70
- const {gl} = this.context;
79
+ /** All properties supported by GPUGridLayer. */
80
+ export type GPUGridLayerProps<DataT = any> = _GPUGridLayerProps<DataT> &
81
+ GridAggregationLayerProps<DataT>;
82
+
83
+ /** Properties added by GPUGridLayer. */
84
+ export type _GPUGridLayerProps<DataT> = {
85
+ /**
86
+ * Size of each cell in meters.
87
+ * @default 1000
88
+ */
89
+ cellSize?: number;
90
+
91
+ /**
92
+ * Color scale domain, default is set to the extent of aggregated weights in each cell.
93
+ * @default [min(colorWeight), max(colorWeight)]
94
+ */
95
+ colorDomain?: [number, number] | null;
96
+
97
+ /**
98
+ * Default: [colorbrewer](http://colorbrewer2.org/#type=sequential&scheme=YlOrRd&n=6) `6-class YlOrRd`
99
+ */
100
+ colorRange?: Color[];
101
+
102
+ /**
103
+ * Cell size multiplier, clamped between 0 - 1.
104
+ * @default 1
105
+ */
106
+ coverage?: number;
107
+
108
+ /**
109
+ * Elevation scale input domain, default is set to between 0 and the max of aggregated weights in each cell.
110
+ * @default [0, max(elevationWeight)]
111
+ */
112
+ elevationDomain?: [number, number] | null;
113
+
114
+ /**
115
+ * Elevation scale output range.
116
+ * @default [0, 1000]
117
+ */
118
+ elevationRange?: [number, number];
119
+
120
+ /**
121
+ * Cell elevation multiplier.
122
+ * @default 1
123
+ */
124
+ elevationScale?: number;
125
+
126
+ /**
127
+ * Whether to enable cell elevation. If set to false, all cell will be flat.
128
+ * @default true
129
+ */
130
+ extruded?: boolean;
131
+
132
+ /**
133
+ * Material settings for lighting effect. Applies if `extruded: true`.
134
+ *
135
+ * @default true
136
+ * @see https://deck.gl/docs/developer-guide/using-lighting
137
+ */
138
+ material?: Material;
139
+
140
+ /**
141
+ * Defines the operation used to aggregate all data object weights to calculate a cell's color value.
142
+ * @default 'SUM'
143
+ */
144
+ colorAggregation?: 'SUM' | 'MEAN' | 'MIN' | 'MAX';
145
+
146
+ /**
147
+ * Defines the operation used to aggregate all data object weights to calculate a cell's elevation value.
148
+ * @default 'SUM'
149
+ */
150
+ elevationAggregation?: 'SUM' | 'MEAN' | 'MIN' | 'MAX';
151
+
152
+ /**
153
+ * Method called to retrieve the position of each object.
154
+ * @default object => object.position
155
+ */
156
+ getPosition?: AccessorFunction<DataT, Position>;
157
+
158
+ /**
159
+ * The weight of a data object used to calculate the color value for a cell.
160
+ * @default 1
161
+ */
162
+ getColorWeight?: Accessor<DataT, number>;
163
+
164
+ /**
165
+ * The weight of a data object used to calculate the elevation value for a cell.
166
+ * @default 1
167
+ */
168
+ getElevationWeight?: Accessor<DataT, number>;
169
+ };
170
+
171
+ /**
172
+ * The `GPUGridLayer` renders a grid heatmap based on an array of inputs.
173
+ */
174
+ export default class GPUGridLayer<DataT = any, ExtraPropsT = {}> extends GridAggregationLayer<
175
+ ExtraPropsT & Required<_GPUGridLayerProps<DataT>>
176
+ > {
177
+ static layerName = 'GPUGridLayer';
178
+ static defaultProps = defaultProps;
179
+
180
+ initializeState({gl}: LayerContext): void {
71
181
  const isSupported = GPUGridAggregator.isSupported(gl);
72
182
  if (!isSupported) {
73
183
  log.error('GPUGridLayer is not supported on this browser, use GridLayer instead')();
74
184
  }
75
- super.initializeState({
185
+ super.initializeAggregationLayer({
76
186
  dimensions: DIMENSIONS
77
187
  });
78
188
  this.setState({
@@ -101,7 +211,7 @@ export default class GPUGridLayer extends GridAggregationLayer {
101
211
  },
102
212
  positionAttributeName: 'positions'
103
213
  });
104
- const attributeManager = this.getAttributeManager();
214
+ const attributeManager = this.getAttributeManager()!;
105
215
  attributeManager.add({
106
216
  [POSITION_ATTRIBUTE_NAME]: {
107
217
  size: 3,
@@ -129,7 +239,7 @@ export default class GPUGridLayer extends GridAggregationLayer {
129
239
  }
130
240
  }
131
241
 
132
- getHashKeyForIndex(index) {
242
+ getHashKeyForIndex(index: number): string {
133
243
  const {numRow, numCol, boundingBox, gridOffset} = this.state;
134
244
  const gridSize = [numCol, numRow];
135
245
  const gridOrigin = [boundingBox.xMin, boundingBox.yMin];
@@ -147,7 +257,7 @@ export default class GPUGridLayer extends GridAggregationLayer {
147
257
  return `${latIdx}-${lonIdx}`;
148
258
  }
149
259
 
150
- getPositionForIndex(index) {
260
+ getPositionForIndex(index: number): Position {
151
261
  const {numRow, numCol, boundingBox, gridOffset} = this.state;
152
262
  const gridSize = [numCol, numRow];
153
263
  const gridOrigin = [boundingBox.xMin, boundingBox.yMin];
@@ -160,9 +270,9 @@ export default class GPUGridLayer extends GridAggregationLayer {
160
270
  return [xPos, yPos];
161
271
  }
162
272
 
163
- getPickingInfo({info, mode}) {
273
+ getPickingInfo({info, mode}: GetPickingInfoParams): PickingInfo {
164
274
  const {index} = info;
165
- let object = null;
275
+ let object: any = null;
166
276
  if (index >= 0) {
167
277
  const {gpuGridAggregator} = this.state;
168
278
  const position = this.getPositionForIndex(index);
@@ -190,7 +300,7 @@ export default class GPUGridLayer extends GridAggregationLayer {
190
300
  const {gridOffset, translation, boundingBox} = this.state;
191
301
  const {viewport} = this.context;
192
302
  const attributes = this.getAttributes();
193
- const cpuAggregation = pointToDensityGridDataCPU(props, {
303
+ const cpuAggregation = pointToDensityGridDataCPU(props as any, {
194
304
  gridOffset,
195
305
  attributes,
196
306
  viewport,
@@ -267,14 +377,14 @@ export default class GPUGridLayer extends GridAggregationLayer {
267
377
  );
268
378
  }
269
379
 
270
- finalizeState() {
380
+ finalizeState(context: LayerContext) {
271
381
  const {color, elevation} = this.state.weights;
272
382
  [color, elevation].forEach(weight => {
273
383
  const {aggregationBuffer, maxMinBuffer} = weight;
274
384
  maxMinBuffer.delete();
275
385
  aggregationBuffer?.delete();
276
386
  });
277
- super.finalizeState();
387
+ super.finalizeState(context);
278
388
  }
279
389
 
280
390
  // Aggregation Overrides
@@ -338,6 +448,3 @@ export default class GPUGridLayer extends GridAggregationLayer {
338
448
  elevation.operation = AGGREGATION_OPERATION[elevationAggregation];
339
449
  }
340
450
  }
341
-
342
- GPUGridLayer.layerName = 'GPUGridLayer';
343
- GPUGridLayer.defaultProps = defaultProps;