@deck.gl/aggregation-layers 8.8.0-beta.2 → 8.8.0-beta.5

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 (87) hide show
  1. package/dist/dist.dev.js +271 -261
  2. package/dist/es5/contour-layer/contour-layer.js.map +1 -1
  3. package/dist/es5/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  4. package/dist/es5/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  5. package/dist/es5/grid-layer/grid-layer.js.map +1 -1
  6. package/dist/es5/heatmap-layer/heatmap-layer.js +17 -12
  7. package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
  8. package/dist/es5/hexagon-layer/hexagon-layer.js.map +1 -1
  9. package/dist/es5/screen-grid-layer/screen-grid-layer.js.map +1 -1
  10. package/dist/esm/contour-layer/contour-layer.js.map +1 -1
  11. package/dist/esm/cpu-grid-layer/cpu-grid-layer.js.map +1 -1
  12. package/dist/esm/gpu-grid-layer/gpu-grid-layer.js.map +1 -1
  13. package/dist/esm/grid-layer/grid-layer.js.map +1 -1
  14. package/dist/esm/heatmap-layer/heatmap-layer.js +16 -12
  15. package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
  16. package/dist/esm/hexagon-layer/hexagon-layer.js.map +1 -1
  17. package/dist/esm/screen-grid-layer/screen-grid-layer.js.map +1 -1
  18. package/dist.min.js +1 -1
  19. package/package.json +2 -2
  20. package/src/contour-layer/contour-layer.ts +2 -0
  21. package/src/cpu-grid-layer/cpu-grid-layer.ts +1 -0
  22. package/src/gpu-grid-layer/gpu-grid-layer.ts +1 -3
  23. package/src/grid-layer/grid-layer.ts +1 -0
  24. package/src/heatmap-layer/heatmap-layer.ts +24 -12
  25. package/src/hexagon-layer/hexagon-layer.ts +1 -0
  26. package/src/screen-grid-layer/screen-grid-layer.ts +1 -0
  27. package/typed/contour-layer/contour-layer.d.ts +1 -0
  28. package/typed/contour-layer/contour-layer.d.ts.map +1 -1
  29. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts +1 -0
  30. package/typed/cpu-grid-layer/cpu-grid-layer.d.ts.map +1 -1
  31. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts +1 -3
  32. package/typed/gpu-grid-layer/gpu-grid-layer.d.ts.map +1 -1
  33. package/typed/grid-layer/grid-layer.d.ts +1 -0
  34. package/typed/grid-layer/grid-layer.d.ts.map +1 -1
  35. package/typed/heatmap-layer/heatmap-layer.d.ts +1 -0
  36. package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  37. package/typed/hexagon-layer/hexagon-layer.d.ts +1 -0
  38. package/typed/hexagon-layer/hexagon-layer.d.ts.map +1 -1
  39. package/typed/screen-grid-layer/screen-grid-layer.d.ts +1 -0
  40. package/typed/screen-grid-layer/screen-grid-layer.d.ts.map +1 -1
  41. package/typed/utils/bin-sorter.d.ts +1 -1
  42. package/typed/aggregation-layer.js +0 -151
  43. package/typed/contour-layer/contour-layer.js +0 -234
  44. package/typed/contour-layer/contour-utils.js +0 -64
  45. package/typed/contour-layer/marching-squares-codes.js +0 -337
  46. package/typed/contour-layer/marching-squares.js +0 -147
  47. package/typed/cpu-grid-layer/cpu-grid-layer.js +0 -129
  48. package/typed/cpu-grid-layer/grid-aggregator.js +0 -141
  49. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -34
  50. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -141
  51. package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +0 -143
  52. package/typed/gpu-grid-layer/gpu-grid-layer.js +0 -289
  53. package/typed/grid-aggregation-layer.js +0 -172
  54. package/typed/grid-layer/grid-layer.js +0 -60
  55. package/typed/heatmap-layer/heatmap-layer-utils.js +0 -78
  56. package/typed/heatmap-layer/heatmap-layer.js +0 -478
  57. package/typed/heatmap-layer/max-fs.glsl.js +0 -7
  58. package/typed/heatmap-layer/max-vs.glsl.js +0 -12
  59. package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +0 -58
  60. package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +0 -51
  61. package/typed/heatmap-layer/triangle-layer.js +0 -67
  62. package/typed/heatmap-layer/weights-fs.glsl.js +0 -19
  63. package/typed/heatmap-layer/weights-vs.glsl.js +0 -23
  64. package/typed/hexagon-layer/hexagon-aggregator.js +0 -112
  65. package/typed/hexagon-layer/hexagon-layer.js +0 -171
  66. package/typed/index.js +0 -33
  67. package/typed/screen-grid-layer/screen-grid-cell-layer.js +0 -159
  68. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +0 -37
  69. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +0 -83
  70. package/typed/screen-grid-layer/screen-grid-layer.js +0 -216
  71. package/typed/types.js +0 -1
  72. package/typed/utils/aggregation-operation-utils.js +0 -94
  73. package/typed/utils/bin-sorter.js +0 -167
  74. package/typed/utils/color-utils.js +0 -53
  75. package/typed/utils/cpu-aggregator.js +0 -417
  76. package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -39
  77. package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -53
  78. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -31
  79. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -77
  80. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
  81. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
  82. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -562
  83. package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -36
  84. package/typed/utils/grid-aggregation-utils.js +0 -114
  85. package/typed/utils/prop-utils.js +0 -28
  86. package/typed/utils/resource-utils.js +0 -40
  87. package/typed/utils/scale-utils.js +0 -184
