@deck.gl/aggregation-layers 8.9.6 → 8.9.8

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 (51) hide show
  1. package/package.json +2 -2
  2. package/typed/heatmap-layer/heatmap-layer.orig.d.ts +116 -0
  3. package/typed/heatmap-layer/heatmap-layer.orig.d.ts.map +1 -0
  4. package/typed/heatmap-layer/heatmap-layer.patched.d.ts +116 -0
  5. package/typed/heatmap-layer/heatmap-layer.patched.d.ts.map +1 -0
  6. package/typed/aggregation-layer.js +0 -151
  7. package/typed/contour-layer/contour-layer.js +0 -234
  8. package/typed/contour-layer/contour-utils.js +0 -64
  9. package/typed/contour-layer/marching-squares-codes.js +0 -337
  10. package/typed/contour-layer/marching-squares.js +0 -147
  11. package/typed/cpu-grid-layer/cpu-grid-layer.js +0 -129
  12. package/typed/cpu-grid-layer/grid-aggregator.js +0 -141
  13. package/typed/gpu-grid-layer/gpu-grid-cell-layer-fragment.glsl.js +0 -34
  14. package/typed/gpu-grid-layer/gpu-grid-cell-layer-vertex.glsl.js +0 -141
  15. package/typed/gpu-grid-layer/gpu-grid-cell-layer.js +0 -143
  16. package/typed/gpu-grid-layer/gpu-grid-layer.js +0 -289
  17. package/typed/grid-aggregation-layer.js +0 -172
  18. package/typed/grid-layer/grid-layer.js +0 -60
  19. package/typed/heatmap-layer/heatmap-layer-utils.js +0 -78
  20. package/typed/heatmap-layer/heatmap-layer.js +0 -478
  21. package/typed/heatmap-layer/max-fs.glsl.js +0 -7
  22. package/typed/heatmap-layer/max-vs.glsl.js +0 -12
  23. package/typed/heatmap-layer/triangle-layer-fragment.glsl.js +0 -58
  24. package/typed/heatmap-layer/triangle-layer-vertex.glsl.js +0 -51
  25. package/typed/heatmap-layer/triangle-layer.js +0 -67
  26. package/typed/heatmap-layer/weights-fs.glsl.js +0 -19
  27. package/typed/heatmap-layer/weights-vs.glsl.js +0 -23
  28. package/typed/hexagon-layer/hexagon-aggregator.js +0 -112
  29. package/typed/hexagon-layer/hexagon-layer.js +0 -171
  30. package/typed/index.js +0 -33
  31. package/typed/screen-grid-layer/screen-grid-cell-layer.js +0 -159
  32. package/typed/screen-grid-layer/screen-grid-layer-fragment.glsl.js +0 -37
  33. package/typed/screen-grid-layer/screen-grid-layer-vertex.glsl.js +0 -83
  34. package/typed/screen-grid-layer/screen-grid-layer.js +0 -216
  35. package/typed/types.js +0 -1
  36. package/typed/utils/aggregation-operation-utils.js +0 -94
  37. package/typed/utils/bin-sorter.js +0 -167
  38. package/typed/utils/color-utils.js +0 -53
  39. package/typed/utils/cpu-aggregator.js +0 -417
  40. package/typed/utils/gpu-grid-aggregation/aggregate-all-fs.glsl.js +0 -39
  41. package/typed/utils/gpu-grid-aggregation/aggregate-all-vs.glsl.js +0 -53
  42. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-fs.glsl.js +0 -31
  43. package/typed/utils/gpu-grid-aggregation/aggregate-to-grid-vs.glsl.js +0 -77
  44. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-constants.js +0 -41
  45. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator-utils.js +0 -1
  46. package/typed/utils/gpu-grid-aggregation/gpu-grid-aggregator.js +0 -562
  47. package/typed/utils/gpu-grid-aggregation/transform-mean-vs.glsl.js +0 -36
  48. package/typed/utils/grid-aggregation-utils.js +0 -114
  49. package/typed/utils/prop-utils.js +0 -28
  50. package/typed/utils/resource-utils.js +0 -40
  51. package/typed/utils/scale-utils.js +0 -184
