@deck.gl/extensions 8.8.0-alpha.6 → 8.8.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 (128) hide show
  1. package/dist/dist.dev.js +480 -1335
  2. package/dist/es5/brushing/brushing.js +19 -15
  3. package/dist/es5/brushing/brushing.js.map +1 -1
  4. package/dist/es5/brushing/shader-module.js +1 -1
  5. package/dist/es5/brushing/shader-module.js.map +1 -1
  6. package/dist/es5/clip/clip.js +4 -2
  7. package/dist/es5/clip/clip.js.map +1 -1
  8. package/dist/es5/data-filter/aggregator.js +1 -1
  9. package/dist/es5/data-filter/aggregator.js.map +1 -1
  10. package/dist/es5/data-filter/data-filter.js +9 -9
  11. package/dist/es5/data-filter/data-filter.js.map +1 -1
  12. package/dist/es5/data-filter/shader-module.js +22 -13
  13. package/dist/es5/data-filter/shader-module.js.map +1 -1
  14. package/dist/es5/fill-style/fill-style.js +13 -11
  15. package/dist/es5/fill-style/fill-style.js.map +1 -1
  16. package/dist/es5/fill-style/shaders.glsl.js +8 -6
  17. package/dist/es5/fill-style/shaders.glsl.js.map +1 -1
  18. package/dist/es5/fp64/fp64.js +4 -2
  19. package/dist/es5/fp64/fp64.js.map +1 -1
  20. package/dist/es5/fp64/project64.glsl.js +1 -1
  21. package/dist/es5/fp64/project64.js +2 -5
  22. package/dist/es5/fp64/project64.js.map +1 -1
  23. package/dist/es5/index.js.map +1 -1
  24. package/dist/es5/mask/mask.js +7 -4
  25. package/dist/es5/mask/mask.js.map +1 -1
  26. package/dist/es5/mask/shader-module.js +6 -7
  27. package/dist/es5/mask/shader-module.js.map +1 -1
  28. package/dist/es5/path-style/path-style.js +5 -5
  29. package/dist/es5/path-style/path-style.js.map +1 -1
  30. package/dist/es5/path-style/shaders.glsl.js +1 -1
  31. package/dist/es5/path-style/shaders.glsl.js.map +1 -1
  32. package/dist/esm/brushing/brushing.js +20 -15
  33. package/dist/esm/brushing/brushing.js.map +1 -1
  34. package/dist/esm/brushing/shader-module.js +1 -1
  35. package/dist/esm/brushing/shader-module.js.map +1 -1
  36. package/dist/esm/clip/clip.js +5 -2
  37. package/dist/esm/clip/clip.js.map +1 -1
  38. package/dist/esm/data-filter/aggregator.js +1 -1
  39. package/dist/esm/data-filter/aggregator.js.map +1 -1
  40. package/dist/esm/data-filter/data-filter.js +6 -3
  41. package/dist/esm/data-filter/data-filter.js.map +1 -1
  42. package/dist/esm/data-filter/shader-module.js +21 -21
  43. package/dist/esm/data-filter/shader-module.js.map +1 -1
  44. package/dist/esm/fill-style/fill-style.js +18 -13
  45. package/dist/esm/fill-style/fill-style.js.map +1 -1
  46. package/dist/esm/fill-style/shaders.glsl.js +6 -2
  47. package/dist/esm/fill-style/shaders.glsl.js.map +1 -1
  48. package/dist/esm/fp64/fp64.js +4 -2
  49. package/dist/esm/fp64/fp64.js.map +1 -1
  50. package/dist/esm/fp64/project64.glsl.js +1 -1
  51. package/dist/esm/fp64/project64.glsl.js.map +1 -1
  52. package/dist/esm/fp64/project64.js +2 -3
  53. package/dist/esm/fp64/project64.js.map +1 -1
  54. package/dist/esm/index.js.map +1 -1
  55. package/dist/esm/mask/mask.js +7 -4
  56. package/dist/esm/mask/mask.js.map +1 -1
  57. package/dist/esm/mask/shader-module.js +6 -6
  58. package/dist/esm/mask/shader-module.js.map +1 -1
  59. package/dist/esm/path-style/path-style.js +6 -5
  60. package/dist/esm/path-style/path-style.js.map +1 -1
  61. package/dist/esm/path-style/shaders.glsl.js +1 -1
  62. package/dist/esm/path-style/shaders.glsl.js.map +1 -1
  63. package/dist.min.js +1 -1
  64. package/package.json +5 -3
  65. package/src/brushing/{brushing.js → brushing.ts} +45 -17
  66. package/src/brushing/{shader-module.js → shader-module.ts} +13 -3
  67. package/src/clip/{clip.js → clip.ts} +26 -9
  68. package/src/data-filter/{aggregator.js → aggregator.ts} +12 -8
  69. package/src/data-filter/{data-filter.js → data-filter.ts} +90 -13
  70. package/src/data-filter/{shader-module.js → shader-module.ts} +36 -27
  71. package/src/fill-style/{fill-style.js → fill-style.ts} +83 -19
  72. package/src/fill-style/{shaders.glsl.js → shaders.glsl.ts} +24 -4
  73. package/src/fp64/{fp64.js → fp64.ts} +6 -3
  74. package/src/fp64/{project64.glsl.js → project64.glsl.ts} +0 -0
  75. package/src/fp64/{project64.js → project64.ts} +16 -5
  76. package/src/index.ts +8 -0
  77. package/src/mask/{mask.js → mask.ts} +25 -8
  78. package/src/mask/shader-module.ts +86 -0
  79. package/src/path-style/{path-style.js → path-style.ts} +65 -14
  80. package/src/path-style/{shaders.glsl.js → shaders.glsl.ts} +0 -0
  81. package/typed/brushing/brushing.d.ts +37 -16
  82. package/typed/brushing/brushing.d.ts.map +1 -1
  83. package/typed/brushing/brushing.js +83 -0
  84. package/typed/brushing/shader-module.d.ts +9 -24
  85. package/typed/brushing/shader-module.d.ts.map +1 -1
  86. package/typed/brushing/shader-module.js +116 -0
  87. package/typed/clip/clip.d.ts +27 -10
  88. package/typed/clip/clip.d.ts.map +1 -1
  89. package/typed/clip/clip.js +114 -0
  90. package/typed/data-filter/aggregator.d.ts +10 -9
  91. package/typed/data-filter/aggregator.d.ts.map +1 -1
  92. package/typed/data-filter/aggregator.js +98 -0
  93. package/typed/data-filter/data-filter.d.ts +87 -29
  94. package/typed/data-filter/data-filter.d.ts.map +1 -1
  95. package/typed/data-filter/data-filter.js +159 -0
  96. package/typed/data-filter/shader-module.d.ts +7 -24
  97. package/typed/data-filter/shader-module.d.ts.map +1 -1
  98. package/typed/data-filter/shader-module.js +152 -0
  99. package/typed/fill-style/fill-style.d.ts +74 -41
  100. package/typed/fill-style/fill-style.d.ts.map +1 -1
  101. package/typed/fill-style/fill-style.js +152 -0
  102. package/typed/fill-style/shaders.glsl.d.ts +8 -33
  103. package/typed/fill-style/shaders.glsl.d.ts.map +1 -1
  104. package/typed/fill-style/shaders.glsl.js +95 -0
  105. package/typed/fp64/fp64.d.ts +6 -6
  106. package/typed/fp64/fp64.d.ts.map +1 -1
  107. package/typed/fp64/fp64.js +34 -0
  108. package/typed/fp64/project64.d.ts +5 -9
  109. package/typed/fp64/project64.d.ts.map +1 -1
  110. package/typed/fp64/project64.glsl.d.ts +1 -1
  111. package/typed/fp64/project64.glsl.d.ts.map +1 -1
  112. package/typed/fp64/project64.glsl.js +100 -0
  113. package/typed/fp64/project64.js +50 -0
  114. package/typed/index.d.ts +6 -0
  115. package/typed/index.d.ts.map +1 -1
  116. package/typed/index.js +9 -0
  117. package/typed/mask/mask.d.ts +21 -9
  118. package/typed/mask/mask.d.ts.map +1 -1
  119. package/typed/mask/mask.js +48 -0
  120. package/typed/mask/shader-module.d.ts +6 -20
  121. package/typed/mask/shader-module.d.ts.map +1 -1
  122. package/{src → typed}/mask/shader-module.js +16 -21
  123. package/typed/path-style/path-style.d.ts +63 -27
  124. package/typed/path-style/path-style.d.ts.map +1 -1
  125. package/typed/path-style/path-style.js +107 -0
  126. package/typed/path-style/shaders.glsl.d.ts +6 -7
  127. package/typed/path-style/shaders.glsl.d.ts.map +1 -1
  128. package/typed/path-style/shaders.glsl.js +93 -0
