@deck.gl-community/layers 9.0.0-alpha.1 → 9.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/index.cjs +605 -0
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +6 -5
  6. package/dist/path-marker-layer/arrow-2d-geometry.d.ts +5 -0
  7. package/dist/path-marker-layer/arrow-2d-geometry.d.ts.map +1 -0
  8. package/dist/path-marker-layer/arrow-2d-geometry.js +58 -0
  9. package/dist/path-marker-layer/create-path-markers.d.ts +19 -0
  10. package/dist/path-marker-layer/create-path-markers.d.ts.map +1 -0
  11. package/dist/path-marker-layer/create-path-markers.js +78 -0
  12. package/dist/path-marker-layer/path-marker-layer.d.ts +41 -0
  13. package/dist/path-marker-layer/path-marker-layer.d.ts.map +1 -0
  14. package/dist/path-marker-layer/path-marker-layer.js +124 -0
  15. package/dist/path-marker-layer/polyline.d.ts +19 -0
  16. package/dist/path-marker-layer/polyline.d.ts.map +1 -0
  17. package/dist/path-marker-layer/polyline.js +40 -0
  18. package/dist/path-outline-layer/outline.d.ts +9 -0
  19. package/dist/path-outline-layer/outline.d.ts.map +1 -0
  20. package/dist/path-outline-layer/outline.js +100 -0
  21. package/dist/path-outline-layer/path-outline-layer.d.ts +35 -0
  22. package/dist/path-outline-layer/path-outline-layer.d.ts.map +1 -0
  23. package/dist/path-outline-layer/path-outline-layer.js +116 -0
  24. package/dist/tile-source-layer/tile-source-layer.d.ts +44 -0
  25. package/dist/tile-source-layer/tile-source-layer.d.ts.map +1 -0
  26. package/dist/tile-source-layer/tile-source-layer.js +109 -0
  27. package/package.json +27 -13
  28. package/src/index.ts +7 -4
  29. package/src/path-marker-layer/arrow-2d-geometry.ts +65 -0
  30. package/src/path-marker-layer/create-path-markers.ts +122 -0
  31. package/src/path-marker-layer/path-marker-layer.ts +183 -0
  32. package/src/path-marker-layer/polyline.ts +44 -0
  33. package/src/path-outline-layer/outline.ts +107 -0
  34. package/src/path-outline-layer/path-outline-layer.ts +159 -0
  35. package/src/{tile-source-layer.ts → tile-source-layer/tile-source-layer.ts} +30 -22
  36. package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js +0 -193
  37. package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js.map +0 -1
  38. package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js +0 -31
  39. package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js.map +0 -1
  40. package/dist/data-driven-tile-3d-layer/utils/filter-tile.js +0 -146
  41. package/dist/data-driven-tile-3d-layer/utils/filter-tile.js.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/tile-source-layer.js +0 -112
  44. package/dist/tile-source-layer.js.map +0 -1
  45. package/src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts +0 -261
  46. package/src/data-driven-tile-3d-layer/utils/colorize-tile.ts +0 -53
  47. package/src/data-driven-tile-3d-layer/utils/filter-tile.ts +0 -179