@@ -1,19 +0,0 @@
1
- export default `\
2
- varying vec4 weightsTexture;
3
- // Epanechnikov function, keeping for reference
4
- // float epanechnikovKDE(float u) {
5
- // return 0.75 * (1.0 - u * u);
6
- // }
7
- float gaussianKDE(float u){
8
- return pow(2.71828, -u*u/0.05555)/(1.77245385*0.166666);
9
- }
10
- void main()
11
- {
12
- float dist = length(gl_PointCoord - vec2(0.5, 0.5));
13
- if (dist > 0.5) {
14
- discard;
15
- }
16
- gl_FragColor = weightsTexture * gaussianKDE(2. * dist);
17
- DECKGL_FILTER_COLOR(gl_FragColor, geometry);
18
- }
19
- `;
@@ -1,23 +0,0 @@
1
- export default `\
2
- attribute vec3 positions;
3
- attribute vec3 positions64Low;
4
- attribute float weights;
5
- varying vec4 weightsTexture;
6
- uniform float radiusPixels;
7
- uniform float textureWidth;
8
- uniform vec4 commonBounds;
9
- uniform float weightsScale;
10
- void main()
11
- {
12
- weightsTexture = vec4(weights * weightsScale, 0., 0., 1.);
13
-
14
- float radiusTexels = project_pixel_size(radiusPixels) * textureWidth / (commonBounds.z - commonBounds.x);
15
- gl_PointSize = radiusTexels * 2.;
16
-
17
- vec3 commonPosition = project_position(positions, positions64Low);
18
-
19
- // map xy from commonBounds to [-1, 1]
20
- gl_Position.xy = (commonPosition.xy - commonBounds.xy) / (commonBounds.zw - commonBounds.xy) ;
21
- gl_Position.xy = (gl_Position.xy * 2.) - (1.);
22
- }
23
- `;
@@ -1,112 +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
- import { hexbin } from 'd3-hexbin';
21
- import { createIterable, log } from '@deck.gl/core';
22
- /**
23
- * Use d3-hexbin to performs hexagonal binning from geo points to hexagons
24
- * @param {Iterable} data - array of points
25
- * @param {Number} radius - hexagon radius in meter
26
- * @param {function} getPosition - get points lon lat
27
- * @param {Object} viewport - current viewport object
28
-
29
- * @return {Object} - hexagons and countRange
30
- */
31
- export function pointToHexbin(props, aggregationParams) {
32
- const { data, radius } = props;
33
- const { viewport, attributes } = aggregationParams;
34
- // get hexagon radius in mercator world unit
35
- const centerLngLat = data.length ? getPointsCenter(data, aggregationParams) : null;
36
- const radiusCommon = getRadiusInCommon(radius, viewport, centerLngLat);
37
- // add world space coordinates to points
38
- const screenPoints = [];
39
- const { iterable, objectInfo } = createIterable(data);
40
- const positions = attributes.positions.value;
41
- const { size } = attributes.positions.getAccessor();
42
- for (const object of iterable) {
43
- objectInfo.index++;
44
- const posIndex = objectInfo.index * size;
45
- const position = [positions[posIndex], positions[posIndex + 1]];
46
- const arrayIsFinite = Number.isFinite(position[0]) && Number.isFinite(position[1]);
47
- if (arrayIsFinite) {
48
- screenPoints.push({
49
- screenCoord: viewport.projectFlat(position),
50
- source: object,
51
- index: objectInfo.index
52
- });
53
- }
54
- else {
55
- log.warn('HexagonLayer: invalid position')();
56
- }
57
- }
58
- const newHexbin = hexbin()
59
- .radius(radiusCommon)
60
- .x(d => d.screenCoord[0])
61
- .y(d => d.screenCoord[1]);
62
- const hexagonBins = newHexbin(screenPoints);
63
- return {
64
- hexagons: hexagonBins.map((hex, index) => ({
65
- position: viewport.unprojectFlat([hex.x, hex.y]),
66
- points: hex,
67
- index
68
- })),
69
- radiusCommon
70
- };
71
- }
72
- /**
73
- * Get the bounding box of all data points
74
- */
75
- export function getPointsCenter(data, aggregationParams) {
76
- const { attributes } = aggregationParams;
77
- const positions = attributes.positions.value;
78
- const { size } = attributes.positions.getAccessor();
79
- let minX = Infinity;
80
- let minY = Infinity;
81
- let maxX = -Infinity;
82
- let maxY = -Infinity;
83
- let i;
84
- for (i = 0; i < size * data.length; i += size) {
85
- const x = positions[i];
86
- const y = positions[i + 1];
87
- const arrayIsFinite = Number.isFinite(x) && Number.isFinite(y);
88
- if (arrayIsFinite) {
89
- minX = Math.min(x, minX);
90
- maxX = Math.max(x, maxX);
91
- minY = Math.min(y, minY);
92
- maxY = Math.max(y, maxY);
93
- }
94
- }
95
- // return center
96
- return [minX, minY, maxX, maxY].every(Number.isFinite)
97
- ? [(minX + maxX) / 2, (minY + maxY) / 2]
98
- : null;
99
- }
100
- /**
101
- * Get radius in mercator world space coordinates from meter
102
- * @param {Number} radius - in meter
103
- * @param {Object} viewport - current viewport object
104
- * @param {Array<Number>} center - data center
105
-
106
- * @return {Number} radius in mercator world spcae coordinates
107
- */
108
- export function getRadiusInCommon(radius, viewport, center) {
109
- const { unitsPerMeter } = viewport.getDistanceScales(center);
110
- // x, y distance should be the same
111
- return radius * unitsPerMeter[0];
112
- }
@@ -1,171 +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
- import { log } from '@deck.gl/core';
21
- import { ColumnLayer } from '@deck.gl/layers';
22
- import { defaultColorRange } from '../utils/color-utils';
23
- import { pointToHexbin } from './hexagon-aggregator';
24
- import CPUAggregator from '../utils/cpu-aggregator';
25
- import AggregationLayer from '../aggregation-layer';
26
- import GL from '@luma.gl/constants';
27
- // eslint-disable-next-line @typescript-eslint/no-empty-function
28
- function nop() { }
29
- const defaultProps = {
30
- // color
31
- colorDomain: null,
32
- colorRange: defaultColorRange,
33
- getColorValue: { type: 'accessor', value: null },
34
- getColorWeight: { type: 'accessor', value: 1 },
35
- colorAggregation: 'SUM',
36
- lowerPercentile: { type: 'number', value: 0, min: 0, max: 100 },
37
- upperPercentile: { type: 'number', value: 100, min: 0, max: 100 },
38
- colorScaleType: 'quantize',
39
- onSetColorDomain: nop,
40
- // elevation
41
- elevationDomain: null,
42
- elevationRange: [0, 1000],
43
- getElevationValue: { type: 'accessor', value: null },
44
- getElevationWeight: { type: 'accessor', value: 1 },
45
- elevationAggregation: 'SUM',
46
- elevationLowerPercentile: { type: 'number', value: 0, min: 0, max: 100 },
47
- elevationUpperPercentile: { type: 'number', value: 100, min: 0, max: 100 },
48
- elevationScale: { type: 'number', min: 0, value: 1 },
49
- elevationScaleType: 'linear',
50
- onSetElevationDomain: nop,
51
- radius: { type: 'number', value: 1000, min: 1 },
52
- coverage: { type: 'number', min: 0, max: 1, value: 1 },
53
- extruded: false,
54
- hexagonAggregator: pointToHexbin,
55
- getPosition: { type: 'accessor', value: x => x.position },
56
- // Optional material for 'lighting' shader module
57
- material: true,
58
- // data filter
59
- _filterData: { type: 'function', value: null, optional: true }
60
- };
61
- export default class HexagonLayer extends AggregationLayer {
62
- initializeState() {
63
- const cpuAggregator = new CPUAggregator({
64
- getAggregator: props => props.hexagonAggregator,
65
- getCellSize: props => props.radius
66
- });
67
- this.state = {
68
- cpuAggregator,
69
- aggregatorState: cpuAggregator.state,
70
- vertices: null
71
- };
72
- const attributeManager = this.getAttributeManager();
73
- attributeManager.add({
74
- positions: { size: 3, type: GL.DOUBLE, accessor: 'getPosition' }
75
- });
76
- // color and elevation attributes can't be added as attributes
77
- // they are calculated using 'getValue' accessor that takes an array of pints.
78
- }
79
- updateState(opts) {
80
- super.updateState(opts);
81
- if (opts.changeFlags.propsOrDataChanged) {
82
- const aggregatorState = this.state.cpuAggregator.updateState(opts, {
83
- viewport: this.context.viewport,
84
- attributes: this.getAttributes()
85
- });
86
- if (this.state.aggregatorState.layerData !== aggregatorState.layerData) {
87
- // if user provided custom aggregator and returns hexagonVertices,
88
- // Need to recalculate radius and angle based on vertices
89
- const { hexagonVertices } = aggregatorState.layerData || {};
90
- this.setState({
91
- vertices: hexagonVertices && this.convertLatLngToMeterOffset(hexagonVertices)
92
- });
93
- }
94
- this.setState({
95
- // make a copy of the internal state of cpuAggregator for testing
96
- aggregatorState
97
- });
98
- }
99
- }
100
- convertLatLngToMeterOffset(hexagonVertices) {
101
- const { viewport } = this.context;
102
- if (Array.isArray(hexagonVertices) && hexagonVertices.length === 6) {
103
- // get centroid of hexagons
104
- const vertex0 = hexagonVertices[0];
105
- const vertex3 = hexagonVertices[3];
106
- const centroid = [(vertex0[0] + vertex3[0]) / 2, (vertex0[1] + vertex3[1]) / 2];
107
- const centroidFlat = viewport.projectFlat(centroid);
108
- const { metersPerUnit } = viewport.getDistanceScales(centroid);
109
- // offset all points by centroid to meter offset
110
- const vertices = hexagonVertices.map(vt => {
111
- const vtFlat = viewport.projectFlat(vt);
112
- return [
113
- (vtFlat[0] - centroidFlat[0]) * metersPerUnit[0],
114
- (vtFlat[1] - centroidFlat[1]) * metersPerUnit[1]
115
- ];
116
- });
117
- return vertices;
118
- }
119
- log.error('HexagonLayer: hexagonVertices needs to be an array of 6 points')();
120
- return null;
121
- }
122
- getPickingInfo({ info }) {
123
- return this.state.cpuAggregator.getPickingInfo({ info });
124
- }
125
- // create a method for testing
126
- _onGetSublayerColor(cell) {
127
- return this.state.cpuAggregator.getAccessor('fillColor')(cell);
128
- }
129
- // create a method for testing
130
- _onGetSublayerElevation(cell) {
131
- return this.state.cpuAggregator.getAccessor('elevation')(cell);
132
- }
133
- _getSublayerUpdateTriggers() {
134
- return this.state.cpuAggregator.getUpdateTriggers(this.props);
135
- }
136
- renderLayers() {
137
- const { elevationScale, extruded, coverage, material, transitions } = this.props;
138
- const { aggregatorState, vertices } = this.state;
139
- const SubLayerClass = this.getSubLayerClass('hexagon-cell', ColumnLayer);
140
- const updateTriggers = this._getSublayerUpdateTriggers();
141
- const geometry = vertices
142
- ? { vertices, radius: 1 }
143
- : {
144
- // default geometry
145
- radius: aggregatorState.layerData.radiusCommon || 1,
146
- radiusUnits: 'common',
147
- angle: 90
148
- };
149
- return new SubLayerClass({
150
- ...geometry,
151
- diskResolution: 6,
152
- elevationScale,
153
- extruded,
154
- coverage,
155
- material,
156
- getFillColor: this._onGetSublayerColor.bind(this),
157
- getElevation: this._onGetSublayerElevation.bind(this),
158
- transitions: transitions && {
159
- getFillColor: transitions.getColorValue || transitions.getColorWeight,
160
- getElevation: transitions.getElevationValue || transitions.getElevationWeight
161
- }
162
- }, this.getSubLayerProps({
163
- id: 'hexagon-cell',
164
- updateTriggers
165
- }), {
166
- data: aggregatorState.layerData.data
167
- });
168
- }
169
- }
170
- HexagonLayer.layerName = 'HexagonLayer';
171
- HexagonLayer.defaultProps = defaultProps;
package/typed/index.js DELETED
@@ -1,33 +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
- /* eslint-disable max-len */
21
- export { default as ScreenGridLayer } from './screen-grid-layer/screen-grid-layer';
22
- export { default as CPUGridLayer } from './cpu-grid-layer/cpu-grid-layer';
23
- export { default as HexagonLayer } from './hexagon-layer/hexagon-layer';
24
- export { default as ContourLayer } from './contour-layer/contour-layer';
25
- export { default as GridLayer } from './grid-layer/grid-layer';
26
- export { default as GPUGridLayer } from './gpu-grid-layer/gpu-grid-layer';
27
- export { AGGREGATION_OPERATION } from './utils/aggregation-operation-utils';
28
- // experimental export
29
- export { default as HeatmapLayer } from './heatmap-layer/heatmap-layer';
30
- export { default as _GPUGridAggregator } from './utils/gpu-grid-aggregation/gpu-grid-aggregator';
31
- export { default as _CPUAggregator } from './utils/cpu-aggregator';
32
- export { default as _AggregationLayer } from './aggregation-layer';
33
- export { default as _BinSorter } from './utils/bin-sorter';
@@ -1,159 +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
- import GL from '@luma.gl/constants';
21
- import { Model, Geometry, FEATURES, hasFeatures } from '@luma.gl/core';
22
- import { Layer, log, picking } from '@deck.gl/core';
23
- import { defaultColorRange, colorRangeToFlatArray } from '../utils/color-utils';
24
- import vs from './screen-grid-layer-vertex.glsl';
25
- import fs from './screen-grid-layer-fragment.glsl';
26
- const DEFAULT_MINCOLOR = [0, 0, 0, 0];
27
- const DEFAULT_MAXCOLOR = [0, 255, 0, 255];
28
- const COLOR_PROPS = ['minColor', 'maxColor', 'colorRange', 'colorDomain'];
29
- const defaultProps = {
30
- cellSizePixels: { value: 100, min: 1 },
31
- cellMarginPixels: { value: 2, min: 0, max: 5 },
32
- colorDomain: null,
33
- colorRange: defaultColorRange
34
- };
35
- export default class ScreenGridCellLayer extends Layer {
36
- static isSupported(gl) {
37
- return hasFeatures(gl, [FEATURES.TEXTURE_FLOAT]);
38
- }
39
- getShaders() {
40
- return { vs, fs, modules: [picking] };
41
- }
42
- initializeState() {
43
- const { gl } = this.context;
44
- const attributeManager = this.getAttributeManager();
45
- attributeManager.addInstanced({
46
- // eslint-disable-next-line @typescript-eslint/unbound-method
47
- instancePositions: { size: 3, update: this.calculateInstancePositions },
48
- instanceCounts: { size: 4, noAlloc: true }
49
- });
50
- this.setState({
51
- model: this._getModel(gl)
52
- });
53
- }
54
- shouldUpdateState({ changeFlags }) {
55
- // 'instanceCounts' buffer contetns change on viewport change.
56
- return changeFlags.somethingChanged;
57
- }
58
- updateState(params) {
59
- super.updateState(params);
60
- const { oldProps, props, changeFlags } = params;
61
- const attributeManager = this.getAttributeManager();
62
- if (props.numInstances !== oldProps.numInstances) {
63
- attributeManager.invalidateAll();
64
- }
65
- else if (oldProps.cellSizePixels !== props.cellSizePixels) {
66
- attributeManager.invalidate('instancePositions');
67
- }
68
- this._updateUniforms(oldProps, props, changeFlags);
69
- }
70
- draw({ uniforms }) {
71
- const { parameters, maxTexture } = this.props;
72
- const minColor = this.props.minColor || DEFAULT_MINCOLOR;
73
- const maxColor = this.props.maxColor || DEFAULT_MAXCOLOR;
74
- // If colorDomain not specified we use default domain [1, maxCount]
75
- // maxCount value will be sampled form maxTexture in vertex shader.
76
- const colorDomain = this.props.colorDomain || [1, 0];
77
- const { model } = this.state;
78
- model
79
- .setUniforms(uniforms)
80
- .setUniforms({
81
- minColor,
82
- maxColor,
83
- maxTexture,
84
- colorDomain
85
- })
86
- .draw({
87
- parameters: {
88
- depthTest: false,
89
- depthMask: false,
90
- ...parameters
91
- }
92
- });
93
- }
94
- calculateInstancePositions(attribute, { numInstances }) {
95
- const { width, height } = this.context.viewport;
96
- const { cellSizePixels } = this.props;
97
- const numCol = Math.ceil(width / cellSizePixels);
98
- const { value, size } = attribute;
99
- for (let i = 0; i < numInstances; i++) {
100
- const x = i % numCol;
101
- const y = Math.floor(i / numCol);
102
- value[i * size + 0] = ((x * cellSizePixels) / width) * 2 - 1;
103
- value[i * size + 1] = 1 - ((y * cellSizePixels) / height) * 2;
104
- value[i * size + 2] = 0;
105
- }
106
- }
107
- // Private Methods
108
- _getModel(gl) {
109
- return new Model(gl, {
110
- ...this.getShaders(),
111
- id: this.props.id,
112
- geometry: new Geometry({
113
- drawMode: GL.TRIANGLE_FAN,
114
- attributes: {
115
- positions: new Float32Array([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0])
116
- }
117
- }),
118
- isInstanced: true
119
- });
120
- }
121
- _shouldUseMinMax() {
122
- const { minColor, maxColor, colorDomain, colorRange } = this.props;
123
- if (minColor || maxColor) {
124
- log.deprecated('ScreenGridLayer props: minColor and maxColor', 'colorRange, colorDomain')();
125
- return true;
126
- }
127
- // minColor and maxColor not supplied, check if colorRange or colorDomain supplied.
128
- // NOTE: colorDomain and colorRange are experimental features, use them only when supplied.
129
- if (colorDomain || colorRange) {
130
- return false;
131
- }
132
- // None specified, use default minColor and maxColor
133
- return true;
134
- }
135
- _updateUniforms(oldProps, props, changeFlags) {
136
- const { model } = this.state;
137
- if (COLOR_PROPS.some(key => oldProps[key] !== props[key])) {
138
- model.setUniforms({ shouldUseMinMax: this._shouldUseMinMax() });
139
- }
140
- if (oldProps.colorRange !== props.colorRange) {
141
- model.setUniforms({ colorRange: colorRangeToFlatArray(props.colorRange) });
142
- }
143
- if (oldProps.cellMarginPixels !== props.cellMarginPixels ||
144
- oldProps.cellSizePixels !== props.cellSizePixels ||
145
- changeFlags.viewportChanged) {
146
- const { width, height } = this.context.viewport;
147
- const { cellSizePixels, cellMarginPixels } = this.props;
148
- const margin = cellSizePixels > cellMarginPixels ? cellMarginPixels : 0;
149
- const cellScale = new Float32Array([
150
- ((cellSizePixels - margin) / width) * 2,
151
- (-(cellSizePixels - margin) / height) * 2,
152
- 1
153
- ]);
154
- model.setUniforms({ cellScale });
155
- }
156
- }
157
- }
158
- ScreenGridCellLayer.layerName = 'ScreenGridCellLayer';
159
- ScreenGridCellLayer.defaultProps = defaultProps;
@@ -1,37 +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
- /* fragment shader for the grid-layer */
21
- export default `\
22
- #define SHADER_NAME screen-grid-layer-fragment-shader
23
-
24
- precision highp float;
25
-
26
- varying vec4 vColor;
27
- varying float vSampleCount;
28
-
29
- void main(void) {
30
- if (vSampleCount <= 0.0) {
31
- discard;
32
- }
33
- gl_FragColor = vColor;
34
-
35
- DECKGL_FILTER_COLOR(gl_FragColor, geometry);
36
- }
37
- `;
@@ -1,83 +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 screen-grid-layer-vertex-shader
22
- #define RANGE_COUNT 6
23
-
24
- attribute vec3 positions;
25
- attribute vec3 instancePositions;
26
- attribute vec4 instanceCounts;
27
- attribute vec3 instancePickingColors;
28
-
29
- uniform float opacity;
30
- uniform vec3 cellScale;
31
- uniform vec4 minColor;
32
- uniform vec4 maxColor;
33
- uniform vec4 colorRange[RANGE_COUNT];
34
- uniform vec2 colorDomain;
35
- uniform bool shouldUseMinMax;
36
- uniform sampler2D maxTexture;
37
-
38
- varying vec4 vColor;
39
- varying float vSampleCount;
40
-
41
- vec4 quantizeScale(vec2 domain, vec4 range[RANGE_COUNT], float value) {
42
- vec4 outColor = vec4(0., 0., 0., 0.);
43
- if (value >= domain.x && value <= domain.y) {
44
- float domainRange = domain.y - domain.x;
45
- if (domainRange <= 0.) {
46
- outColor = colorRange[0];
47
- } else {
48
- float rangeCount = float(RANGE_COUNT);
49
- float rangeStep = domainRange / rangeCount;
50
- float idx = floor((value - domain.x) / rangeStep);
51
- idx = clamp(idx, 0., rangeCount - 1.);
52
- int intIdx = int(idx);
53
- outColor = colorRange[intIdx];
54
- }
55
- }
56
- outColor = outColor / 255.;
57
- return outColor;
58
- }
59
-
60
- void main(void) {
61
- vSampleCount = instanceCounts.a;
62
-
63
- float weight = instanceCounts.r;
64
- float maxWeight = texture2D(maxTexture, vec2(0.5)).r;
65
-
66
- float step = weight / maxWeight;
67
- vec4 minMaxColor = mix(minColor, maxColor, step) / 255.;
68
-
69
- vec2 domain = colorDomain;
70
- float domainMaxValid = float(colorDomain.y != 0.);
71
- domain.y = mix(maxWeight, colorDomain.y, domainMaxValid);
72
- vec4 rangeColor = quantizeScale(domain, colorRange, weight);
73
-
74
- float rangeMinMax = float(shouldUseMinMax);
75
- vec4 color = mix(rangeColor, minMaxColor, rangeMinMax);
76
- vColor = vec4(color.rgb, color.a * opacity);
77
-
78
- // Set color to be rendered to picking fbo (also used to check for selection highlight).
79
- picking_setPickingColor(instancePickingColors);
80
-
81
- gl_Position = vec4(instancePositions + positions * cellScale, 1.);
82
- }
83
- `;