@@ -1,78 +0,0 @@
1
- import GL from '@luma.gl/constants';
2
- import { isWebGL2 } from '@luma.gl/core';
3
- export function getBounds(points) {
4
- // Now build bounding box in world space (aligned to world coordiante system)
5
- const x = points.map(p => p[0]);
6
- const y = points.map(p => p[1]);
7
- const xMin = Math.min.apply(null, x);
8
- const xMax = Math.max.apply(null, x);
9
- const yMin = Math.min.apply(null, y);
10
- const yMax = Math.max.apply(null, y);
11
- return [xMin, yMin, xMax, yMax];
12
- }
13
- // true if currentBounds contains targetBounds, false otherwise
14
- export function boundsContain(currentBounds, targetBounds) {
15
- if (targetBounds[0] >= currentBounds[0] &&
16
- targetBounds[2] <= currentBounds[2] &&
17
- targetBounds[1] >= currentBounds[1] &&
18
- targetBounds[3] <= currentBounds[3]) {
19
- return true;
20
- }
21
- return false;
22
- }
23
- const scratchArray = new Float32Array(12);
24
- // For given rectangle bounds generates two triangles vertices that coverit completely
25
- export function packVertices(points, dimensions = 2) {
26
- let index = 0;
27
- for (const point of points) {
28
- for (let i = 0; i < dimensions; i++) {
29
- scratchArray[index++] = point[i] || 0;
30
- }
31
- }
32
- return scratchArray;
33
- }
34
- // Expands boundingBox:[xMin, yMin, xMax, yMax] to match aspect ratio of given width and height
35
- export function scaleToAspectRatio(boundingBox, width, height) {
36
- const [xMin, yMin, xMax, yMax] = boundingBox;
37
- const currentWidth = xMax - xMin;
38
- const currentHeight = yMax - yMin;
39
- let newWidth = currentWidth;
40
- let newHeight = currentHeight;
41
- if (currentWidth / currentHeight < width / height) {
42
- // expand bounding box width
43
- newWidth = (width / height) * currentHeight;
44
- }
45
- else {
46
- newHeight = (height / width) * currentWidth;
47
- }
48
- if (newWidth < width) {
49
- newWidth = width;
50
- newHeight = height;
51
- }
52
- const xCenter = (xMax + xMin) / 2;
53
- const yCenter = (yMax + yMin) / 2;
54
- return [
55
- xCenter - newWidth / 2,
56
- yCenter - newHeight / 2,
57
- xCenter + newWidth / 2,
58
- yCenter + newHeight / 2
59
- ];
60
- }
61
- // Get texture coordiante of point inside a bounding box
62
- export function getTextureCoordinates(point, bounds) {
63
- const [xMin, yMin, xMax, yMax] = bounds;
64
- return [(point[0] - xMin) / (xMax - xMin), (point[1] - yMin) / (yMax - yMin)];
65
- }
66
- // Returns format and type for creating texture objects
67
- export function getTextureParams({ gl, floatTargetSupport }) {
68
- return floatTargetSupport
69
- ? {
70
- // format: should be RGBA32F on WebGL2 (float textures), RGBA in WebGL1 for float or non float textures
71
- format: isWebGL2(gl) ? GL.RGBA32F : GL.RGBA,
72
- type: GL.FLOAT
73
- }
74
- : {
75
- format: GL.RGBA,
76
- type: GL.UNSIGNED_BYTE
77
- };
78
- }
@@ -1,478 +0,0 @@
1
- // Copyright (c) 2015 - 2019 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
- /* global setTimeout clearTimeout */
21
- import GL from '@luma.gl/constants';
22
- import { getBounds, boundsContain, packVertices, scaleToAspectRatio, getTextureCoordinates, getTextureParams } from './heatmap-layer-utils';
23
- import { Buffer, Texture2D, Transform, getParameters, FEATURES, hasFeatures } from '@luma.gl/core';
24
- import { AttributeManager, COORDINATE_SYSTEM, log } from '@deck.gl/core';
25
- import TriangleLayer from './triangle-layer';
26
- import AggregationLayer from '../aggregation-layer';
27
- import { defaultColorRange, colorRangeToFlatArray } from '../utils/color-utils';
28
- import weightsVs from './weights-vs.glsl';
29
- import weightsFs from './weights-fs.glsl';
30
- import vsMax from './max-vs.glsl';
31
- import fsMax from './max-fs.glsl';
32
- const RESOLUTION = 2; // (number of common space pixels) / (number texels)
33
- const TEXTURE_OPTIONS = {
34
- mipmaps: false,
35
- parameters: {
36
- [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
37
- [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
38
- [GL.TEXTURE_WRAP_S]: GL.CLAMP_TO_EDGE,
39
- [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
40
- },
41
- dataFormat: GL.RGBA
42
- };
43
- const DEFAULT_COLOR_DOMAIN = [0, 0];
44
- const AGGREGATION_MODE = {
45
- SUM: 0,
46
- MEAN: 1
47
- };
48
- const defaultProps = {
49
- getPosition: { type: 'accessor', value: x => x.position },
50
- getWeight: { type: 'accessor', value: 1 },
51
- intensity: { type: 'number', min: 0, value: 1 },
52
- radiusPixels: { type: 'number', min: 1, max: 100, value: 50 },
53
- colorRange: defaultColorRange,
54
- threshold: { type: 'number', min: 0, max: 1, value: 0.05 },
55
- colorDomain: { type: 'array', value: null, optional: true },
56
- // 'SUM' or 'MEAN'
57
- aggregation: 'SUM',
58
- weightsTextureSize: { type: 'number', min: 128, max: 2048, value: 2048 },
59
- debounceTimeout: { type: 'number', min: 0, max: 1000, value: 500 }
60
- };
61
- const REQUIRED_FEATURES = [
62
- FEATURES.BLEND_EQUATION_MINMAX,
63
- FEATURES.TEXTURE_FLOAT // weight-map as texture
64
- ];
65
- const FLOAT_TARGET_FEATURES = [
66
- FEATURES.COLOR_ATTACHMENT_RGBA32F,
67
- FEATURES.FLOAT_BLEND // ability to blend when rendering to float texture
68
- ];
69
- const DIMENSIONS = {
70
- data: {
71
- props: ['radiusPixels']
72
- }
73
- };
74
- export default class HeatmapLayer extends AggregationLayer {
75
- initializeState() {
76
- const { gl } = this.context;
77
- if (!hasFeatures(gl, REQUIRED_FEATURES)) {
78
- this.setState({ supported: false });
79
- log.error(`HeatmapLayer: ${this.id} is not supported on this browser`)();
80
- return;
81
- }
82
- super.initializeAggregationLayer(DIMENSIONS);
83
- this.setState({ supported: true, colorDomain: DEFAULT_COLOR_DOMAIN });
84
- this._setupTextureParams();
85
- this._setupAttributes();
86
- this._setupResources();
87
- }
88
- shouldUpdateState({ changeFlags }) {
89
- // Need to be updated when viewport changes
90
- return changeFlags.somethingChanged;
91
- }
92
- /* eslint-disable max-statements,complexity */
93
- updateState(opts) {
94
- if (!this.state.supported) {
95
- return;
96
- }
97
- super.updateState(opts);
98
- this._updateHeatmapState(opts);
99
- }
100
- _updateHeatmapState(opts) {
101
- const { props, oldProps } = opts;
102
- const changeFlags = this._getChangeFlags(opts);
103
- if (changeFlags.dataChanged || changeFlags.viewportChanged) {
104
- // if data is changed, do not debounce and immediately update the weight map
105
- changeFlags.boundsChanged = this._updateBounds(changeFlags.dataChanged);
106
- this._updateTextureRenderingBounds();
107
- }
108
- if (changeFlags.dataChanged || changeFlags.boundsChanged) {
109
- // Update weight map immediately
110
- clearTimeout(this.state.updateTimer);
111
- this.setState({ isWeightMapDirty: true });
112
- }
113
- else if (changeFlags.viewportZoomChanged) {
114
- // Update weight map when zoom stops
115
- this._debouncedUpdateWeightmap();
116
- }
117
- if (props.colorRange !== oldProps.colorRange) {
118
- this._updateColorTexture(opts);
119
- }
120
- if (this.state.isWeightMapDirty) {
121
- this._updateWeightmap();
122
- }
123
- this.setState({ zoom: opts.context.viewport.zoom });
124
- }
125
- renderLayers() {
126
- if (!this.state.supported) {
127
- return [];
128
- }
129
- const { weightsTexture, triPositionBuffer, triTexCoordBuffer, maxWeightsTexture, colorTexture, colorDomain } = this.state;
130
- const { updateTriggers, intensity, threshold, aggregation } = this.props;
131
- const TriangleLayerClass = this.getSubLayerClass('triangle', TriangleLayer);
132
- return new TriangleLayerClass(this.getSubLayerProps({
133
- id: 'triangle-layer',
134
- updateTriggers
135
- }), {
136
- // position buffer is filled with world coordinates generated from viewport.unproject
137
- // i.e. LNGLAT if geospatial, CARTESIAN otherwise
138
- coordinateSystem: COORDINATE_SYSTEM.DEFAULT,
139
- data: {
140
- attributes: {
141
- positions: triPositionBuffer,
142
- texCoords: triTexCoordBuffer
143
- }
144
- },
145
- vertexCount: 4,
146
- maxTexture: maxWeightsTexture,
147
- colorTexture,
148
- aggregationMode: AGGREGATION_MODE[aggregation] || 0,
149
- texture: weightsTexture,
150
- intensity,
151
- threshold,
152
- colorDomain
153
- });
154
- }
155
- finalizeState(context) {
156
- super.finalizeState(context);
157
- const { weightsTransform, weightsTexture, maxWeightTransform, maxWeightsTexture, triPositionBuffer, triTexCoordBuffer, colorTexture, updateTimer } = this.state;
158
- weightsTransform?.delete();
159
- weightsTexture?.delete();
160
- maxWeightTransform?.delete();
161
- maxWeightsTexture?.delete();
162
- triPositionBuffer?.delete();
163
- triTexCoordBuffer?.delete();
164
- colorTexture?.delete();
165
- if (updateTimer) {
166
- clearTimeout(updateTimer);
167
- }
168
- }
169
- // PRIVATE
170
- // override Composite layer private method to create AttributeManager instance
171
- _getAttributeManager() {
172
- return new AttributeManager(this.context.gl, {
173
- id: this.props.id,
174
- stats: this.context.stats
175
- });
176
- }
177
- _getChangeFlags(opts) {
178
- const changeFlags = {};
179
- const { dimensions } = this.state;
180
- changeFlags.dataChanged =
181
- this.isAttributeChanged() || // if any attribute is changed
182
- this.isAggregationDirty(opts, {
183
- compareAll: true,
184
- dimension: dimensions.data
185
- });
186
- changeFlags.viewportChanged = opts.changeFlags.viewportChanged;
187
- const { zoom } = this.state;
188
- if (!opts.context.viewport || opts.context.viewport.zoom !== zoom) {
189
- changeFlags.viewportZoomChanged = true;
190
- }
191
- return changeFlags;
192
- }
193
- _createTextures() {
194
- const { gl } = this.context;
195
- const { textureSize, format, type } = this.state;
196
- this.setState({
197
- weightsTexture: new Texture2D(gl, {
198
- width: textureSize,
199
- height: textureSize,
200
- format,
201
- type,
202
- ...TEXTURE_OPTIONS
203
- }),
204
- maxWeightsTexture: new Texture2D(gl, { format, type, ...TEXTURE_OPTIONS }) // 1 X 1 texture,
205
- });
206
- }
207
- _setupAttributes() {
208
- const attributeManager = this.getAttributeManager();
209
- attributeManager.add({
210
- positions: { size: 3, type: GL.DOUBLE, accessor: 'getPosition' },
211
- weights: { size: 1, accessor: 'getWeight' }
212
- });
213
- this.setState({ positionAttributeName: 'positions' });
214
- }
215
- _setupTextureParams() {
216
- const { gl } = this.context;
217
- const { weightsTextureSize } = this.props;
218
- const textureSize = Math.min(weightsTextureSize, getParameters(gl, gl.MAX_TEXTURE_SIZE));
219
- const floatTargetSupport = hasFeatures(gl, FLOAT_TARGET_FEATURES);
220
- const { format, type } = getTextureParams({ gl, floatTargetSupport });
221
- const weightsScale = floatTargetSupport ? 1 : 1 / 255;
222
- this.setState({ textureSize, format, type, weightsScale });
223
- if (!floatTargetSupport) {
224
- log.warn(`HeatmapLayer: ${this.id} rendering to float texture not supported, fallingback to low precession format`)();
225
- }
226
- }
227
- getShaders(type) {
228
- return super.getShaders(type === 'max-weights-transform'
229
- ? {
230
- vs: vsMax,
231
- _fs: fsMax
232
- }
233
- : {
234
- vs: weightsVs,
235
- _fs: weightsFs
236
- });
237
- }
238
- _createWeightsTransform(shaders = {}) {
239
- const { gl } = this.context;
240
- let { weightsTransform } = this.state;
241
- const { weightsTexture } = this.state;
242
- weightsTransform?.delete();
243
- weightsTransform = new Transform(gl, {
244
- id: `${this.id}-weights-transform`,
245
- elementCount: 1,
246
- _targetTexture: weightsTexture,
247
- _targetTextureVarying: 'weightsTexture',
248
- ...shaders
249
- });
250
- this.setState({ weightsTransform });
251
- }
252
- _setupResources() {
253
- const { gl } = this.context;
254
- this._createTextures();
255
- const { textureSize, weightsTexture, maxWeightsTexture } = this.state;
256
- const weightsTransformShaders = this.getShaders('weights-transform');
257
- this._createWeightsTransform(weightsTransformShaders);
258
- const maxWeightsTransformShaders = this.getShaders('max-weights-transform');
259
- const maxWeightTransform = new Transform(gl, {
260
- id: `${this.id}-max-weights-transform`,
261
- _sourceTextures: {
262
- inTexture: weightsTexture
263
- },
264
- _targetTexture: maxWeightsTexture,
265
- _targetTextureVarying: 'outTexture',
266
- ...maxWeightsTransformShaders,
267
- elementCount: textureSize * textureSize
268
- });
269
- this.setState({
270
- weightsTexture,
271
- maxWeightsTexture,
272
- maxWeightTransform,
273
- zoom: null,
274
- triPositionBuffer: new Buffer(gl, {
275
- byteLength: 48,
276
- accessor: { size: 3 }
277
- }),
278
- triTexCoordBuffer: new Buffer(gl, {
279
- byteLength: 48,
280
- accessor: { size: 2 }
281
- })
282
- });
283
- }
284
- // overwrite super class method to update transform model
285
- updateShaders(shaderOptions) {
286
- // sahder params (modules, injects) changed, update model object
287
- this._createWeightsTransform(shaderOptions);
288
- }
289
- _updateMaxWeightValue() {
290
- const { maxWeightTransform } = this.state;
291
- maxWeightTransform.run({
292
- parameters: {
293
- blend: true,
294
- depthTest: false,
295
- blendFunc: [GL.ONE, GL.ONE],
296
- blendEquation: GL.MAX
297
- }
298
- });
299
- }
300
- // Computes world bounds area that needs to be processed for generate heatmap
301
- _updateBounds(forceUpdate = false) {
302
- const { viewport } = this.context;
303
- // Unproject all 4 corners of the current screen coordinates into world coordinates (lng/lat)
304
- // Takes care of viewport has non zero bearing/pitch (i.e axis not aligned with world coordiante system)
305
- const viewportCorners = [
306
- viewport.unproject([0, 0]),
307
- viewport.unproject([viewport.width, 0]),
308
- viewport.unproject([viewport.width, viewport.height]),
309
- viewport.unproject([0, viewport.height])
310
- ].map(p => p.map(Math.fround));
311
- // #1: get world bounds for current viewport extends
312
- const visibleWorldBounds = getBounds(viewportCorners); // TODO: Change to visible bounds
313
- const newState = { visibleWorldBounds, viewportCorners };
314
- let boundsChanged = false;
315
- if (forceUpdate ||
316
- !this.state.worldBounds ||
317
- !boundsContain(this.state.worldBounds, visibleWorldBounds)) {
318
- // #2 : convert world bounds to common (Flat) bounds
319
- // #3 : extend common bounds to match aspect ratio with viewport
320
- const scaledCommonBounds = this._worldToCommonBounds(visibleWorldBounds);
321
- // #4 :convert aligned common bounds to world bounds
322
- const worldBounds = this._commonToWorldBounds(scaledCommonBounds);
323
- // Clip webmercator projection limits
324
- if (this.props.coordinateSystem === COORDINATE_SYSTEM.LNGLAT) {
325
- worldBounds[1] = Math.max(worldBounds[1], -85.051129);
326
- worldBounds[3] = Math.min(worldBounds[3], 85.051129);
327
- worldBounds[0] = Math.max(worldBounds[0], -360);
328
- worldBounds[2] = Math.min(worldBounds[2], 360);
329
- }
330
- // #5: now convert world bounds to common using Layer's coordiante system and origin
331
- const normalizedCommonBounds = this._worldToCommonBounds(worldBounds);
332
- newState.worldBounds = worldBounds;
333
- newState.normalizedCommonBounds = normalizedCommonBounds;
334
- boundsChanged = true;
335
- }
336
- this.setState(newState);
337
- return boundsChanged;
338
- }
339
- _updateTextureRenderingBounds() {
340
- // Just render visible portion of the texture
341
- const { triPositionBuffer, triTexCoordBuffer, normalizedCommonBounds, viewportCorners } = this.state;
342
- const { viewport } = this.context;
343
- triPositionBuffer.subData(packVertices(viewportCorners, 3));
344
- const textureBounds = viewportCorners.map(p => getTextureCoordinates(viewport.projectPosition(p), normalizedCommonBounds));
345
- triTexCoordBuffer.subData(packVertices(textureBounds, 2));
346
- }
347
- _updateColorTexture(opts) {
348
- const { colorRange } = opts.props;
349
- let { colorTexture } = this.state;
350
- const colors = colorRangeToFlatArray(colorRange, false, Uint8Array);
351
- if (colorTexture) {
352
- colorTexture.setImageData({
353
- data: colors,
354
- width: colorRange.length
355
- });
356
- }
357
- else {
358
- colorTexture = new Texture2D(this.context.gl, {
359
- data: colors,
360
- width: colorRange.length,
361
- height: 1,
362
- ...TEXTURE_OPTIONS
363
- });
364
- }
365
- this.setState({ colorTexture });
366
- }
367
- _updateWeightmap() {
368
- const { radiusPixels, colorDomain, aggregation } = this.props;
369
- const { weightsTransform, worldBounds, textureSize, weightsTexture, weightsScale } = this.state;
370
- this.state.isWeightMapDirty = false;
371
- // convert world bounds to common using Layer's coordiante system and origin
372
- const commonBounds = this._worldToCommonBounds(worldBounds, {
373
- useLayerCoordinateSystem: true
374
- });
375
- if (colorDomain && aggregation === 'SUM') {
376
- // scale color domain to weight per pixel
377
- const { viewport } = this.context;
378
- const metersPerPixel = (viewport.distanceScales.metersPerUnit[2] * (commonBounds[2] - commonBounds[0])) /
379
- textureSize;
380
- this.state.colorDomain = colorDomain.map(x => x * metersPerPixel * weightsScale);
381
- }
382
- else {
383
- this.state.colorDomain = colorDomain || DEFAULT_COLOR_DOMAIN;
384
- }
385
- const uniforms = {
386
- radiusPixels,
387
- commonBounds,
388
- textureWidth: textureSize,
389
- weightsScale
390
- };
391
- // Attribute manager sets data array count as instaceCount on model
392
- // we need to set that as elementCount on 'weightsTransform'
393
- weightsTransform.update({
394
- elementCount: this.getNumInstances()
395
- });
396
- weightsTransform.run({
397
- uniforms,
398
- parameters: {
399
- blend: true,
400
- depthTest: false,
401
- blendFunc: [GL.ONE, GL.ONE],
402
- blendEquation: GL.FUNC_ADD
403
- },
404
- clearRenderTarget: true,
405
- attributes: this.getAttributes(),
406
- moduleSettings: this.getModuleSettings()
407
- });
408
- this._updateMaxWeightValue();
409
- // reset filtering parameters (TODO: remove once luma issue#1193 is fixed)
410
- weightsTexture.setParameters({
411
- [GL.TEXTURE_MAG_FILTER]: GL.LINEAR,
412
- [GL.TEXTURE_MIN_FILTER]: GL.LINEAR
413
- });
414
- }
415
- _debouncedUpdateWeightmap(fromTimer = false) {
416
- let { updateTimer } = this.state;
417
- const { debounceTimeout } = this.props;
418
- if (fromTimer) {
419
- updateTimer = null;
420
- // update
421
- this._updateBounds(true);
422
- this._updateTextureRenderingBounds();
423
- this.setState({ isWeightMapDirty: true });
424
- }
425
- else {
426
- this.setState({ isWeightMapDirty: false });
427
- clearTimeout(updateTimer);
428
- updateTimer = setTimeout(this._debouncedUpdateWeightmap.bind(this, true), debounceTimeout);
429
- }
430
- this.setState({ updateTimer });
431
- }
432
- // input: worldBounds: [minLong, minLat, maxLong, maxLat]
433
- // input: opts.useLayerCoordinateSystem : layers coordiante system is used
434
- // optput: commonBounds: [minX, minY, maxX, maxY] scaled to fit the current texture
435
- _worldToCommonBounds(worldBounds, opts = {}) {
436
- const { useLayerCoordinateSystem = false } = opts;
437
- const [minLong, minLat, maxLong, maxLat] = worldBounds;
438
- const { viewport } = this.context;
439
- const { textureSize } = this.state;
440
- const { coordinateSystem } = this.props;
441
- const offsetMode = useLayerCoordinateSystem &&
442
- (coordinateSystem === COORDINATE_SYSTEM.LNGLAT_OFFSETS ||
443
- coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS);
444
- const offsetOriginCommon = offsetMode
445
- ? viewport.projectPosition(this.props.coordinateOrigin)
446
- : [0, 0];
447
- const size = (textureSize * RESOLUTION) / viewport.scale;
448
- let bottomLeftCommon;
449
- let topRightCommon;
450
- // Y-axis is flipped between World and Common bounds
451
- if (useLayerCoordinateSystem && !offsetMode) {
452
- bottomLeftCommon = this.projectPosition([minLong, minLat, 0]);
453
- topRightCommon = this.projectPosition([maxLong, maxLat, 0]);
454
- }
455
- else {
456
- bottomLeftCommon = viewport.projectPosition([minLong, minLat, 0]);
457
- topRightCommon = viewport.projectPosition([maxLong, maxLat, 0]);
458
- }
459
- // Ignore z component
460
- return scaleToAspectRatio([
461
- bottomLeftCommon[0] - offsetOriginCommon[0],
462
- bottomLeftCommon[1] - offsetOriginCommon[1],
463
- topRightCommon[0] - offsetOriginCommon[0],
464
- topRightCommon[1] - offsetOriginCommon[1]
465
- ], size, size);
466
- }
467
- // input commonBounds: [xMin, yMin, xMax, yMax]
468
- // output worldBounds: [minLong, minLat, maxLong, maxLat]
469
- _commonToWorldBounds(commonBounds) {
470
- const [xMin, yMin, xMax, yMax] = commonBounds;
471
- const { viewport } = this.context;
472
- const bottomLeftWorld = viewport.unprojectPosition([xMin, yMin]);
473
- const topRightWorld = viewport.unprojectPosition([xMax, yMax]);
474
- return bottomLeftWorld.slice(0, 2).concat(topRightWorld.slice(0, 2));
475
- }
476
- }
477
- HeatmapLayer.layerName = 'HeatmapLayer';
478
- HeatmapLayer.defaultProps = defaultProps;
@@ -1,7 +0,0 @@
1
- export default `\
2
- varying vec4 outTexture;
3
- void main() {
4
- gl_FragColor = outTexture;
5
- gl_FragColor.g = outTexture.r / max(1.0, outTexture.a);
6
- }
7
- `;
@@ -1,12 +0,0 @@
1
- export default `\
2
- attribute vec4 inTexture;
3
- varying vec4 outTexture;
4
-
5
- void main()
6
- {
7
- outTexture = inTexture;
8
- gl_Position = vec4(0, 0, 0, 1.);
9
- // Enforce default value for ANGLE issue (https://bugs.chromium.org/p/angleproject/issues/detail?id=3941)
10
- gl_PointSize = 1.0;
11
- }
12
- `;
@@ -1,58 +0,0 @@
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
- export default `\
21
- #define SHADER_NAME triangle-layer-fragment-shader
22
-
23
- precision highp float;
24
-
25
- uniform float opacity;
26
- uniform sampler2D texture;
27
- uniform sampler2D colorTexture;
28
- uniform float aggregationMode;
29
-
30
- varying vec2 vTexCoords;
31
- varying float vIntensityMin;
32
- varying float vIntensityMax;
33
-
34
- vec4 getLinearColor(float value) {
35
- float factor = clamp(value * vIntensityMax, 0., 1.);
36
- vec4 color = texture2D(colorTexture, vec2(factor, 0.5));
37
- color.a *= min(value * vIntensityMin, 1.0);
38
- return color;
39
- }
40
-
41
- void main(void) {
42
- vec4 weights = texture2D(texture, vTexCoords);
43
- float weight = weights.r;
44
-
45
- if (aggregationMode > 0.5) {
46
- weight /= max(1.0, weights.a);
47
- }
48
-
49
- // discard pixels with 0 weight.
50
- if (weight <= 0.) {
51
- discard;
52
- }
53
-
54
- vec4 linearColor = getLinearColor(weight);
55
- linearColor.a *= opacity;
56
- gl_FragColor =linearColor;
57
- }
58
- `;
@@ -1,51 +0,0 @@
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
- // Inspired by screen-grid-layer vertex shader in deck.gl
21
- export default `\
22
- #define SHADER_NAME heatp-map-layer-vertex-shader
23
-
24
- uniform sampler2D maxTexture;
25
- uniform float intensity;
26
- uniform vec2 colorDomain;
27
- uniform float threshold;
28
- uniform float aggregationMode;
29
-
30
- attribute vec3 positions;
31
- attribute vec2 texCoords;
32
-
33
- varying vec2 vTexCoords;
34
- varying float vIntensityMin;
35
- varying float vIntensityMax;
36
-
37
- void main(void) {
38
- gl_Position = project_position_to_clipspace(positions, vec3(0.0), vec3(0.0));
39
- vTexCoords = texCoords;
40
- vec4 maxTexture = texture2D(maxTexture, vec2(0.5));
41
- float maxValue = aggregationMode < 0.5 ? maxTexture.r : maxTexture.g;
42
- float minValue = maxValue * threshold;
43
- if (colorDomain[1] > 0.) {
44
- // if user specified custom domain use it.
45
- maxValue = colorDomain[1];
46
- minValue = colorDomain[0];
47
- }
48
- vIntensityMax = intensity / maxValue;
49
- vIntensityMin = intensity / minValue;
50
- }
51
- `;