@deck.gl-community/experimental 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.
- package/LICENSE +20 -0
- package/README.md +5 -0
- package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.d.ts +65 -0
- package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.d.ts.map +1 -0
- package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js +188 -0
- package/dist/data-driven-tile-3d-layer/utils/colorize-tile.d.ts +11 -0
- package/dist/data-driven-tile-3d-layer/utils/colorize-tile.d.ts.map +1 -0
- package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js +37 -0
- package/dist/data-driven-tile-3d-layer/utils/filter-tile.d.ts +13 -0
- package/dist/data-driven-tile-3d-layer/utils/filter-tile.d.ts.map +1 -0
- package/dist/data-driven-tile-3d-layer/utils/filter-tile.js +120 -0
- package/dist/index.cjs +338 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/package.json +48 -0
- package/src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts +260 -0
- package/src/data-driven-tile-3d-layer/utils/colorize-tile.ts +53 -0
- package/src/data-driven-tile-3d-layer/utils/filter-tile.ts +177 -0
- package/src/index.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2015 - 2021 Uber Technologies, Inc.
|
|
2
|
+
Copyright (c) 2022 - 2023 react-graph-layers contributors
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Tile3DLayer } from '@deck.gl/geo-layers';
|
|
2
|
+
import { UpdateParameters, Viewport } from '@deck.gl/core';
|
|
3
|
+
import { Tile3D, Tileset3D } from '@loaders.gl/tiles';
|
|
4
|
+
type _DataDrivenTile3DLayerProps = {
|
|
5
|
+
onTraversalComplete?: (selectedTiles: Tile3D[]) => Tile3D[];
|
|
6
|
+
colorsByAttribute?: ColorsByAttribute | null;
|
|
7
|
+
customizeColors?: (tile: Tile3D, colorsByAttribute: ColorsByAttribute | null) => Promise<{
|
|
8
|
+
isColored: boolean;
|
|
9
|
+
id: string;
|
|
10
|
+
}>;
|
|
11
|
+
filtersByAttribute?: FiltersByAttribute | null;
|
|
12
|
+
filterTile?: (tile: Tile3D, filtersByAttribute: FiltersByAttribute | null) => Promise<{
|
|
13
|
+
isFiltered: boolean;
|
|
14
|
+
id: string;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
export type ColorsByAttribute = {
|
|
18
|
+
/** Feature attribute name */
|
|
19
|
+
attributeName: string;
|
|
20
|
+
/** Minimum attribute value */
|
|
21
|
+
minValue: number;
|
|
22
|
+
/** Maximum attribute value */
|
|
23
|
+
maxValue: number;
|
|
24
|
+
/** Minimum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */
|
|
25
|
+
minColor: [number, number, number, number];
|
|
26
|
+
/** Maximum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */
|
|
27
|
+
maxColor: [number, number, number, number];
|
|
28
|
+
/** Colorization mode. `replace` - replace vertex colors with a new colors, `multiply` - multiply vertex colors with new colors */
|
|
29
|
+
mode: string;
|
|
30
|
+
};
|
|
31
|
+
export type FiltersByAttribute = {
|
|
32
|
+
/** Feature attribute name */
|
|
33
|
+
attributeName: string;
|
|
34
|
+
/** Filter value */
|
|
35
|
+
value: number;
|
|
36
|
+
};
|
|
37
|
+
export declare class DataDrivenTile3DLayer<DataT = any, ExtraProps extends Record<string, unknown> = Record<string, unknown>> extends Tile3DLayer<DataT, Required<_DataDrivenTile3DLayerProps> & ExtraProps> {
|
|
38
|
+
static layerName: string;
|
|
39
|
+
static defaultProps: any;
|
|
40
|
+
state: {
|
|
41
|
+
activeViewports: any;
|
|
42
|
+
frameNumber?: number;
|
|
43
|
+
lastUpdatedViewports: {
|
|
44
|
+
[viewportId: string]: Viewport;
|
|
45
|
+
} | null;
|
|
46
|
+
layerMap: {
|
|
47
|
+
[layerId: string]: any;
|
|
48
|
+
};
|
|
49
|
+
tileset3d: Tileset3D | null;
|
|
50
|
+
colorsByAttribute: ColorsByAttribute | null;
|
|
51
|
+
filtersByAttribute: FiltersByAttribute | null;
|
|
52
|
+
loadingCounter: number;
|
|
53
|
+
};
|
|
54
|
+
initializeState(): void;
|
|
55
|
+
updateState(params: UpdateParameters<this>): void;
|
|
56
|
+
private _loadTileset;
|
|
57
|
+
private _onTileLoad;
|
|
58
|
+
private _onTraversalComplete;
|
|
59
|
+
private _colorizeTiles;
|
|
60
|
+
private _colorizeTileset;
|
|
61
|
+
private _filterTiles;
|
|
62
|
+
private _filterTileset;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=data-driven-tile-3d-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-driven-tile-3d-layer.d.ts","sourceRoot":"","sources":["../../src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,WAAW,EAAmB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAC,gBAAgB,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAC;AACvE,OAAO,EAAY,MAAM,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAW/D,KAAK,2BAA2B,GAAG;IACjC,mBAAmB,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;IAC5D,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC7C,eAAe,CAAC,EAAE,CAChB,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,KACxC,OAAO,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;IAC/C,kBAAkB,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC/C,UAAU,CAAC,EAAE,CACX,IAAI,EAAE,MAAM,EACZ,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,KAC1C,OAAO,CAAC;QAAC,UAAU,EAAE,OAAO,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,2FAA2F;IAC3F,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,2FAA2F;IAC3F,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,kIAAkI;IAClI,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,6BAA6B;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAGF,qBAAa,qBAAqB,CAChC,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACpE,SAAQ,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,2BAA2B,CAAC,GAAG,UAAU,CAAC;IAC9E,MAAM,CAAC,SAAS,SAA2B;IAC3C,MAAM,CAAC,YAAY,EAAmB,GAAG,CAAC;IAE1C,KAAK,EAAE;QACL,eAAe,EAAE,GAAG,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,oBAAoB,EAAE;YAAC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAA;SAAC,GAAG,IAAI,CAAC;QAC9D,QAAQ,EAAE;YAAC,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;SAAC,CAAC;QACnC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;QAE5B,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,CAAC;QAC5C,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,CAAC;QAC9C,cAAc,EAAE,MAAM,CAAC;KACxB,CAAc;IAEf,eAAe;IAUf,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;YA+B1B,YAAY;YA4ClB,WAAW;IAkB5B,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,cAAc;IA8BtB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,YAAY;IA8BpB,OAAO,CAAC,cAAc;CAOvB"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Tile3DLayer } from '@deck.gl/geo-layers';
|
|
5
|
+
import { TILE_TYPE, Tileset3D } from '@loaders.gl/tiles';
|
|
6
|
+
import { load } from '@loaders.gl/core';
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
colorsByAttribute: null,
|
|
9
|
+
filtersByAttribute: null
|
|
10
|
+
};
|
|
11
|
+
// @ts-expect-error call of private method of the base class
|
|
12
|
+
export class DataDrivenTile3DLayer extends Tile3DLayer {
|
|
13
|
+
static layerName = 'DataDrivenTile3DLayer';
|
|
14
|
+
static defaultProps = defaultProps;
|
|
15
|
+
state = undefined;
|
|
16
|
+
initializeState() {
|
|
17
|
+
super.initializeState();
|
|
18
|
+
this.setState({
|
|
19
|
+
colorsByAttribute: this.props.colorsByAttribute,
|
|
20
|
+
filtersByAttribute: this.props.filtersByAttribute,
|
|
21
|
+
loadingCounter: 0
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
updateState(params) {
|
|
25
|
+
const { props, oldProps, changeFlags } = params;
|
|
26
|
+
if (props.data && props.data !== oldProps.data) {
|
|
27
|
+
this._loadTileset(props.data);
|
|
28
|
+
}
|
|
29
|
+
else if (props.colorsByAttribute !== oldProps.colorsByAttribute) {
|
|
30
|
+
this.setState({
|
|
31
|
+
colorsByAttribute: props.colorsByAttribute
|
|
32
|
+
});
|
|
33
|
+
this._colorizeTileset();
|
|
34
|
+
}
|
|
35
|
+
else if (props.filtersByAttribute !== oldProps.filtersByAttribute) {
|
|
36
|
+
this.setState({
|
|
37
|
+
filtersByAttribute: props.filtersByAttribute
|
|
38
|
+
});
|
|
39
|
+
this._filterTileset();
|
|
40
|
+
}
|
|
41
|
+
else if (changeFlags.viewportChanged) {
|
|
42
|
+
const { activeViewports } = this.state;
|
|
43
|
+
const viewportsNumber = Object.keys(activeViewports).length;
|
|
44
|
+
if (viewportsNumber) {
|
|
45
|
+
if (!this.state.loadingCounter) {
|
|
46
|
+
// @ts-expect-error call of private method of the base class
|
|
47
|
+
super._updateTileset(activeViewports);
|
|
48
|
+
}
|
|
49
|
+
this.state.lastUpdatedViewports = activeViewports;
|
|
50
|
+
this.state.activeViewports = {};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
super.updateState(params);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async _loadTileset(tilesetUrl) {
|
|
58
|
+
const { loadOptions = {} } = this.props;
|
|
59
|
+
// TODO: deprecate `loader` in v9.0
|
|
60
|
+
let loader = this.props.loader || this.props.loaders;
|
|
61
|
+
if (Array.isArray(loader)) {
|
|
62
|
+
loader = loader[0];
|
|
63
|
+
}
|
|
64
|
+
const options = { loadOptions: { ...loadOptions } };
|
|
65
|
+
if (loader.preload) {
|
|
66
|
+
const preloadOptions = await loader.preload(tilesetUrl, loadOptions);
|
|
67
|
+
if (preloadOptions.headers) {
|
|
68
|
+
options.loadOptions.fetch = {
|
|
69
|
+
...options.loadOptions.fetch,
|
|
70
|
+
headers: preloadOptions.headers
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
Object.assign(options, preloadOptions);
|
|
74
|
+
}
|
|
75
|
+
const tilesetJson = await load(tilesetUrl, loader, options.loadOptions);
|
|
76
|
+
const tileset3d = new Tileset3D(tilesetJson, {
|
|
77
|
+
onTileLoad: this._onTileLoad.bind(this),
|
|
78
|
+
// @ts-expect-error call of private method of the base class
|
|
79
|
+
onTileUnload: super._onTileUnload.bind(this),
|
|
80
|
+
onTileError: this.props.onTileError,
|
|
81
|
+
// New code ------------------
|
|
82
|
+
onTraversalComplete: this._onTraversalComplete.bind(this),
|
|
83
|
+
// ---------------------------
|
|
84
|
+
...options
|
|
85
|
+
});
|
|
86
|
+
this.setState({
|
|
87
|
+
tileset3d,
|
|
88
|
+
layerMap: {}
|
|
89
|
+
});
|
|
90
|
+
// @ts-expect-error call of private method of the base class
|
|
91
|
+
super._updateTileset(this.state.activeViewports);
|
|
92
|
+
this.props.onTilesetLoad(tileset3d);
|
|
93
|
+
}
|
|
94
|
+
_onTileLoad(tileHeader) {
|
|
95
|
+
const { lastUpdatedViewports } = this.state;
|
|
96
|
+
// New code ------------------
|
|
97
|
+
this._colorizeTiles([tileHeader]);
|
|
98
|
+
this._filterTiles([tileHeader]);
|
|
99
|
+
// ---------------------------
|
|
100
|
+
this.props.onTileLoad(tileHeader);
|
|
101
|
+
// New code ------------------ condition is added
|
|
102
|
+
if (!this.state.colorsByAttribute && !this.state.filtersByAttribute) {
|
|
103
|
+
// ---------------------------
|
|
104
|
+
// @ts-expect-error call of private method of the base class
|
|
105
|
+
super._updateTileset(lastUpdatedViewports);
|
|
106
|
+
this.setNeedsUpdate();
|
|
107
|
+
// New code ------------------
|
|
108
|
+
}
|
|
109
|
+
// ------------------
|
|
110
|
+
}
|
|
111
|
+
_onTraversalComplete(selectedTiles) {
|
|
112
|
+
this._colorizeTiles(selectedTiles);
|
|
113
|
+
this._filterTiles(selectedTiles);
|
|
114
|
+
return this.props.onTraversalComplete
|
|
115
|
+
? this.props.onTraversalComplete(selectedTiles)
|
|
116
|
+
: selectedTiles;
|
|
117
|
+
}
|
|
118
|
+
_colorizeTiles(tiles) {
|
|
119
|
+
if (this.props.customizeColors && tiles[0]?.type === TILE_TYPE.MESH) {
|
|
120
|
+
const { layerMap, colorsByAttribute } = this.state;
|
|
121
|
+
const promises = [];
|
|
122
|
+
for (const tile of tiles) {
|
|
123
|
+
promises.push(this.props.customizeColors(tile, colorsByAttribute));
|
|
124
|
+
}
|
|
125
|
+
this.setState({
|
|
126
|
+
loadingCounter: this.state.loadingCounter + 1
|
|
127
|
+
});
|
|
128
|
+
Promise.allSettled(promises).then((result) => {
|
|
129
|
+
this.setState({
|
|
130
|
+
loadingCounter: this.state.loadingCounter - 1
|
|
131
|
+
});
|
|
132
|
+
let isTileChanged = false;
|
|
133
|
+
for (const item of result) {
|
|
134
|
+
if (item.status === 'fulfilled' && item.value.isColored) {
|
|
135
|
+
isTileChanged = true;
|
|
136
|
+
delete layerMap[item.value.id];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (isTileChanged && !this.state.loadingCounter) {
|
|
140
|
+
// @ts-expect-error call of private method of the base class
|
|
141
|
+
super._updateTileset(this.state.activeViewports);
|
|
142
|
+
this.setNeedsUpdate();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_colorizeTileset() {
|
|
148
|
+
const { tileset3d } = this.state;
|
|
149
|
+
if (tileset3d) {
|
|
150
|
+
this._colorizeTiles(tileset3d.selectedTiles);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
_filterTiles(tiles) {
|
|
154
|
+
if (this.props.filterTile && tiles[0]?.type === TILE_TYPE.MESH) {
|
|
155
|
+
const { layerMap, filtersByAttribute } = this.state;
|
|
156
|
+
const promises = [];
|
|
157
|
+
for (const tile of tiles) {
|
|
158
|
+
promises.push(this.props.filterTile(tile, filtersByAttribute));
|
|
159
|
+
}
|
|
160
|
+
this.setState({
|
|
161
|
+
loadingCounter: this.state.loadingCounter + 1
|
|
162
|
+
});
|
|
163
|
+
Promise.allSettled(promises).then((result) => {
|
|
164
|
+
this.setState({
|
|
165
|
+
loadingCounter: this.state.loadingCounter - 1
|
|
166
|
+
});
|
|
167
|
+
let isTileChanged = false;
|
|
168
|
+
for (const item of result) {
|
|
169
|
+
if (item.status === 'fulfilled' && item.value.isFiltered) {
|
|
170
|
+
isTileChanged = true;
|
|
171
|
+
delete layerMap[item.value.id];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (isTileChanged && !this.state.loadingCounter) {
|
|
175
|
+
// @ts-expect-error call of private method of the base class
|
|
176
|
+
super._updateTileset(this.state.activeViewports);
|
|
177
|
+
this.setNeedsUpdate();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
_filterTileset() {
|
|
183
|
+
const { tileset3d } = this.state;
|
|
184
|
+
if (tileset3d) {
|
|
185
|
+
this._filterTiles(tileset3d.selectedTiles);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Tile3D } from '@loaders.gl/tiles';
|
|
2
|
+
import { ColorsByAttribute } from "../data-driven-tile-3d-layer.js";
|
|
3
|
+
/**
|
|
4
|
+
* Update tile colors with the custom colors assigned to the I3S Loader
|
|
5
|
+
* @returns {Promise<{isColored: boolean; id: string}>} Result of the tile colorization - isColored: true/false and tile id
|
|
6
|
+
*/
|
|
7
|
+
export declare const colorizeTile: (tile: Tile3D, colorsByAttribute: ColorsByAttribute | null) => Promise<{
|
|
8
|
+
isColored: boolean;
|
|
9
|
+
id: string;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=colorize-tile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorize-tile.d.ts","sourceRoot":"","sources":["../../../src/data-driven-tile-3d-layer/utils/colorize-tile.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAC,wCAAqC;AAE/D;;;GAGG;AACH,eAAO,MAAM,YAAY,SACjB,MAAM,qBACO,iBAAiB,GAAG,IAAI,KAC1C,OAAO,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,CAqC1C,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { customizeColors } from '@loaders.gl/i3s';
|
|
5
|
+
/**
|
|
6
|
+
* Update tile colors with the custom colors assigned to the I3S Loader
|
|
7
|
+
* @returns {Promise<{isColored: boolean; id: string}>} Result of the tile colorization - isColored: true/false and tile id
|
|
8
|
+
*/
|
|
9
|
+
export const colorizeTile = async (tile, colorsByAttribute) => {
|
|
10
|
+
const result = { isColored: false, id: tile.id };
|
|
11
|
+
if (tile.content.customColors !== colorsByAttribute) {
|
|
12
|
+
if (tile.content && colorsByAttribute) {
|
|
13
|
+
if (!tile.content.originalColorsAttributes) {
|
|
14
|
+
tile.content.originalColorsAttributes = {
|
|
15
|
+
...tile.content.attributes.colors,
|
|
16
|
+
value: new Uint8Array(tile.content.attributes.colors.value)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else if (colorsByAttribute.mode === 'multiply') {
|
|
20
|
+
tile.content.attributes.colors.value.set(tile.content.originalColorsAttributes.value);
|
|
21
|
+
}
|
|
22
|
+
tile.content.customColors = colorsByAttribute;
|
|
23
|
+
const newColors = await customizeColors(tile.content.attributes.colors, tile.content.featureIds, tile.header.attributeUrls, tile.tileset.tileset.fields, tile.tileset.tileset.attributeStorageInfo, colorsByAttribute, tile.tileset.loadOptions.i3s.token);
|
|
24
|
+
// Make sure custom colors is not changed during async customizeColors execution
|
|
25
|
+
if (tile.content.customColors === colorsByAttribute) {
|
|
26
|
+
tile.content.attributes.colors = newColors;
|
|
27
|
+
result.isColored = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (tile.content && tile.content.originalColorsAttributes) {
|
|
31
|
+
tile.content.attributes.colors.value = tile.content.originalColorsAttributes.value;
|
|
32
|
+
tile.content.customColors = null;
|
|
33
|
+
result.isColored = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Tile3D } from '@loaders.gl/tiles';
|
|
2
|
+
import { FiltersByAttribute } from "../data-driven-tile-3d-layer.js";
|
|
3
|
+
/**
|
|
4
|
+
* Filter tile indices by attribute value
|
|
5
|
+
* @param tile - tile to be filtered
|
|
6
|
+
* @param filtersByAttribute - custom filters patameters
|
|
7
|
+
* @returns {Promise<{isFiltered: boolean; id: string}>} Result of the tile filtering - isFiltered: true/false and tile id
|
|
8
|
+
*/
|
|
9
|
+
export declare const filterTile: (tile: Tile3D, filtersByAttribute: FiltersByAttribute | null) => Promise<{
|
|
10
|
+
isFiltered: boolean;
|
|
11
|
+
id: string;
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=filter-tile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-tile.d.ts","sourceRoot":"","sources":["../../../src/data-driven-tile-3d-layer/utils/filter-tile.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAC,kBAAkB,EAAC,wCAAqC;AAOhE;;;;;GAKG;AACH,eAAO,MAAM,UAAU,SACf,MAAM,sBACQ,kBAAkB,GAAG,IAAI,KAC5C,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,CA8B3C,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { I3SAttributeLoader } from '@loaders.gl/i3s';
|
|
5
|
+
import { load } from '@loaders.gl/core';
|
|
6
|
+
/**
|
|
7
|
+
* Filter tile indices by attribute value
|
|
8
|
+
* @param tile - tile to be filtered
|
|
9
|
+
* @param filtersByAttribute - custom filters patameters
|
|
10
|
+
* @returns {Promise<{isFiltered: boolean; id: string}>} Result of the tile filtering - isFiltered: true/false and tile id
|
|
11
|
+
*/
|
|
12
|
+
export const filterTile = async (tile, filtersByAttribute) => {
|
|
13
|
+
const result = { isFiltered: false, id: tile.id };
|
|
14
|
+
if (tile.content.userData?.customFilters !== filtersByAttribute) {
|
|
15
|
+
if (tile.content && filtersByAttribute) {
|
|
16
|
+
if (tile.content.userData?.originalIndices === undefined) {
|
|
17
|
+
tile.content.userData = {};
|
|
18
|
+
// save original indices for filtring cancellation
|
|
19
|
+
tile.content.userData.originalIndices = tile.content.indices;
|
|
20
|
+
}
|
|
21
|
+
tile.content.indices = tile.content.userData?.originalIndices;
|
|
22
|
+
tile.content.userData.customFilters = filtersByAttribute;
|
|
23
|
+
const { indices } = await filterTileIndices(tile, filtersByAttribute, tile.tileset.loadOptions.i3s.token);
|
|
24
|
+
// Make sure custom filters is not changed during async filtring execution
|
|
25
|
+
if (indices && tile.content.userData.customFilters === filtersByAttribute) {
|
|
26
|
+
tile.content.indices = indices;
|
|
27
|
+
result.isFiltered = true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (tile.content && tile.content.userData?.originalIndices !== undefined) {
|
|
31
|
+
tile.content.indices = tile.content.userData.originalIndices;
|
|
32
|
+
tile.content.userData.customFilters = null;
|
|
33
|
+
result.isFiltered = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
// eslint-disable-next-line max-statements, complexity
|
|
39
|
+
async function filterTileIndices(tile, filtersByAttribute, token) {
|
|
40
|
+
if (!filtersByAttribute.attributeName.length) {
|
|
41
|
+
return { success: false };
|
|
42
|
+
}
|
|
43
|
+
const filterAttributeField = tile.tileset.tileset.fields.find(({ name }) => name === filtersByAttribute?.attributeName);
|
|
44
|
+
if (!filterAttributeField ||
|
|
45
|
+
!['esriFieldTypeDouble', 'esriFieldTypeInteger', 'esriFieldTypeSmallInteger'].includes(filterAttributeField.type)) {
|
|
46
|
+
return { success: false };
|
|
47
|
+
}
|
|
48
|
+
const tileFilterAttributeData = await loadFeatureAttributeData(filterAttributeField.name, tile.header.attributeUrls, tile.tileset.tileset.attributeStorageInfo, token);
|
|
49
|
+
if (!tileFilterAttributeData) {
|
|
50
|
+
return { success: false };
|
|
51
|
+
}
|
|
52
|
+
const objectIdField = tile.tileset.tileset.fields.find(({ type }) => type === 'esriFieldTypeOID');
|
|
53
|
+
if (!objectIdField) {
|
|
54
|
+
return { success: false };
|
|
55
|
+
}
|
|
56
|
+
const objectIdAttributeData = await loadFeatureAttributeData(objectIdField.name, tile.header.attributeUrls, tile.tileset.tileset.attributeStorageInfo, token);
|
|
57
|
+
if (!objectIdAttributeData) {
|
|
58
|
+
return { success: false };
|
|
59
|
+
}
|
|
60
|
+
const attributeValuesMap = {};
|
|
61
|
+
objectIdAttributeData[objectIdField.name]?.forEach((elem, index) => {
|
|
62
|
+
attributeValuesMap[elem] = tileFilterAttributeData[filterAttributeField.name][index];
|
|
63
|
+
});
|
|
64
|
+
if (!tile.content.indices) {
|
|
65
|
+
const triangles = [];
|
|
66
|
+
for (let i = 0; i < tile.content.featureIds.length; i += 3) {
|
|
67
|
+
if (attributeValuesMap[tile.content.featureIds[i]] === filtersByAttribute.value) {
|
|
68
|
+
triangles.push(i);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const indices = new Uint32Array(3 * triangles.length);
|
|
72
|
+
triangles.forEach((vertex, index) => {
|
|
73
|
+
indices[index * 3] = vertex;
|
|
74
|
+
indices[index * 3 + 1] = vertex + 1;
|
|
75
|
+
indices[index * 3 + 2] = vertex + 2;
|
|
76
|
+
});
|
|
77
|
+
return { success: true, indices };
|
|
78
|
+
}
|
|
79
|
+
const triangles = [];
|
|
80
|
+
for (let i = 0; i < tile.content.indices.length; i += 3) {
|
|
81
|
+
if (attributeValuesMap[tile.content.featureIds[tile.content.indices[i]]] ===
|
|
82
|
+
filtersByAttribute.value) {
|
|
83
|
+
triangles.push(i);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const indices = new Uint32Array(3 * triangles.length);
|
|
87
|
+
triangles.forEach((vertex, index) => {
|
|
88
|
+
indices[index * 3] = tile.content.indices[vertex];
|
|
89
|
+
indices[index * 3 + 1] = tile.content.indices[vertex + 1];
|
|
90
|
+
indices[index * 3 + 2] = tile.content.indices[vertex + 2];
|
|
91
|
+
});
|
|
92
|
+
return { success: true, indices };
|
|
93
|
+
}
|
|
94
|
+
async function loadFeatureAttributeData(attributeName, attributeUrls, attributesStorageInfo, token) {
|
|
95
|
+
const attributeIndex = attributesStorageInfo.findIndex(({ name }) => attributeName === name);
|
|
96
|
+
if (attributeIndex === -1) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], token);
|
|
100
|
+
const attributeType = getAttributeValueType(attributesStorageInfo[attributeIndex]);
|
|
101
|
+
const objectIdAttributeData = await load(objectIdAttributeUrl, I3SAttributeLoader, {
|
|
102
|
+
attributeName,
|
|
103
|
+
attributeType
|
|
104
|
+
});
|
|
105
|
+
return objectIdAttributeData;
|
|
106
|
+
}
|
|
107
|
+
function getUrlWithToken(url, token = null) {
|
|
108
|
+
return token ? `${url}?token=${token}` : url;
|
|
109
|
+
}
|
|
110
|
+
function getAttributeValueType(attribute) {
|
|
111
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
112
|
+
if (attribute.hasOwnProperty('objectIds')) {
|
|
113
|
+
return 'Oid32';
|
|
114
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
115
|
+
}
|
|
116
|
+
else if (attribute.hasOwnProperty('attributeValues')) {
|
|
117
|
+
return attribute.attributeValues?.valueType;
|
|
118
|
+
}
|
|
119
|
+
return '';
|
|
120
|
+
}
|