@@ -1,261 +0,0 @@
1
- // deck.gl-community
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {Tile3DLayer, Tile3DLayerProps} from '@deck.gl/geo-layers';
6
- import {UpdateParameters, Viewport, DefaultProps} from '@deck.gl/core';
7
- import {TILE_TYPE, Tile3D, Tileset3D} from '@loaders.gl/tiles';
8
- import {load} from '@loaders.gl/core';
9
-
10
- const defaultProps: DefaultProps<DataDrivenTile3DLayerProps> = {
11
- colorsByAttribute: null,
12
- filtersByAttribute: null
13
- };
14
-
15
- type DataDrivenTile3DLayerProps<DataT = any> = _DataDrivenTile3DLayerProps &
16
- Tile3DLayerProps<DataT>;
17
-
18
- type _DataDrivenTile3DLayerProps = {
19
- onTraversalComplete?: (selectedTiles: Tile3D[]) => Tile3D[];
20
- colorsByAttribute?: ColorsByAttribute | null;
21
- customizeColors?: (
22
- tile: Tile3D,
23
- colorsByAttribute: ColorsByAttribute | null
24
- ) => Promise<{isColored: boolean; id: string}>;
25
- filtersByAttribute?: FiltersByAttribute | null;
26
- filterTile?: (
27
- tile: Tile3D,
28
- filtersByAttribute: FiltersByAttribute | null
29
- ) => Promise<{isFiltered: boolean; id: string}>;
30
- };
31
-
32
- export type ColorsByAttribute = {
33
- /** Feature attribute name */
34
- attributeName: string;
35
- /** Minimum attribute value */
36
- minValue: number;
37
- /** Maximum attribute value */
38
- maxValue: number;
39
- /** Minimum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */
40
- minColor: [number, number, number, number];
41
- /** Maximum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */
42
- maxColor: [number, number, number, number];
43
- /** Colorization mode. `replace` - replace vertex colors with a new colors, `multiply` - multiply vertex colors with new colors */
44
- mode: string;
45
- };
46
-
47
- export type FiltersByAttribute = {
48
- /** Feature attribute name */
49
- attributeName: string;
50
- /** Filter value */
51
- value: number;
52
- };
53
-
54
- //@ts-expect-error call of private method of the base class
55
- export class DataDrivenTile3DLayer<DataT = any, ExtraProps extends {} = {}> extends Tile3DLayer<
56
- DataT,
57
- Required<_DataDrivenTile3DLayerProps> & ExtraProps
58
- > {
59
- static layerName = 'DataDrivenTile3DLayer';
60
- static defaultProps = defaultProps as any;
61
-
62
- state!: {
63
- activeViewports: any;
64
- frameNumber?: number;
65
- lastUpdatedViewports: {[viewportId: string]: Viewport} | null;
66
- layerMap: {[layerId: string]: any};
67
- tileset3d: Tileset3D | null;
68
-
69
- colorsByAttribute: ColorsByAttribute | null;
70
- filtersByAttribute: FiltersByAttribute | null;
71
- loadingCounter: number;
72
- };
73
-
74
- initializeState() {
75
- super.initializeState();
76
-
77
- this.setState({
78
- colorsByAttribute: this.props.colorsByAttribute,
79
- filtersByAttribute: this.props.filtersByAttribute,
80
- loadingCounter: 0
81
- });
82
- }
83
-
84
- updateState(params: UpdateParameters<this>): void {
85
- const {props, oldProps, changeFlags} = params;
86
-
87
- if (props.data && props.data !== oldProps.data) {
88
- this._loadTileset(props.data);
89
- } else if (props.colorsByAttribute !== oldProps.colorsByAttribute) {
90
- this.setState({
91
- colorsByAttribute: props.colorsByAttribute
92
- });
93
- this._colorizeTileset();
94
- } else if (props.filtersByAttribute !== oldProps.filtersByAttribute) {
95
- this.setState({
96
- filtersByAttribute: props.filtersByAttribute
97
- });
98
- this._filterTileset();
99
- } else if (changeFlags.viewportChanged) {
100
- const {activeViewports} = this.state;
101
- const viewportsNumber = Object.keys(activeViewports).length;
102
- if (viewportsNumber) {
103
- if (!this.state.loadingCounter) {
104
- //@ts-expect-error call of private method of the base class
105
- super._updateTileset(activeViewports);
106
- }
107
- this.state.lastUpdatedViewports = activeViewports;
108
- this.state.activeViewports = {};
109
- }
110
- } else {
111
- super.updateState(params);
112
- }
113
- }
114
-
115
- private override async _loadTileset(tilesetUrl) {
116
- const {loadOptions = {}} = this.props;
117
-
118
- // TODO: deprecate `loader` in v9.0
119
- let loader = this.props.loader || this.props.loaders;
120
- if (Array.isArray(loader)) {
121
- loader = loader[0];
122
- }
123
-
124
- const options = {loadOptions: {...loadOptions}};
125
- if (loader.preload) {
126
- const preloadOptions = await loader.preload(tilesetUrl, loadOptions);
127
-
128
- if (preloadOptions.headers) {
129
- options.loadOptions.fetch = {
130
- ...options.loadOptions.fetch,
131
- headers: preloadOptions.headers
132
- };
133
- }
134
- Object.assign(options, preloadOptions);
135
- }
136
- //@ts-expect-error loader
137
- const tilesetJson = await load(tilesetUrl, loader, options.loadOptions);
138
-
139
- const tileset3d = new Tileset3D(tilesetJson, {
140
- onTileLoad: this._onTileLoad.bind(this),
141
- //@ts-expect-error call of private method of the base class
142
- onTileUnload: super._onTileUnload.bind(this),
143
- onTileError: this.props.onTileError,
144
- // New code ------------------
145
- onTraversalComplete: this._onTraversalComplete.bind(this),
146
- // ---------------------------
147
- ...options
148
- });
149
-
150
- this.setState({
151
- tileset3d,
152
- layerMap: {}
153
- });
154
-
155
- //@ts-expect-error call of private method of the base class
156
- super._updateTileset(this.state.activeViewports);
157
- this.props.onTilesetLoad(tileset3d);
158
- }
159
-
160
- private override _onTileLoad(tileHeader: Tile3D): void {
161
- const {lastUpdatedViewports} = this.state;
162
- // New code ------------------
163
- this._colorizeTiles([tileHeader]);
164
- this._filterTiles([tileHeader]);
165
- // ---------------------------
166
- this.props.onTileLoad(tileHeader);
167
- // New code ------------------ condition is added
168
- if (!this.state.colorsByAttribute && !this.state.filtersByAttribute) {
169
- // ---------------------------
170
- //@ts-expect-error call of private method of the base class
171
- super._updateTileset(lastUpdatedViewports);
172
- this.setNeedsUpdate();
173
- // New code ------------------
174
- }
175
- // ------------------
176
- }
177
-
178
- private _onTraversalComplete(selectedTiles: Tile3D[]): Tile3D[] {
179
- this._colorizeTiles(selectedTiles);
180
- this._filterTiles(selectedTiles);
181
- return this.props.onTraversalComplete
182
- ? this.props.onTraversalComplete(selectedTiles)
183
- : selectedTiles;
184
- }
185
-
186
- private _colorizeTiles(tiles: Tile3D[]): void {
187
- if (this.props.customizeColors && tiles[0]?.type === TILE_TYPE.MESH) {
188
- const {layerMap, colorsByAttribute} = this.state;
189
- const promises: Promise<{isColored: boolean; id: string}>[] = [];
190
- for (const tile of tiles) {
191
- promises.push(this.props.customizeColors(tile, colorsByAttribute));
192
- }
193
- this.setState({
194
- loadingCounter: this.state.loadingCounter + 1
195
- });
196
- Promise.allSettled(promises).then((result) => {
197
- this.setState({
198
- loadingCounter: this.state.loadingCounter - 1
199
- });
200
- let isTileChanged = false;
201
- for (const item of result) {
202
- if (item.status === 'fulfilled' && item.value.isColored) {
203
- isTileChanged = true;
204
- delete layerMap[item.value.id];
205
- }
206
- }
207
- if (isTileChanged && !this.state.loadingCounter) {
208
- //@ts-expect-error call of private method of the base class
209
- super._updateTileset(this.state.activeViewports);
210
- this.setNeedsUpdate();
211
- }
212
- });
213
- }
214
- }
215
-
216
- private _colorizeTileset(): void {
217
- const {tileset3d} = this.state;
218
-
219
- if (tileset3d) {
220
- this._colorizeTiles(tileset3d.selectedTiles);
221
- }
222
- }
223
-
224
- private _filterTiles(tiles: Tile3D[]): void {
225
- if (this.props.filterTile && tiles[0]?.type === TILE_TYPE.MESH) {
226
- const {layerMap, filtersByAttribute} = this.state;
227
- const promises: Promise<{isFiltered: boolean; id: string}>[] = [];
228
- for (const tile of tiles) {
229
- promises.push(this.props.filterTile(tile, filtersByAttribute));
230
- }
231
- this.setState({
232
- loadingCounter: this.state.loadingCounter + 1
233
- });
234
- Promise.allSettled(promises).then((result) => {
235
- this.setState({
236
- loadingCounter: this.state.loadingCounter - 1
237
- });
238
- let isTileChanged = false;
239
- for (const item of result) {
240
- if (item.status === 'fulfilled' && item.value.isFiltered) {
241
- isTileChanged = true;
242
- delete layerMap[item.value.id];
243
- }
244
- }
245
- if (isTileChanged && !this.state.loadingCounter) {
246
- //@ts-expect-error call of private method of the base class
247
- super._updateTileset(this.state.activeViewports);
248
- this.setNeedsUpdate();
249
- }
250
- });
251
- }
252
- }
253
-
254
- private _filterTileset(): void {
255
- const {tileset3d} = this.state;
256
-
257
- if (tileset3d) {
258
- this._filterTiles(tileset3d.selectedTiles);
259
- }
260
- }
261
- }
@@ -1,53 +0,0 @@
1
- // deck.gl-community
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {customizeColors} from '@loaders.gl/i3s';
6
- import {Tile3D} from '@loaders.gl/tiles';
7
- import {ColorsByAttribute} from '../data-driven-tile-3d-layer';
8
-
9
- /**
10
- * Update tile colors with the custom colors assigned to the I3S Loader
11
- * @returns {Promise<{isColored: boolean; id: string}>} Result of the tile colorization - isColored: true/false and tile id
12
- */
13
- export const colorizeTile = async (
14
- tile: Tile3D,
15
- colorsByAttribute: ColorsByAttribute | null
16
- ): Promise<{isColored: boolean; id: string}> => {
17
- const result = {isColored: false, id: tile.id};
18
-
19
- if (tile.content.customColors !== colorsByAttribute) {
20
- if (tile.content && colorsByAttribute) {
21
- if (!tile.content.originalColorsAttributes) {
22
- tile.content.originalColorsAttributes = {
23
- ...tile.content.attributes.colors,
24
- value: new Uint8Array(tile.content.attributes.colors.value)
25
- };
26
- } else if (colorsByAttribute.mode === 'multiply') {
27
- tile.content.attributes.colors.value.set(tile.content.originalColorsAttributes.value);
28
- }
29
-
30
- tile.content.customColors = colorsByAttribute;
31
-
32
- const newColors = await customizeColors(
33
- tile.content.attributes.colors,
34
- tile.content.featureIds,
35
- tile.header.attributeUrls,
36
- tile.tileset.tileset.fields,
37
- tile.tileset.tileset.attributeStorageInfo,
38
- colorsByAttribute,
39
- (tile.tileset.loadOptions as any).i3s.token
40
- );
41
- // Make sure custom colors is not changed during async customizeColors execution
42
- if (tile.content.customColors === colorsByAttribute) {
43
- tile.content.attributes.colors = newColors;
44
- result.isColored = true;
45
- }
46
- } else if (tile.content && tile.content.originalColorsAttributes) {
47
- tile.content.attributes.colors.value = tile.content.originalColorsAttributes.value;
48
- tile.content.customColors = null;
49
- result.isColored = true;
50
- }
51
- }
52
- return result;
53
- };
@@ -1,179 +0,0 @@
1
- // deck.gl-community
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import {Tile3D} from '@loaders.gl/tiles';
6
- import {FiltersByAttribute} from '../data-driven-tile-3d-layer';
7
- import {AttributeStorageInfo, I3SAttributeLoader} from '@loaders.gl/i3s';
8
- import {load} from '@loaders.gl/core';
9
- import {TypedArray} from '@loaders.gl/schema';
10
-
11
- type I3STileAttributes = Record<string, string[] | TypedArray | null>;
12
-
13
- /**
14
- * Filter tile indices by attribute value
15
- * @param tile - tile to be filtered
16
- * @param filtersByAttribute - custom filters patameters
17
- * @returns {Promise<{isFiltered: boolean; id: string}>} Result of the tile filtering - isFiltered: true/false and tile id
18
- */
19
- export const filterTile = async (
20
- tile: Tile3D,
21
- filtersByAttribute: FiltersByAttribute | null
22
- ): Promise<{isFiltered: boolean; id: string}> => {
23
- const result = {isFiltered: false, id: tile.id};
24
-
25
- if (tile.content.userData?.customFilters !== filtersByAttribute) {
26
- if (tile.content && filtersByAttribute) {
27
- if (tile.content.userData?.originalIndices === undefined) {
28
- tile.content.userData = {};
29
- //save original indices for filtring cancellation
30
- tile.content.userData.originalIndices = tile.content.indices;
31
- }
32
- tile.content.indices = tile.content.userData?.originalIndices;
33
- tile.content.userData.customFilters = filtersByAttribute;
34
-
35
- const {indices} = await filterTileIndices(
36
- tile,
37
- filtersByAttribute,
38
- (tile.tileset.loadOptions as any).i3s.token
39
- );
40
- // Make sure custom filters is not changed during async filtring execution
41
- if (indices && tile.content.userData.customFilters === filtersByAttribute) {
42
- tile.content.indices = indices;
43
- result.isFiltered = true;
44
- }
45
- } else if (tile.content && tile.content.userData?.originalIndices !== undefined) {
46
- tile.content.indices = tile.content.userData.originalIndices;
47
- tile.content.userData.customFilters = null;
48
- result.isFiltered = true;
49
- }
50
- }
51
- return result;
52
- };
53
-
54
- async function filterTileIndices(
55
- tile: Tile3D,
56
- filtersByAttribute: FiltersByAttribute,
57
- token: string
58
- ): Promise<{success: boolean; indices?: Uint32Array}> {
59
- if (!filtersByAttribute.attributeName.length) {
60
- return {success: false};
61
- }
62
-
63
- const filterAttributeField = tile.tileset.tileset.fields.find(
64
- ({name}) => name === filtersByAttribute?.attributeName
65
- );
66
-
67
- if (
68
- !filterAttributeField ||
69
- !['esriFieldTypeDouble', 'esriFieldTypeInteger', 'esriFieldTypeSmallInteger'].includes(
70
- filterAttributeField.type
71
- )
72
- ) {
73
- return {success: false};
74
- }
75
-
76
- const tileFilterAttributeData = await loadFeatureAttributeData(
77
- filterAttributeField.name,
78
- tile.header.attributeUrls,
79
- tile.tileset.tileset.attributeStorageInfo,
80
- token
81
- );
82
- if (!tileFilterAttributeData) {
83
- return {success: false};
84
- }
85
-
86
- const objectIdField = tile.tileset.tileset.fields.find(({type}) => type === 'esriFieldTypeOID');
87
- if (!objectIdField) {
88
- return {success: false};
89
- }
90
-
91
- const objectIdAttributeData = await loadFeatureAttributeData(
92
- objectIdField.name,
93
- tile.header.attributeUrls,
94
- tile.tileset.tileset.attributeStorageInfo,
95
- token
96
- );
97
- if (!objectIdAttributeData) {
98
- return {success: false};
99
- }
100
-
101
- const attributeValuesMap = {};
102
- objectIdAttributeData[objectIdField.name]?.forEach((elem, index) => {
103
- attributeValuesMap[elem] =
104
- //@ts-expect-error possible null
105
- tileFilterAttributeData[filterAttributeField.name][index];
106
- });
107
-
108
- if (!tile.content.indices) {
109
- const triangles: number[] = [];
110
- for (let i = 0; i < tile.content.featureIds.length; i += 3) {
111
- if (attributeValuesMap[tile.content.featureIds[i]] === filtersByAttribute.value) {
112
- triangles.push(i);
113
- }
114
- }
115
-
116
- const indices = new Uint32Array(3 * triangles.length);
117
-
118
- triangles.forEach((vertex, index) => {
119
- indices[index * 3] = vertex;
120
- indices[index * 3 + 1] = vertex + 1;
121
- indices[index * 3 + 2] = vertex + 2;
122
- });
123
- return {success: true, indices};
124
- } else {
125
- const triangles: number[] = [];
126
- for (let i = 0; i < tile.content.indices.length; i += 3) {
127
- if (
128
- attributeValuesMap[tile.content.featureIds[tile.content.indices[i]]] ===
129
- filtersByAttribute.value
130
- ) {
131
- triangles.push(i);
132
- }
133
- }
134
-
135
- const indices = new Uint32Array(3 * triangles.length);
136
-
137
- triangles.forEach((vertex, index) => {
138
- indices[index * 3] = tile.content.indices[vertex];
139
- indices[index * 3 + 1] = tile.content.indices[vertex + 1];
140
- indices[index * 3 + 2] = tile.content.indices[vertex + 2];
141
- });
142
- return {success: true, indices};
143
- }
144
- }
145
-
146
- async function loadFeatureAttributeData(
147
- attributeName: string,
148
- attributeUrls: string[],
149
- attributesStorageInfo: AttributeStorageInfo[],
150
- token?: string
151
- ): Promise<I3STileAttributes | null> {
152
- const attributeIndex = attributesStorageInfo.findIndex(({name}) => attributeName === name);
153
- if (attributeIndex === -1) {
154
- return null;
155
- }
156
- const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], token);
157
- const attributeType = getAttributeValueType(attributesStorageInfo[attributeIndex]);
158
- const objectIdAttributeData = await load(objectIdAttributeUrl, I3SAttributeLoader, {
159
- attributeName,
160
- attributeType
161
- });
162
-
163
- return objectIdAttributeData;
164
- }
165
-
166
- function getUrlWithToken(url: string, token: string | null = null): string {
167
- return token ? `${url}?token=${token}` : url;
168
- }
169
-
170
- function getAttributeValueType(attribute: AttributeStorageInfo) {
171
- // eslint-disable-next-line no-prototype-builtins
172
- if (attribute.hasOwnProperty('objectIds')) {
173
- return 'Oid32';
174
- // eslint-disable-next-line no-prototype-builtins
175
- } else if (attribute.hasOwnProperty('attributeValues')) {
176
- return attribute.attributeValues?.valueType;
177
- }
178
- return '';
179
- }