@@ -24,6 +24,8 @@ import * as aggregator from './aggregator';
24
24
  import {readPixelsToArray, clear} from '@luma.gl/core';
25
25
  import GL from '@luma.gl/constants';
26
26
 
27
+ import type {Layer, LayerContext, Accessor, UpdateParameters} from '@deck.gl/core';
28
+
27
29
  const defaultProps = {
28
30
  getFilterValue: {type: 'accessor', value: 0},
29
31
  onFilteredItemsChange: {type: 'function', value: null, compare: false},
@@ -35,6 +37,68 @@ const defaultProps = {
35
37
  filterTransformColor: true
36
38
  };
37
39
 
40
+ export type DataFilterExtensionProps<DataT = any> = {
41
+ /**
42
+ * Accessor to retrieve the value for each object that it will be filtered by.
43
+ * Returns either a number (if `filterSize: 1`) or an array of numbers.
44
+ */
45
+ getFilterValue?: Accessor<DataT, number | number[]>;
46
+ /**
47
+ * Enable/disable the data filter. If the data filter is disabled, all objects are rendered.
48
+ * @default true
49
+ */
50
+ filterEnabled?: boolean;
51
+ /**
52
+ * The [min, max] bounds which defines whether an object should be rendered.
53
+ * If an object's filtered value is within the bounds, the object will be rendered; otherwise it will be hidden.
54
+ * @default [-1, 1]
55
+ */
56
+ filterRange?: [number, number] | [number, number][];
57
+ /**
58
+ * If specified, objects will be faded in/out instead of abruptly shown/hidden.
59
+ * When the filtered value is outside of the bounds defined by `filterSoftRange` but still within the bounds defined by `filterRange`, the object will be rendered as "faded."
60
+ * @default null
61
+ */
62
+ filterSoftRange?: [number, number] | [number, number][] | null;
63
+ /**
64
+ * When an object is "faded", manipulate its size so that it appears smaller or thinner. Only works if `filterSoftRange` is specified.
65
+ * @default true
66
+ */
67
+ filterTransformSize?: boolean;
68
+ /**
69
+ * When an object is "faded", manipulate its opacity so that it appears more translucent. Only works if `filterSoftRange` is specified.
70
+ * @default true
71
+ */
72
+ filterTransformColor?: boolean;
73
+ /**
74
+ * Only called if the `countItems` option is enabled.
75
+ */
76
+ onFilteredItemsChange?: (evt: {
77
+ /** The id of the source layer. */
78
+ id: string;
79
+ /** The number of data objects that pass the filter. */
80
+ count: number;
81
+ }) => void;
82
+ };
83
+
84
+ type DataFilterExtensionOptions = {
85
+ /**
86
+ * The size of the filter (number of columns to filter by). The data filter can show/hide data based on 1-4 numeric properties of each object.
87
+ * @default 1
88
+ */
89
+ filterSize: number;
90
+ /**
91
+ * Use 64-bit precision instead of 32-bit.
92
+ * @default false
93
+ */
94
+ fp64: boolean;
95
+ /**
96
+ * If `true`, reports the number of filtered objects with the `onFilteredItemsChange` callback.
97
+ * @default `false`.
98
+ */
99
+ countItems: boolean;
100
+ };
101
+
38
102
  const DATA_TYPE_FROM_SIZE = {
39
103
  1: 'float',
40
104
  2: 'vec2',
@@ -42,8 +106,16 @@ const DATA_TYPE_FROM_SIZE = {
42
106
  4: 'vec4'
43
107
  };
44
108
 
45
- export default class DataFilterExtension extends LayerExtension {
46
- constructor({filterSize = 1, fp64 = false, countItems = false} = {}) {
109
+ /** Adds GPU-based data filtering functionalities to layers. It allows the layer to show/hide objects based on user-defined properties. */
110
+ export default class DataFilterExtension extends LayerExtension<DataFilterExtensionOptions> {
111
+ static defaultProps = defaultProps;
112
+ static extensionName = 'DataFilterExtension';
113
+
114
+ constructor({
115
+ filterSize = 1,
116
+ fp64 = false,
117
+ countItems = false
118
+ }: Partial<DataFilterExtensionOptions> = {}) {
47
119
  if (!DATA_TYPE_FROM_SIZE[filterSize]) {
48
120
  throw new Error('filterSize out of range');
49
121
  }
@@ -51,7 +123,7 @@ export default class DataFilterExtension extends LayerExtension {
51
123
  super({filterSize, fp64, countItems});
52
124
  }
53
125
 
54
- getShaders(extension) {
126
+ getShaders(this: Layer<DataFilterExtensionProps>, extension: this): any {
55
127
  const {filterSize, fp64} = extension.opts;
56
128
 
57
129
  return {
@@ -63,7 +135,7 @@ export default class DataFilterExtension extends LayerExtension {
63
135
  };
64
136
  }
65
137
 
66
- initializeState(context, extension) {
138
+ initializeState(this: Layer<DataFilterExtensionProps>, context: LayerContext, extension: this) {
67
139
  const attributeManager = this.getAttributeManager();
68
140
  if (attributeManager) {
69
141
  attributeManager.add({
@@ -111,16 +183,24 @@ export default class DataFilterExtension extends LayerExtension {
111
183
  });
112
184
 
113
185
  const filterFBO = aggregator.getFramebuffer(gl, useFloatTarget);
114
- const filterModel = aggregator.getModel(gl, extension.getShaders(extension), useFloatTarget);
186
+ const filterModel = aggregator.getModel(
187
+ gl,
188
+ extension.getShaders.call(this, extension),
189
+ useFloatTarget
190
+ );
115
191
  this.setState({filterFBO, filterModel});
116
192
  }
117
193
  }
118
194
 
119
- updateState({props, oldProps}) {
195
+ updateState(
196
+ this: Layer<DataFilterExtensionProps>,
197
+ {props, oldProps}: UpdateParameters<Layer<DataFilterExtensionProps>>
198
+ ) {
120
199
  if (this.state.filterModel) {
121
200
  const attributeManager = this.getAttributeManager();
122
201
  const filterNeedsUpdate =
123
- attributeManager.attributes.filterValues.needsUpdate() ||
202
+ // attributeManager must be defined for filterModel to be set
203
+ attributeManager!.attributes.filterValues.needsUpdate() ||
124
204
  props.filterEnabled !== oldProps.filterEnabled ||
125
205
  props.filterRange !== oldProps.filterRange ||
126
206
  props.filterSoftRange !== oldProps.filterSoftRange;
@@ -130,13 +210,13 @@ export default class DataFilterExtension extends LayerExtension {
130
210
  }
131
211
  }
132
212
 
133
- draw(params, extension) {
213
+ draw(this: Layer<DataFilterExtensionProps>, params: any, extension: this) {
134
214
  const {filterFBO, filterModel, filterNeedsUpdate} = this.state;
135
215
  const {onFilteredItemsChange} = this.props;
136
216
  if (filterNeedsUpdate && onFilteredItemsChange && filterModel) {
137
217
  const {
138
218
  attributes: {filterValues, filterIndices}
139
- } = this.getAttributeManager();
219
+ } = this.getAttributeManager()!;
140
220
  filterModel.setVertexCount(this.getNumInstances());
141
221
 
142
222
  const {gl} = this.context;
@@ -166,7 +246,7 @@ export default class DataFilterExtension extends LayerExtension {
166
246
  }
167
247
  }
168
248
 
169
- finalizeState() {
249
+ finalizeState(this: Layer<DataFilterExtensionProps>) {
170
250
  const {filterFBO, filterModel} = this.state;
171
251
  if (filterFBO) {
172
252
  filterFBO.color.delete();
@@ -175,6 +255,3 @@ export default class DataFilterExtension extends LayerExtension {
175
255
  }
176
256
  }
177
257
  }
178
-
179
- DataFilterExtension.extensionName = 'DataFilterExtension';
180
- DataFilterExtension.defaultProps = defaultProps;
@@ -1,3 +1,7 @@
1
+ import {_ShaderModule as ShaderModule} from '@deck.gl/core/typed';
2
+
3
+ import type {DataFilterExtensionProps} from './data-filter';
4
+
1
5
  /*
2
6
  * data filter shader module
3
7
  */
@@ -63,8 +67,13 @@ uniform bool filter_transformColor;
63
67
  varying float dataFilter_value;
64
68
  `;
65
69
 
66
- const getUniforms = opts => {
67
- if (!opts || !opts.extensions) {
70
+ type DataFilterModuleSettings = {
71
+ extensions: any[]; // used to detect if layer props are present
72
+ } & DataFilterExtensionProps;
73
+
74
+ /* eslint-disable camelcase */
75
+ function getUniforms(opts?: DataFilterModuleSettings | {}): Record<string, any> {
76
+ if (!opts || !('extensions' in opts)) {
68
77
  return {};
69
78
  }
70
79
  const {
@@ -75,29 +84,29 @@ const getUniforms = opts => {
75
84
  } = opts;
76
85
  const filterSoftRange = opts.filterSoftRange || filterRange;
77
86
 
78
- const uniforms = Number.isFinite(filterRange[0])
79
- ? {
80
- filter_min: filterRange[0],
81
- filter_softMin: filterSoftRange[0],
82
- filter_softMax: filterSoftRange[1],
83
- filter_max: filterRange[1]
84
- }
85
- : {
86
- filter_min: filterRange.map(r => r[0]),
87
- filter_softMin: filterSoftRange.map(r => r[0]),
88
- filter_softMax: filterSoftRange.map(r => r[1]),
89
- filter_max: filterRange.map(r => r[1])
90
- };
91
- uniforms.filter_enabled = filterEnabled;
92
- uniforms.filter_useSoftMargin = Boolean(opts.filterSoftRange);
93
- uniforms.filter_transformSize = filterEnabled && filterTransformSize;
94
- uniforms.filter_transformColor = filterEnabled && filterTransformColor;
95
-
96
- return uniforms;
97
- };
87
+ return {
88
+ ...(Number.isFinite(filterRange[0])
89
+ ? {
90
+ filter_min: filterRange[0],
91
+ filter_softMin: filterSoftRange[0],
92
+ filter_softMax: filterSoftRange[1],
93
+ filter_max: filterRange[1]
94
+ }
95
+ : {
96
+ filter_min: filterRange.map(r => r[0]),
97
+ filter_softMin: filterSoftRange.map(r => r[0]),
98
+ filter_softMax: filterSoftRange.map(r => r[1]),
99
+ filter_max: filterRange.map(r => r[1])
100
+ }),
101
+ filter_enabled: filterEnabled,
102
+ filter_useSoftMargin: Boolean(opts.filterSoftRange),
103
+ filter_transformSize: filterEnabled && filterTransformSize,
104
+ filter_transformColor: filterEnabled && filterTransformColor
105
+ };
106
+ }
98
107
 
99
- const getUniforms64 = opts => {
100
- if (!opts || !opts.extensions) {
108
+ function getUniforms64(opts?: DataFilterModuleSettings | {}): Record<string, any> {
109
+ if (!opts || !('extensions' in opts)) {
101
110
  return {};
102
111
  }
103
112
  const uniforms = getUniforms(opts);
@@ -123,7 +132,7 @@ const getUniforms64 = opts => {
123
132
  uniforms.filter_max64High = max64High;
124
133
  }
125
134
  return uniforms;
126
- };
135
+ }
127
136
 
128
137
  const inject = {
129
138
  'vs:#main-start': `
@@ -151,7 +160,7 @@ const inject = {
151
160
  `
152
161
  };
153
162
 
154
- export const shaderModule = {
163
+ export const shaderModule: ShaderModule<DataFilterModuleSettings> = {
155
164
  name: 'data-filter',
156
165
  vs,
157
166
  fs,
@@ -159,7 +168,7 @@ export const shaderModule = {
159
168
  getUniforms
160
169
  };
161
170
 
162
- export const shaderModule64 = {
171
+ export const shaderModule64: ShaderModule<DataFilterModuleSettings> = {
163
172
  name: 'data-filter-fp64',
164
173
  vs,
165
174
  fs,
@@ -4,6 +4,15 @@ import GL from '@luma.gl/constants';
4
4
 
5
5
  import {patternShaders} from './shaders.glsl';
6
6
 
7
+ import type {
8
+ Layer,
9
+ LayerContext,
10
+ Accessor,
11
+ AccessorFunction,
12
+ Texture,
13
+ UpdateParameters
14
+ } from '@deck.gl/core';
15
+
7
16
  const defaultProps = {
8
17
  fillPatternEnabled: true,
9
18
  fillPatternAtlas: null,
@@ -14,6 +23,54 @@ const defaultProps = {
14
23
  getFillPatternOffset: {type: 'accessor', value: [0, 0]}
15
24
  };
16
25
 
26
+ export type FillStyleExtensionProps<DataT = any> = {
27
+ /** Cheap toggle to enable/disable pattern fill. Requires the `pattern` option to be on.
28
+ * @default true
29
+ */
30
+ fillPatternEnabled?: boolean;
31
+ /** Sprite image url or texture that packs all your patterns into one layout. */
32
+ fillPatternAtlas?: Texture;
33
+ /** Pattern names mapped to pattern definitions, or a url that points to a JSON file. */
34
+ fillPatternMapping?:
35
+ | string
36
+ | Record<
37
+ string,
38
+ {
39
+ /** Left position of the pattern on the atlas */
40
+ x: number;
41
+ /** Top position of the pattern on the atlas */
42
+ y: number;
43
+ /** Width of the pattern */
44
+ width: number;
45
+ /** Height of the pattern */
46
+ height: number;
47
+ }
48
+ >;
49
+ /**
50
+ * Whether to treat the patterns as transparency masks.
51
+ * @default true
52
+ */
53
+ fillPatternMask?: boolean;
54
+ /** Accessor for the name of the pattern. */
55
+ getFillPattern?: AccessorFunction<DataT, string>;
56
+ /** Accessor for the scale of the pattern, relative to the original size. If the pattern is 24 x 24 pixels, scale `1` roughly yields 24 meters.
57
+ * @default 1
58
+ */
59
+ getFillPatternScale?: Accessor<DataT, number>;
60
+ /**
61
+ * Accessor for the offset of the pattern, relative to the original size. Offset `[0.5, 0.5]` shifts the pattern alignment by half.
62
+ * @default [0, 0]
63
+ */
64
+ getFillPatternOffset?: Accessor<DataT, [number, number]>;
65
+ };
66
+
67
+ type FillStyleExtensionOptions = {
68
+ /** If `true`, adds the ability to tile the filled area with a pattern.
69
+ * @default false
70
+ */
71
+ pattern: boolean;
72
+ };
73
+
17
74
  const DEFAULT_TEXTURE_PARAMETERS = {
18
75
  [GL.TEXTURE_MIN_FILTER]: GL.LINEAR,
19
76
  // GL.LINEAR is the default value but explicitly set it here
@@ -23,16 +80,20 @@ const DEFAULT_TEXTURE_PARAMETERS = {
23
80
  [GL.TEXTURE_WRAP_T]: GL.CLAMP_TO_EDGE
24
81
  };
25
82
 
26
- export default class FillStyleExtension extends LayerExtension {
27
- constructor({pattern = false} = {}) {
83
+ /** Adds selected features to layers that render a "fill", such as the `PolygonLayer` and `ScatterplotLayer`. */
84
+ export default class FillStyleExtension extends LayerExtension<FillStyleExtensionOptions> {
85
+ static defaultProps = defaultProps;
86
+ static extensionName = 'FillStyleExtension';
87
+
88
+ constructor({pattern = false}: Partial<FillStyleExtensionOptions> = {}) {
28
89
  super({pattern});
29
90
  }
30
91
 
31
- isEnabled(layer) {
32
- return layer.getAttributeManager() && !layer.state.pathTesselator;
92
+ isEnabled(layer: Layer<FillStyleExtensionProps>): boolean {
93
+ return layer.getAttributeManager() !== null && !('pathTesselator' in layer.state);
33
94
  }
34
95
 
35
- getShaders(extension) {
96
+ getShaders(this: Layer<FillStyleExtensionProps>, extension: this): any {
36
97
  if (!extension.isEnabled(this)) {
37
98
  return null;
38
99
  }
@@ -42,7 +103,7 @@ export default class FillStyleExtension extends LayerExtension {
42
103
  };
43
104
  }
44
105
 
45
- initializeState(context, extension) {
106
+ initializeState(this: Layer<FillStyleExtensionProps>, context: LayerContext, extension: this) {
46
107
  if (!extension.isEnabled(this)) {
47
108
  return;
48
109
  }
@@ -50,7 +111,7 @@ export default class FillStyleExtension extends LayerExtension {
50
111
  const attributeManager = this.getAttributeManager();
51
112
 
52
113
  if (extension.opts.pattern) {
53
- attributeManager.add({
114
+ attributeManager!.add({
54
115
  fillPatternFrames: {
55
116
  size: 4,
56
117
  accessor: 'getFillPattern',
@@ -100,20 +161,24 @@ export default class FillStyleExtension extends LayerExtension {
100
161
  });
101
162
  }
102
163
 
103
- updateState({props, oldProps}, extension) {
164
+ updateState(
165
+ this: Layer<FillStyleExtensionProps>,
166
+ {props, oldProps}: UpdateParameters<Layer<FillStyleExtensionProps>>,
167
+ extension: this
168
+ ) {
104
169
  if (!extension.isEnabled(this)) {
105
170
  return;
106
171
  }
107
172
 
108
173
  if (props.fillPatternAtlas && props.fillPatternAtlas !== oldProps.fillPatternAtlas) {
109
- extension.loadPatternAtlas.call(this, props);
174
+ extension.loadPatternAtlas.call(this);
110
175
  }
111
176
  if (props.fillPatternMapping && props.fillPatternMapping !== oldProps.fillPatternMapping) {
112
- extension.loadPatternMapping.call(this, props);
177
+ extension.loadPatternMapping.call(this);
113
178
  }
114
179
  }
115
180
 
116
- draw(params, extension) {
181
+ draw(this: Layer<FillStyleExtensionProps>, params: any, extension: this) {
117
182
  if (!extension.isEnabled(this)) {
118
183
  return;
119
184
  }
@@ -124,13 +189,14 @@ export default class FillStyleExtension extends LayerExtension {
124
189
  });
125
190
  }
126
191
 
127
- finalizeState() {
192
+ finalizeState(this: Layer<FillStyleExtensionProps>) {
128
193
  const {patternTexture, emptyTexture} = this.state;
129
194
  patternTexture?.delete();
130
195
  emptyTexture?.delete();
131
196
  }
132
197
 
133
- async loadPatternAtlas({fillPatternAtlas, fetch}) {
198
+ async loadPatternAtlas(this: Layer<FillStyleExtensionProps>) {
199
+ const {fillPatternAtlas, fetch} = this.props;
134
200
  this.state.patternTexture?.delete();
135
201
  this.setState({patternTexture: null});
136
202
  let image = fillPatternAtlas;
@@ -147,7 +213,8 @@ export default class FillStyleExtension extends LayerExtension {
147
213
  this.setState({patternTexture});
148
214
  }
149
215
 
150
- async loadPatternMapping({fillPatternMapping, fetch}) {
216
+ async loadPatternMapping(this: Layer<FillStyleExtensionProps>) {
217
+ const {fillPatternMapping, fetch} = this.props;
151
218
  this.setState({patternMapping: null});
152
219
  let patternMapping = fillPatternMapping;
153
220
  if (typeof patternMapping === 'string') {
@@ -157,16 +224,13 @@ export default class FillStyleExtension extends LayerExtension {
157
224
  });
158
225
  }
159
226
  this.setState({patternMapping});
160
- this.getAttributeManager().invalidate('getFillPattern');
227
+ this.getAttributeManager()!.invalidate('getFillPattern');
161
228
  this.setNeedsUpdate();
162
229
  }
163
230
 
164
- getPatternFrame(name) {
231
+ getPatternFrame(this: Layer<FillStyleExtensionProps>, name: string) {
165
232
  const {patternMapping} = this.state;
166
233
  const def = patternMapping && patternMapping[name];
167
234
  return def ? [def.x, def.y, def.width, def.height] : [0, 0, 0, 0];
168
235
  }
169
236
  }
170
-
171
- FillStyleExtension.extensionName = 'FillStyleExtension';
172
- FillStyleExtension.defaultProps = defaultProps;
@@ -1,4 +1,7 @@
1
1
  import {project, COORDINATE_SYSTEM} from '@deck.gl/core';
2
+ import type {Viewport, _ShaderModule as ShaderModule, ProjectUniforms} from '@deck.gl/core';
3
+
4
+ import type {Texture2D} from '@luma.gl/webgl';
2
5
 
3
6
  /*
4
7
  * fill pattern shader module
@@ -69,7 +72,24 @@ const inject = {
69
72
  `
70
73
  };
71
74
 
72
- function getPatternUniforms(opts = {}, uniforms) {
75
+ type FillStyleModuleSettings =
76
+ | {
77
+ viewport: Viewport;
78
+ fillPatternEnabled?: boolean;
79
+ fillPatternMask?: boolean;
80
+ }
81
+ | {
82
+ fillPatternTexture: Texture2D;
83
+ };
84
+
85
+ /* eslint-disable camelcase */
86
+ function getPatternUniforms(
87
+ opts: FillStyleModuleSettings | {},
88
+ uniforms: Record<string, any>
89
+ ): Record<string, any> {
90
+ if (!opts) {
91
+ return {};
92
+ }
73
93
  if ('fillPatternTexture' in opts) {
74
94
  const {fillPatternTexture} = opts;
75
95
  return {
@@ -77,9 +97,9 @@ function getPatternUniforms(opts = {}, uniforms) {
77
97
  fill_patternTextureSize: [fillPatternTexture.width, fillPatternTexture.height]
78
98
  };
79
99
  }
80
- if (opts.viewport) {
100
+ if ('viewport' in opts) {
81
101
  const {viewport, fillPatternMask = true, fillPatternEnabled = true} = opts;
82
- const {project_uCoordinateOrigin, project_uCoordinateSystem} = uniforms;
102
+ const {project_uCoordinateOrigin, project_uCoordinateSystem} = uniforms as ProjectUniforms;
83
103
 
84
104
  const coordinateOriginCommon =
85
105
  project_uCoordinateSystem === COORDINATE_SYSTEM.CARTESIAN
@@ -95,7 +115,7 @@ function getPatternUniforms(opts = {}, uniforms) {
95
115
  return {};
96
116
  }
97
117
 
98
- export const patternShaders = {
118
+ export const patternShaders: ShaderModule<FillStyleModuleSettings> = {
99
119
  name: 'fill-pattern',
100
120
  vs: patternVs,
101
121
  fs: patternFs,
@@ -21,8 +21,13 @@
21
21
  import {LayerExtension, COORDINATE_SYSTEM} from '@deck.gl/core';
22
22
  import project64 from './project64';
23
23
 
24
+ import type {Layer} from '@deck.gl/core';
25
+
26
+ /** @deprecated Adds the legacy 64-bit precision to geospatial layers. */
24
27
  export default class Fp64Extension extends LayerExtension {
25
- getShaders(opts) {
28
+ static extensionName = 'Fp64Extension';
29
+
30
+ getShaders(this: Layer): any {
26
31
  const {coordinateSystem} = this.props;
27
32
  if (
28
33
  coordinateSystem !== COORDINATE_SYSTEM.LNGLAT &&
@@ -36,5 +41,3 @@ export default class Fp64Extension extends LayerExtension {
36
41
  };
37
42
  }
38
43
  }
39
-
40
- Fp64Extension.extensionName = 'Fp64Extension';
@@ -18,27 +18,32 @@
18
18
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  // THE SOFTWARE.
20
20
 
21
+ /* eslint-disable camelcase */
21
22
  import {fp64} from '@luma.gl/shadertools';
22
23
  const {fp64ify, fp64ifyMatrix4} = fp64;
23
24
  import {project, _memoize as memoize} from '@deck.gl/core';
24
25
 
26
+ import type {Viewport, _ShaderModule as ShaderModule} from '@deck.gl/core';
25
27
  import project64Shader from './project64.glsl';
26
28
 
29
+ type Project64ModuleSettings = {
30
+ viewport: Viewport;
31
+ };
32
+
27
33
  export default {
28
34
  name: 'project64',
29
35
  dependencies: [project, fp64],
30
36
  vs: project64Shader,
31
37
  getUniforms
32
- };
38
+ } as ShaderModule<Project64ModuleSettings>;
33
39
 
34
40
  // TODO - this module should calculate the 64 bit uniforms
35
41
  // It is currently done by project to minimize duplicated work
36
42
 
37
- const DEFAULT_MODULE_OPTIONS = {};
38
43
  const getMemoizedUniforms = memoize(calculateUniforms);
39
44
 
40
- function getUniforms(opts = DEFAULT_MODULE_OPTIONS) {
41
- if (opts.viewport) {
45
+ function getUniforms(opts?: Project64ModuleSettings | {}): Record<string, any> {
46
+ if (opts && 'viewport' in opts) {
42
47
  const {viewProjectionMatrix, scale} = opts.viewport;
43
48
  // We only need to update fp64 uniforms if fp32 projection is being updated
44
49
  return getMemoizedUniforms({viewProjectionMatrix, scale});
@@ -46,7 +51,13 @@ function getUniforms(opts = DEFAULT_MODULE_OPTIONS) {
46
51
  return {};
47
52
  }
48
53
 
49
- function calculateUniforms({viewProjectionMatrix, scale}) {
54
+ function calculateUniforms({
55
+ viewProjectionMatrix,
56
+ scale
57
+ }: {
58
+ viewProjectionMatrix: number[];
59
+ scale: number;
60
+ }) {
50
61
  const glViewProjectionMatrixFP64 = fp64ifyMatrix4(viewProjectionMatrix);
51
62
  const scaleFP64 = fp64ify(scale);
52
63
 
package/src/index.ts CHANGED
@@ -8,3 +8,11 @@ export {default as MaskExtension} from './mask/mask';
8
8
 
9
9
  // Shader module
10
10
  export {default as project64} from './fp64/project64';
11
+
12
+ // Types
13
+ export type {BrushingExtensionProps} from './brushing/brushing';
14
+ export type {DataFilterExtensionProps} from './data-filter/data-filter';
15
+ export type {PathStyleExtensionProps} from './path-style/path-style';
16
+ export type {FillStyleExtensionProps} from './fill-style/fill-style';
17
+ export type {ClipExtensionProps} from './clip/clip';
18
+ export type {MaskExtensionProps} from './mask/mask';
@@ -1,17 +1,36 @@
1
1
  import {COORDINATE_SYSTEM, LayerExtension, log} from '@deck.gl/core';
2
2
  import mask from './shader-module';
3
3
 
4
+ import type {Layer} from '@deck.gl/core';
5
+
4
6
  const defaultProps = {
5
7
  maskId: ''
6
8
  };
7
9
 
10
+ export type MaskExtensionProps = {
11
+ /**
12
+ * Id of the layer that defines the mask. The mask layer must use the prop `operation: 'mask'`.
13
+ * Masking is disabled if `maskId` is empty or no valid mask layer with the specified id is found.
14
+ */
15
+ maskId?: string;
16
+ /**
17
+ * controls whether an object is clipped by its anchor (usually defined by an accessor called `getPosition`, e.g. icon, scatterplot) or by its geometry (e.g. path, polygon).
18
+ * If not specified, it is automatically deduced from the layer.
19
+ */
20
+ maskByInstance?: boolean;
21
+ };
22
+
23
+ /** Allows layers to show/hide objects by a geofence. */
8
24
  export default class MaskExtension extends LayerExtension {
9
- getShaders() {
25
+ static defaultProps = defaultProps;
26
+ static extensionName = 'MaskExtension';
27
+
28
+ getShaders(this: Layer<MaskExtensionProps>): any {
10
29
  // Infer by geometry if 'maskByInstance' prop isn't explictly set
11
- let maskByInstance = 'instancePositions' in this.getAttributeManager().attributes;
30
+ let maskByInstance = 'instancePositions' in this.getAttributeManager()!.attributes;
12
31
  // Users can override by setting the `maskByInstance` prop
13
32
  if ('maskByInstance' in this.props) {
14
- maskByInstance = this.props.maskByInstance;
33
+ maskByInstance = Boolean(this.props.maskByInstance);
15
34
  }
16
35
  this.state.maskByInstance = maskByInstance;
17
36
 
@@ -20,9 +39,10 @@ export default class MaskExtension extends LayerExtension {
20
39
  };
21
40
  }
22
41
 
23
- draw({uniforms, context, moduleParameters}) {
42
+ /* eslint-disable camelcase */
43
+ draw(this: Layer<MaskExtensionProps>, {uniforms, context, moduleParameters}: any) {
24
44
  uniforms.mask_maskByInstance = this.state.maskByInstance;
25
- const {maskId} = this.props;
45
+ const {maskId = ''} = this.props;
26
46
  const {maskChannels} = moduleParameters;
27
47
  const {viewport} = context;
28
48
  if (maskChannels && maskChannels[maskId]) {
@@ -48,6 +68,3 @@ export default class MaskExtension extends LayerExtension {
48
68
  }
49
69
  }
50
70
  }
51
-
52
- MaskExtension.extensionName = 'MaskExtension';
53
- MaskExtension.defaultProps = defaultProps;