@deck.gl/aggregation-layers 9.4.0-alpha.1 → 9.4.0-beta.1

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 (210) hide show
  1. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.d.ts.map +1 -1
  2. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js +1 -3
  3. package/dist/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js.map +1 -1
  4. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js +0 -1
  5. package/dist/common/aggregator/gpu-aggregator/webgl-bin-sorter.js.map +1 -1
  6. package/dist/dist.dev.js +642 -38
  7. package/dist/grid-layer/grid-cell-layer.d.ts.map +1 -1
  8. package/dist/grid-layer/grid-cell-layer.js +3 -2
  9. package/dist/grid-layer/grid-cell-layer.js.map +1 -1
  10. package/dist/grid-layer/grid-cell-layer.wgsl.d.ts +3 -0
  11. package/dist/grid-layer/grid-cell-layer.wgsl.d.ts.map +1 -0
  12. package/dist/grid-layer/grid-cell-layer.wgsl.js +114 -0
  13. package/dist/grid-layer/grid-cell-layer.wgsl.js.map +1 -0
  14. package/dist/grid-layer/grid-layer-uniforms.d.ts +1 -0
  15. package/dist/grid-layer/grid-layer-uniforms.d.ts.map +1 -1
  16. package/dist/grid-layer/grid-layer-uniforms.js +14 -0
  17. package/dist/grid-layer/grid-layer-uniforms.js.map +1 -1
  18. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts +2 -0
  19. package/dist/heatmap-layer/heatmap-layer-uniforms.d.ts.map +1 -1
  20. package/dist/heatmap-layer/heatmap-layer-uniforms.js +19 -0
  21. package/dist/heatmap-layer/heatmap-layer-uniforms.js.map +1 -1
  22. package/dist/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  23. package/dist/heatmap-layer/heatmap-layer.js +59 -12
  24. package/dist/heatmap-layer/heatmap-layer.js.map +1 -1
  25. package/dist/heatmap-layer/max.wgsl.d.ts +3 -0
  26. package/dist/heatmap-layer/max.wgsl.d.ts.map +1 -0
  27. package/dist/heatmap-layer/max.wgsl.js +48 -0
  28. package/dist/heatmap-layer/max.wgsl.js.map +1 -0
  29. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts +1 -0
  30. package/dist/heatmap-layer/triangle-layer-uniforms.d.ts.map +1 -1
  31. package/dist/heatmap-layer/triangle-layer-uniforms.js +16 -0
  32. package/dist/heatmap-layer/triangle-layer-uniforms.js.map +1 -1
  33. package/dist/heatmap-layer/triangle-layer.d.ts.map +1 -1
  34. package/dist/heatmap-layer/triangle-layer.js +3 -2
  35. package/dist/heatmap-layer/triangle-layer.js.map +1 -1
  36. package/dist/heatmap-layer/triangle-layer.wgsl.d.ts +3 -0
  37. package/dist/heatmap-layer/triangle-layer.wgsl.d.ts.map +1 -0
  38. package/dist/heatmap-layer/triangle-layer.wgsl.js +65 -0
  39. package/dist/heatmap-layer/triangle-layer.wgsl.js.map +1 -0
  40. package/dist/heatmap-layer/weights.wgsl.d.ts +3 -0
  41. package/dist/heatmap-layer/weights.wgsl.d.ts.map +1 -0
  42. package/dist/heatmap-layer/weights.wgsl.js +64 -0
  43. package/dist/heatmap-layer/weights.wgsl.js.map +1 -0
  44. package/dist/hexagon-layer/hexagon-cell-layer.d.ts.map +1 -1
  45. package/dist/hexagon-layer/hexagon-cell-layer.js +2 -2
  46. package/dist/hexagon-layer/hexagon-cell-layer.js.map +1 -1
  47. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.d.ts +3 -0
  48. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.d.ts.map +1 -0
  49. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.js +120 -0
  50. package/dist/hexagon-layer/hexagon-cell-layer.wgsl.js.map +1 -0
  51. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts +1 -0
  52. package/dist/hexagon-layer/hexagon-layer-uniforms.d.ts.map +1 -1
  53. package/dist/hexagon-layer/hexagon-layer-uniforms.js +13 -0
  54. package/dist/hexagon-layer/hexagon-layer-uniforms.js.map +1 -1
  55. package/dist/index.cjs +13268 -1488
  56. package/dist/index.cjs.map +3 -4
  57. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts +1 -6
  58. package/dist/screen-grid-layer/screen-grid-cell-layer.d.ts.map +1 -1
  59. package/dist/screen-grid-layer/screen-grid-cell-layer.js +3 -2
  60. package/dist/screen-grid-layer/screen-grid-cell-layer.js.map +1 -1
  61. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.d.ts +3 -0
  62. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.d.ts.map +1 -0
  63. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.js +76 -0
  64. package/dist/screen-grid-layer/screen-grid-cell-layer.wgsl.js.map +1 -0
  65. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts +1 -0
  66. package/dist/screen-grid-layer/screen-grid-layer-uniforms.d.ts.map +1 -1
  67. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js +12 -0
  68. package/dist/screen-grid-layer/screen-grid-layer-uniforms.js.map +1 -1
  69. package/dist.min.js +545 -35
  70. package/dist.webgl-only/common/aggregation-layer.js +68 -0
  71. package/dist.webgl-only/common/aggregation-layer.js.map +1 -0
  72. package/dist.webgl-only/common/aggregator/aggregator.js +5 -0
  73. package/dist.webgl-only/common/aggregator/aggregator.js.map +1 -0
  74. package/dist.webgl-only/common/aggregator/cpu-aggregator/aggregate.js +69 -0
  75. package/dist.webgl-only/common/aggregator/cpu-aggregator/aggregate.js.map +1 -0
  76. package/dist.webgl-only/common/aggregator/cpu-aggregator/cpu-aggregator.js +141 -0
  77. package/dist.webgl-only/common/aggregator/cpu-aggregator/cpu-aggregator.js.map +1 -0
  78. package/dist.webgl-only/common/aggregator/cpu-aggregator/sort-bins.js +44 -0
  79. package/dist.webgl-only/common/aggregator/cpu-aggregator/sort-bins.js.map +1 -0
  80. package/dist.webgl-only/common/aggregator/cpu-aggregator/vertex-accessor.js +56 -0
  81. package/dist.webgl-only/common/aggregator/cpu-aggregator/vertex-accessor.js.map +1 -0
  82. package/dist.webgl-only/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.js +22 -0
  83. package/dist.webgl-only/common/aggregator/gpu-aggregator/aggregation-transform-uniforms.js.map +1 -0
  84. package/dist.webgl-only/common/aggregator/gpu-aggregator/bin-sorter-uniforms.js +18 -0
  85. package/dist.webgl-only/common/aggregator/gpu-aggregator/bin-sorter-uniforms.js.map +1 -0
  86. package/dist.webgl-only/common/aggregator/gpu-aggregator/utils.js +24 -0
  87. package/dist.webgl-only/common/aggregator/gpu-aggregator/utils.js.map +1 -0
  88. package/dist.webgl-only/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js +222 -0
  89. package/dist.webgl-only/common/aggregator/gpu-aggregator/webgl-aggregation-transform.js.map +1 -0
  90. package/dist.webgl-only/common/aggregator/gpu-aggregator/webgl-aggregator.js +203 -0
  91. package/dist.webgl-only/common/aggregator/gpu-aggregator/webgl-aggregator.js.map +1 -0
  92. package/dist.webgl-only/common/aggregator/gpu-aggregator/webgl-bin-sorter.js +225 -0
  93. package/dist.webgl-only/common/aggregator/gpu-aggregator/webgl-bin-sorter.js.map +1 -0
  94. package/dist.webgl-only/common/aggregator/index.js +6 -0
  95. package/dist.webgl-only/common/aggregator/index.js.map +1 -0
  96. package/dist.webgl-only/common/types.js +5 -0
  97. package/dist.webgl-only/common/types.js.map +1 -0
  98. package/dist.webgl-only/common/utils/bounds-utils.js +21 -0
  99. package/dist.webgl-only/common/utils/bounds-utils.js.map +1 -0
  100. package/dist.webgl-only/common/utils/color-utils.js +65 -0
  101. package/dist.webgl-only/common/utils/color-utils.js.map +1 -0
  102. package/dist.webgl-only/common/utils/prop-utils.js +13 -0
  103. package/dist.webgl-only/common/utils/prop-utils.js.map +1 -0
  104. package/dist.webgl-only/common/utils/scale-utils.js +181 -0
  105. package/dist.webgl-only/common/utils/scale-utils.js.map +1 -0
  106. package/dist.webgl-only/contour-layer/bin-options-uniforms.js +18 -0
  107. package/dist.webgl-only/contour-layer/bin-options-uniforms.js.map +1 -0
  108. package/dist.webgl-only/contour-layer/contour-layer.js +282 -0
  109. package/dist.webgl-only/contour-layer/contour-layer.js.map +1 -0
  110. package/dist.webgl-only/contour-layer/contour-utils.js +60 -0
  111. package/dist.webgl-only/contour-layer/contour-utils.js.map +1 -0
  112. package/dist.webgl-only/contour-layer/marching-squares-codes.js +341 -0
  113. package/dist.webgl-only/contour-layer/marching-squares-codes.js.map +1 -0
  114. package/dist.webgl-only/contour-layer/marching-squares.js +151 -0
  115. package/dist.webgl-only/contour-layer/marching-squares.js.map +1 -0
  116. package/dist.webgl-only/contour-layer/value-reader.js +47 -0
  117. package/dist.webgl-only/contour-layer/value-reader.js.map +1 -0
  118. package/dist.webgl-only/grid-layer/bin-options-uniforms.js +18 -0
  119. package/dist.webgl-only/grid-layer/bin-options-uniforms.js.map +1 -0
  120. package/dist.webgl-only/grid-layer/grid-cell-layer-vertex.glsl.js +51 -0
  121. package/dist.webgl-only/grid-layer/grid-cell-layer-vertex.glsl.js.map +1 -0
  122. package/dist.webgl-only/grid-layer/grid-cell-layer.js +95 -0
  123. package/dist.webgl-only/grid-layer/grid-cell-layer.js.map +1 -0
  124. package/dist.webgl-only/grid-layer/grid-cell-layer.wgsl.js +5 -0
  125. package/dist.webgl-only/grid-layer/grid-cell-layer.wgsl.js.map +1 -0
  126. package/dist.webgl-only/grid-layer/grid-layer-uniforms.js +26 -0
  127. package/dist.webgl-only/grid-layer/grid-layer-uniforms.js.map +1 -0
  128. package/dist.webgl-only/grid-layer/grid-layer.js +362 -0
  129. package/dist.webgl-only/grid-layer/grid-layer.js.map +1 -0
  130. package/dist.webgl-only/heatmap-layer/aggregation-layer.js +140 -0
  131. package/dist.webgl-only/heatmap-layer/aggregation-layer.js.map +1 -0
  132. package/dist.webgl-only/heatmap-layer/heatmap-layer-uniforms.js +36 -0
  133. package/dist.webgl-only/heatmap-layer/heatmap-layer-uniforms.js.map +1 -0
  134. package/dist.webgl-only/heatmap-layer/heatmap-layer-utils.js +67 -0
  135. package/dist.webgl-only/heatmap-layer/heatmap-layer-utils.js.map +1 -0
  136. package/dist.webgl-only/heatmap-layer/heatmap-layer.js +513 -0
  137. package/dist.webgl-only/heatmap-layer/heatmap-layer.js.map +1 -0
  138. package/dist.webgl-only/heatmap-layer/max-fs.glsl.js +13 -0
  139. package/dist.webgl-only/heatmap-layer/max-fs.glsl.js.map +1 -0
  140. package/dist.webgl-only/heatmap-layer/max-vs.glsl.js +18 -0
  141. package/dist.webgl-only/heatmap-layer/max-vs.glsl.js.map +1 -0
  142. package/dist.webgl-only/heatmap-layer/max.wgsl.js +5 -0
  143. package/dist.webgl-only/heatmap-layer/max.wgsl.js.map +1 -0
  144. package/dist.webgl-only/heatmap-layer/triangle-layer-fragment.glsl.js +34 -0
  145. package/dist.webgl-only/heatmap-layer/triangle-layer-fragment.glsl.js.map +1 -0
  146. package/dist.webgl-only/heatmap-layer/triangle-layer-uniforms.js +25 -0
  147. package/dist.webgl-only/heatmap-layer/triangle-layer-uniforms.js.map +1 -0
  148. package/dist.webgl-only/heatmap-layer/triangle-layer-vertex.glsl.js +28 -0
  149. package/dist.webgl-only/heatmap-layer/triangle-layer-vertex.glsl.js.map +1 -0
  150. package/dist.webgl-only/heatmap-layer/triangle-layer.js +49 -0
  151. package/dist.webgl-only/heatmap-layer/triangle-layer.js.map +1 -0
  152. package/dist.webgl-only/heatmap-layer/triangle-layer.wgsl.js +5 -0
  153. package/dist.webgl-only/heatmap-layer/triangle-layer.wgsl.js.map +1 -0
  154. package/dist.webgl-only/heatmap-layer/weights-fs.glsl.js +21 -0
  155. package/dist.webgl-only/heatmap-layer/weights-fs.glsl.js.map +1 -0
  156. package/dist.webgl-only/heatmap-layer/weights-vs.glsl.js +21 -0
  157. package/dist.webgl-only/heatmap-layer/weights-vs.glsl.js.map +1 -0
  158. package/dist.webgl-only/heatmap-layer/weights.wgsl.js +5 -0
  159. package/dist.webgl-only/heatmap-layer/weights.wgsl.js.map +1 -0
  160. package/dist.webgl-only/hexagon-layer/bin-options-uniforms.js +18 -0
  161. package/dist.webgl-only/hexagon-layer/bin-options-uniforms.js.map +1 -0
  162. package/dist.webgl-only/hexagon-layer/hexagon-cell-layer-vertex.glsl.js +55 -0
  163. package/dist.webgl-only/hexagon-layer/hexagon-cell-layer-vertex.glsl.js.map +1 -0
  164. package/dist.webgl-only/hexagon-layer/hexagon-cell-layer.js +90 -0
  165. package/dist.webgl-only/hexagon-layer/hexagon-cell-layer.js.map +1 -0
  166. package/dist.webgl-only/hexagon-layer/hexagon-cell-layer.wgsl.js +5 -0
  167. package/dist.webgl-only/hexagon-layer/hexagon-cell-layer.wgsl.js.map +1 -0
  168. package/dist.webgl-only/hexagon-layer/hexagon-layer-uniforms.js +24 -0
  169. package/dist.webgl-only/hexagon-layer/hexagon-layer-uniforms.js.map +1 -0
  170. package/dist.webgl-only/hexagon-layer/hexagon-layer.js +360 -0
  171. package/dist.webgl-only/hexagon-layer/hexagon-layer.js.map +1 -0
  172. package/dist.webgl-only/hexagon-layer/hexbin.js +70 -0
  173. package/dist.webgl-only/hexagon-layer/hexbin.js.map +1 -0
  174. package/dist.webgl-only/index.cjs +15625 -0
  175. package/dist.webgl-only/index.cjs.map +6 -0
  176. package/dist.webgl-only/index.js +11 -0
  177. package/dist.webgl-only/index.js.map +1 -0
  178. package/dist.webgl-only/screen-grid-layer/bin-options-uniforms.js +16 -0
  179. package/dist.webgl-only/screen-grid-layer/bin-options-uniforms.js.map +1 -0
  180. package/dist.webgl-only/screen-grid-layer/screen-grid-cell-layer.js +88 -0
  181. package/dist.webgl-only/screen-grid-layer/screen-grid-cell-layer.js.map +1 -0
  182. package/dist.webgl-only/screen-grid-layer/screen-grid-cell-layer.wgsl.js +5 -0
  183. package/dist.webgl-only/screen-grid-layer/screen-grid-cell-layer.wgsl.js.map +1 -0
  184. package/dist.webgl-only/screen-grid-layer/screen-grid-layer-fragment.glsl.js +16 -0
  185. package/dist.webgl-only/screen-grid-layer/screen-grid-layer-fragment.glsl.js.map +1 -0
  186. package/dist.webgl-only/screen-grid-layer/screen-grid-layer-uniforms.js +22 -0
  187. package/dist.webgl-only/screen-grid-layer/screen-grid-layer-uniforms.js.map +1 -0
  188. package/dist.webgl-only/screen-grid-layer/screen-grid-layer-vertex.glsl.js +31 -0
  189. package/dist.webgl-only/screen-grid-layer/screen-grid-layer-vertex.glsl.js.map +1 -0
  190. package/dist.webgl-only/screen-grid-layer/screen-grid-layer.js +194 -0
  191. package/dist.webgl-only/screen-grid-layer/screen-grid-layer.js.map +1 -0
  192. package/package.json +14 -5
  193. package/src/common/aggregator/gpu-aggregator/webgl-aggregation-transform.ts +1 -3
  194. package/src/common/aggregator/gpu-aggregator/webgl-bin-sorter.ts +0 -1
  195. package/src/grid-layer/grid-cell-layer.ts +3 -2
  196. package/src/grid-layer/grid-cell-layer.wgsl.ts +114 -0
  197. package/src/grid-layer/grid-layer-uniforms.ts +15 -0
  198. package/src/heatmap-layer/heatmap-layer-uniforms.ts +20 -0
  199. package/src/heatmap-layer/heatmap-layer.ts +67 -13
  200. package/src/heatmap-layer/max.wgsl.ts +48 -0
  201. package/src/heatmap-layer/triangle-layer-uniforms.ts +17 -0
  202. package/src/heatmap-layer/triangle-layer.ts +3 -2
  203. package/src/heatmap-layer/triangle-layer.wgsl.ts +65 -0
  204. package/src/heatmap-layer/weights.wgsl.ts +64 -0
  205. package/src/hexagon-layer/hexagon-cell-layer.ts +2 -3
  206. package/src/hexagon-layer/hexagon-cell-layer.wgsl.ts +120 -0
  207. package/src/hexagon-layer/hexagon-layer-uniforms.ts +14 -0
  208. package/src/screen-grid-layer/screen-grid-cell-layer.ts +4 -4
  209. package/src/screen-grid-layer/screen-grid-cell-layer.wgsl.ts +76 -0
  210. package/src/screen-grid-layer/screen-grid-layer-uniforms.ts +13 -0
@@ -0,0 +1,360 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { log, createIterable, project32, Viewport } from '@deck.gl/core';
5
+ import { WebGLAggregator, CPUAggregator } from "../common/aggregator/index.js";
6
+ import AggregationLayer from "../common/aggregation-layer.js";
7
+ import { defaultColorRange } from "../common/utils/color-utils.js";
8
+ import { AttributeWithScale } from "../common/utils/scale-utils.js";
9
+ import { getBinIdRange } from "../common/utils/bounds-utils.js";
10
+ import HexagonCellLayer from "./hexagon-cell-layer.js";
11
+ import { pointToHexbin, HexbinVertices, getHexbinCentroid, pointToHexbinGLSL } from "./hexbin.js";
12
+ import { binOptionsUniforms } from "./bin-options-uniforms.js";
13
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
14
+ function noop() { }
15
+ const defaultProps = {
16
+ gpuAggregation: true,
17
+ // color
18
+ colorDomain: null,
19
+ colorRange: defaultColorRange,
20
+ getColorValue: { type: 'accessor', value: null }, // default value is calculated from `getColorWeight` and `colorAggregation`
21
+ getColorWeight: { type: 'accessor', value: 1 },
22
+ colorAggregation: 'SUM',
23
+ lowerPercentile: { type: 'number', min: 0, max: 100, value: 0 },
24
+ upperPercentile: { type: 'number', min: 0, max: 100, value: 100 },
25
+ colorScaleType: 'quantize',
26
+ onSetColorDomain: noop,
27
+ // elevation
28
+ elevationDomain: null,
29
+ elevationRange: [0, 1000],
30
+ getElevationValue: { type: 'accessor', value: null }, // default value is calculated from `getElevationWeight` and `elevationAggregation`
31
+ getElevationWeight: { type: 'accessor', value: 1 },
32
+ elevationAggregation: 'SUM',
33
+ elevationScale: { type: 'number', min: 0, value: 1 },
34
+ elevationLowerPercentile: { type: 'number', min: 0, max: 100, value: 0 },
35
+ elevationUpperPercentile: { type: 'number', min: 0, max: 100, value: 100 },
36
+ elevationScaleType: 'linear',
37
+ onSetElevationDomain: noop,
38
+ // hexbin
39
+ radius: { type: 'number', min: 1, value: 1000 },
40
+ coverage: { type: 'number', min: 0, max: 1, value: 1 },
41
+ getPosition: { type: 'accessor', value: (x) => x.position },
42
+ hexagonAggregator: { type: 'function', optional: true, value: null },
43
+ extruded: false,
44
+ // Optional material for 'lighting' shader module
45
+ material: true
46
+ };
47
+ /** Aggregate data into a grid-based heatmap. The color and height of a cell are determined based on the objects it contains. */
48
+ class HexagonLayer extends AggregationLayer {
49
+ getAggregatorType() {
50
+ const { gpuAggregation, hexagonAggregator, getColorValue, getElevationValue } = this.props;
51
+ if (gpuAggregation && (hexagonAggregator || getColorValue || getElevationValue)) {
52
+ // If these features are desired by the app, the user should explicitly use CPU aggregation
53
+ log.warn('Features not supported by GPU aggregation, falling back to CPU')();
54
+ return 'cpu';
55
+ }
56
+ if (
57
+ // GPU aggregation is requested
58
+ gpuAggregation &&
59
+ // GPU aggregation is supported by the device
60
+ WebGLAggregator.isSupported(this.context.device)) {
61
+ return 'gpu';
62
+ }
63
+ return 'cpu';
64
+ }
65
+ createAggregator(type) {
66
+ if (type === 'cpu') {
67
+ const { hexagonAggregator, radius } = this.props;
68
+ return new CPUAggregator({
69
+ dimensions: 2,
70
+ getBin: {
71
+ sources: ['positions'],
72
+ getValue: ({ positions }, index, opts) => {
73
+ if (hexagonAggregator) {
74
+ return hexagonAggregator(positions, radius);
75
+ }
76
+ const viewport = this.state.aggregatorViewport;
77
+ // project to common space
78
+ const p = viewport.projectPosition(positions);
79
+ const { radiusCommon, hexOriginCommon } = opts;
80
+ return pointToHexbin([p[0] - hexOriginCommon[0], p[1] - hexOriginCommon[1]], radiusCommon);
81
+ }
82
+ },
83
+ getValue: [
84
+ { sources: ['colorWeights'], getValue: ({ colorWeights }) => colorWeights },
85
+ { sources: ['elevationWeights'], getValue: ({ elevationWeights }) => elevationWeights }
86
+ ]
87
+ });
88
+ }
89
+ return new WebGLAggregator(this.context.device, {
90
+ dimensions: 2,
91
+ channelCount: 2,
92
+ bufferLayout: this.getAttributeManager().getBufferLayouts({ isInstanced: false }),
93
+ ...super.getShaders({
94
+ modules: [project32, binOptionsUniforms],
95
+ vs: /* glsl */ `
96
+ in vec3 positions;
97
+ in vec3 positions64Low;
98
+ in float colorWeights;
99
+ in float elevationWeights;
100
+
101
+ ${pointToHexbinGLSL}
102
+
103
+ void getBin(out ivec2 binId) {
104
+ vec3 positionCommon = project_position(positions, positions64Low);
105
+ binId = pointToHexbin(positionCommon.xy, binOptions.radiusCommon);
106
+ }
107
+ void getValue(out vec2 value) {
108
+ value = vec2(colorWeights, elevationWeights);
109
+ }
110
+ `
111
+ })
112
+ });
113
+ }
114
+ initializeState() {
115
+ super.initializeState();
116
+ const attributeManager = this.getAttributeManager();
117
+ attributeManager.add({
118
+ positions: {
119
+ size: 3,
120
+ accessor: 'getPosition',
121
+ type: 'float64',
122
+ fp64: this.use64bitPositions()
123
+ },
124
+ colorWeights: { size: 1, accessor: 'getColorWeight' },
125
+ elevationWeights: { size: 1, accessor: 'getElevationWeight' }
126
+ });
127
+ }
128
+ // eslint-disable-next-line complexity
129
+ updateState(params) {
130
+ const aggregatorChanged = super.updateState(params);
131
+ const { props, oldProps, changeFlags } = params;
132
+ const { aggregator } = this.state;
133
+ if ((changeFlags.dataChanged || !this.state.dataAsArray) &&
134
+ (props.getColorValue || props.getElevationValue)) {
135
+ // Convert data to array
136
+ this.state.dataAsArray = Array.from(createIterable(props.data).iterable);
137
+ }
138
+ if (aggregatorChanged ||
139
+ changeFlags.dataChanged ||
140
+ props.radius !== oldProps.radius ||
141
+ props.getColorValue !== oldProps.getColorValue ||
142
+ props.getElevationValue !== oldProps.getElevationValue ||
143
+ props.colorAggregation !== oldProps.colorAggregation ||
144
+ props.elevationAggregation !== oldProps.elevationAggregation) {
145
+ this._updateBinOptions();
146
+ const { radiusCommon, hexOriginCommon, binIdRange, dataAsArray } = this.state;
147
+ aggregator.setProps({
148
+ // @ts-expect-error only used by GPUAggregator
149
+ binIdRange,
150
+ pointCount: this.getNumInstances(),
151
+ operations: [props.colorAggregation, props.elevationAggregation],
152
+ binOptions: {
153
+ radiusCommon,
154
+ hexOriginCommon
155
+ },
156
+ onUpdate: this._onAggregationUpdate.bind(this)
157
+ });
158
+ if (dataAsArray) {
159
+ const { getColorValue, getElevationValue } = this.props;
160
+ aggregator.setProps({
161
+ // @ts-expect-error only used by CPUAggregator
162
+ customOperations: [
163
+ getColorValue &&
164
+ ((indices) => getColorValue(indices.map(i => dataAsArray[i]), { indices, data: props.data })),
165
+ getElevationValue &&
166
+ ((indices) => getElevationValue(indices.map(i => dataAsArray[i]), { indices, data: props.data }))
167
+ ]
168
+ });
169
+ }
170
+ }
171
+ if (changeFlags.updateTriggersChanged && changeFlags.updateTriggersChanged.getColorValue) {
172
+ aggregator.setNeedsUpdate(0);
173
+ }
174
+ if (changeFlags.updateTriggersChanged && changeFlags.updateTriggersChanged.getElevationValue) {
175
+ aggregator.setNeedsUpdate(1);
176
+ }
177
+ return aggregatorChanged;
178
+ }
179
+ _updateBinOptions() {
180
+ const bounds = this.getBounds();
181
+ let radiusCommon = 1;
182
+ let hexOriginCommon = [0, 0];
183
+ let binIdRange = [
184
+ [0, 1],
185
+ [0, 1]
186
+ ];
187
+ let viewport = this.context.viewport;
188
+ if (bounds && Number.isFinite(bounds[0][0])) {
189
+ let centroid = [(bounds[0][0] + bounds[1][0]) / 2, (bounds[0][1] + bounds[1][1]) / 2];
190
+ const { radius } = this.props;
191
+ const { unitsPerMeter } = viewport.getDistanceScales(centroid);
192
+ radiusCommon = unitsPerMeter[0] * radius;
193
+ // Use the centroid of the hex at the center of the data
194
+ // This offsets the common space without changing the bins
195
+ const centerHex = pointToHexbin(viewport.projectFlat(centroid), radiusCommon);
196
+ centroid = viewport.unprojectFlat(getHexbinCentroid(centerHex, radiusCommon));
197
+ const ViewportType = viewport.constructor;
198
+ // We construct a viewport for the GPU aggregator's project module
199
+ // This viewport is determined by data
200
+ // removes arbitrary precision variance that depends on initial view state
201
+ viewport = viewport.isGeospatial
202
+ ? new ViewportType({ longitude: centroid[0], latitude: centroid[1], zoom: 12 })
203
+ : new Viewport({ position: [centroid[0], centroid[1], 0], zoom: 12 });
204
+ hexOriginCommon = [Math.fround(viewport.center[0]), Math.fround(viewport.center[1])];
205
+ binIdRange = getBinIdRange({
206
+ dataBounds: bounds,
207
+ getBinId: (p) => {
208
+ const positionCommon = viewport.projectFlat(p);
209
+ positionCommon[0] -= hexOriginCommon[0];
210
+ positionCommon[1] -= hexOriginCommon[1];
211
+ return pointToHexbin(positionCommon, radiusCommon);
212
+ },
213
+ padding: 1
214
+ });
215
+ }
216
+ this.setState({ radiusCommon, hexOriginCommon, binIdRange, aggregatorViewport: viewport });
217
+ }
218
+ draw(opts) {
219
+ // Replaces render time viewport with our own
220
+ if (opts.shaderModuleProps.project) {
221
+ opts.shaderModuleProps.project.viewport = this.state.aggregatorViewport;
222
+ }
223
+ super.draw(opts);
224
+ }
225
+ _onAggregationUpdate({ channel }) {
226
+ const props = this.getCurrentLayer().props;
227
+ const { aggregator } = this.state;
228
+ if (channel === 0) {
229
+ const result = aggregator.getResult(0);
230
+ this.setState({
231
+ colors: new AttributeWithScale(result, aggregator.binCount)
232
+ });
233
+ props.onSetColorDomain(aggregator.getResultDomain(0));
234
+ }
235
+ else if (channel === 1) {
236
+ const result = aggregator.getResult(1);
237
+ this.setState({
238
+ elevations: new AttributeWithScale(result, aggregator.binCount)
239
+ });
240
+ props.onSetElevationDomain(aggregator.getResultDomain(1));
241
+ }
242
+ }
243
+ onAttributeChange(id) {
244
+ const { aggregator } = this.state;
245
+ switch (id) {
246
+ case 'positions':
247
+ aggregator.setNeedsUpdate();
248
+ this._updateBinOptions();
249
+ const { radiusCommon, hexOriginCommon, binIdRange } = this.state;
250
+ aggregator.setProps({
251
+ // @ts-expect-error only used by GPUAggregator
252
+ binIdRange,
253
+ binOptions: {
254
+ radiusCommon,
255
+ hexOriginCommon
256
+ }
257
+ });
258
+ break;
259
+ case 'colorWeights':
260
+ aggregator.setNeedsUpdate(0);
261
+ break;
262
+ case 'elevationWeights':
263
+ aggregator.setNeedsUpdate(1);
264
+ break;
265
+ default:
266
+ // This should not happen
267
+ }
268
+ }
269
+ renderLayers() {
270
+ const { aggregator, radiusCommon, hexOriginCommon } = this.state;
271
+ const { elevationScale, colorRange, elevationRange, extruded, coverage, material, transitions, colorScaleType, lowerPercentile, upperPercentile, colorDomain, elevationScaleType, elevationLowerPercentile, elevationUpperPercentile, elevationDomain } = this.props;
272
+ const CellLayerClass = this.getSubLayerClass('cells', HexagonCellLayer);
273
+ const binAttribute = aggregator.getBins();
274
+ const colors = this.state.colors?.update({
275
+ scaleType: colorScaleType,
276
+ lowerPercentile,
277
+ upperPercentile
278
+ });
279
+ const elevations = this.state.elevations?.update({
280
+ scaleType: elevationScaleType,
281
+ lowerPercentile: elevationLowerPercentile,
282
+ upperPercentile: elevationUpperPercentile
283
+ });
284
+ if (!colors || !elevations) {
285
+ return null;
286
+ }
287
+ return new CellLayerClass(this.getSubLayerProps({
288
+ id: 'cells'
289
+ }), {
290
+ data: {
291
+ length: aggregator.binCount,
292
+ attributes: {
293
+ getBin: binAttribute,
294
+ getColorValue: colors.attribute,
295
+ getElevationValue: elevations.attribute
296
+ }
297
+ },
298
+ // Data has changed shallowly, but we likely don't need to update the attributes
299
+ dataComparator: (data, oldData) => data.length === oldData.length,
300
+ updateTriggers: {
301
+ getBin: [binAttribute],
302
+ getColorValue: [colors.attribute],
303
+ getElevationValue: [elevations.attribute]
304
+ },
305
+ diskResolution: 6,
306
+ vertices: HexbinVertices,
307
+ radius: radiusCommon,
308
+ hexOriginCommon,
309
+ elevationScale,
310
+ colorRange,
311
+ colorScaleType,
312
+ elevationRange,
313
+ extruded,
314
+ coverage,
315
+ material,
316
+ colorDomain: colors.domain || colorDomain || aggregator.getResultDomain(0),
317
+ elevationDomain: elevations.domain || elevationDomain || aggregator.getResultDomain(1),
318
+ colorCutoff: colors.cutoff,
319
+ elevationCutoff: elevations.cutoff,
320
+ transitions: transitions && {
321
+ getFillColor: transitions.getColorValue || transitions.getColorWeight,
322
+ getElevation: transitions.getElevationValue || transitions.getElevationWeight
323
+ },
324
+ // Extensions are already handled by the GPUAggregator, do not pass it down
325
+ extensions: []
326
+ });
327
+ }
328
+ getPickingInfo(params) {
329
+ const info = params.info;
330
+ const { index } = info;
331
+ if (index >= 0) {
332
+ const bin = this.state.aggregator.getBin(index);
333
+ let object;
334
+ if (bin) {
335
+ const centroidCommon = getHexbinCentroid(bin.id, this.state.radiusCommon);
336
+ const centroid = this.context.viewport.unprojectFlat(centroidCommon);
337
+ object = {
338
+ col: bin.id[0],
339
+ row: bin.id[1],
340
+ position: centroid,
341
+ colorValue: bin.value[0],
342
+ elevationValue: bin.value[1],
343
+ count: bin.count
344
+ };
345
+ if (bin.pointIndices) {
346
+ object.pointIndices = bin.pointIndices;
347
+ object.points = Array.isArray(this.props.data)
348
+ ? bin.pointIndices.map(i => this.props.data[i])
349
+ : [];
350
+ }
351
+ }
352
+ info.object = object;
353
+ }
354
+ return info;
355
+ }
356
+ }
357
+ HexagonLayer.layerName = 'HexagonLayer';
358
+ HexagonLayer.defaultProps = defaultProps;
359
+ export default HexagonLayer;
360
+ //# sourceMappingURL=hexagon-layer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hexagon-layer.js","sourceRoot":"","sources":["../../src/hexagon-layer/hexagon-layer.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EACL,GAAG,EAKH,cAAc,EAGd,SAAS,EAIT,QAAQ,EAGT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,eAAe,EAAE,aAAa,EAAuB,sCAAmC;AAChG,OAAO,gBAAgB,uCAAoC;AAE3D,OAAO,EAAC,iBAAiB,EAAC,uCAAoC;AAC9D,OAAO,EAAC,kBAAkB,EAAC,uCAAoC;AAC/D,OAAO,EAAC,aAAa,EAAC,wCAAqC;AAE3D,OAAO,gBAAgB,gCAA6B;AACpD,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAC,oBAAiB;AAC7F,OAAO,EAAa,kBAAkB,EAAC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CAAC,CAAC,CAAC;oBACd,QAAQ,EAAE,QAAQ;oBAClB,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;oBACxB,cAAc,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;oBAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;iBACjB,CAAC;gBACF,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;oBACrB,MAAM,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC;oBACvC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;wBAC5C,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,IAAI,CAAC,KAAK,CAAC,IAAgB,CAAC,CAAC,CAAC,CAAC;wBAC5D,CAAC,CAAC,EAAE,CAAC;gBACT,CAAC;YACH,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;;AApYM,sBAAS,GAAG,cAAc,CAAC;AAC3B,yBAAY,GAAG,YAAY,CAAC;eALhB,YAAY"}
@@ -0,0 +1,70 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ const THIRD_PI = Math.PI / 3;
5
+ const DIST_X = 2 * Math.sin(THIRD_PI);
6
+ const DIST_Y = 1.5;
7
+ export const HexbinVertices = Array.from({ length: 6 }, (_, i) => {
8
+ const angle = i * THIRD_PI;
9
+ return [Math.sin(angle), -Math.cos(angle)];
10
+ });
11
+ /**
12
+ * Adapted from d3-hexbin
13
+ * Copyright Mike Bostock, 2012-2016
14
+ All rights reserved.
15
+ * https://github.com/d3/d3-hexbin/blob/master/src/hexbin.js
16
+ *
17
+ * Returns the hexbin that a point (x,y) falls into
18
+ */
19
+ export function pointToHexbin([px, py], radius) {
20
+ let pj = Math.round((py = py / radius / DIST_Y));
21
+ let pi = Math.round((px = px / radius / DIST_X - (pj & 1) / 2));
22
+ const py1 = py - pj;
23
+ if (Math.abs(py1) * 3 > 1) {
24
+ const px1 = px - pi;
25
+ const pi2 = pi + (px < pi ? -1 : 1) / 2;
26
+ const pj2 = pj + (py < pj ? -1 : 1);
27
+ const px2 = px - pi2;
28
+ const py2 = py - pj2;
29
+ if (px1 * px1 + py1 * py1 > px2 * px2 + py2 * py2) {
30
+ pi = pi2 + (pj & 1 ? 1 : -1) / 2;
31
+ pj = pj2;
32
+ }
33
+ }
34
+ return [pi, pj];
35
+ }
36
+ export const pointToHexbinGLSL = /* glsl */ `
37
+ const vec2 DIST = vec2(${DIST_X}, ${DIST_Y});
38
+
39
+ ivec2 pointToHexbin(vec2 p, float radius) {
40
+ p /= radius * DIST;
41
+ float pj = round(p.y);
42
+ float pjm2 = mod(pj, 2.0);
43
+ p.x -= pjm2 * 0.5;
44
+ float pi = round(p.x);
45
+ vec2 d1 = p - vec2(pi, pj);
46
+
47
+ if (abs(d1.y) * 3. > 1.) {
48
+ vec2 v2 = step(0.0, d1) - 0.5;
49
+ v2.y *= 2.0;
50
+ vec2 d2 = d1 - v2;
51
+ if (dot(d1, d1) > dot(d2, d2)) {
52
+ pi += v2.x + pjm2 - 0.5;
53
+ pj += v2.y;
54
+ }
55
+ }
56
+ return ivec2(pi, pj);
57
+ }
58
+ `;
59
+ export function getHexbinCentroid([i, j], radius) {
60
+ return [(i + (j & 1) / 2) * radius * DIST_X, j * radius * DIST_Y];
61
+ }
62
+ export const getHexbinCentroidGLSL = `
63
+ const vec2 DIST = vec2(${DIST_X}, ${DIST_Y});
64
+
65
+ vec2 hexbinCentroid(vec2 binId, float radius) {
66
+ binId.x += fract(binId.y * 0.5);
67
+ return binId * DIST * radius;
68
+ }
69
+ `;
70
+ //# sourceMappingURL=hexbin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hexbin.js","sourceRoot":"","sources":["../../src/hexagon-layer/h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