@deck.gl-community/layers 9.0.0-alpha.1 → 9.0.2
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/dist/index.cjs +605 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -5
- package/dist/path-marker-layer/arrow-2d-geometry.d.ts +4 -0
- package/dist/path-marker-layer/arrow-2d-geometry.js +58 -0
- package/dist/path-marker-layer/create-path-markers.d.ts +18 -0
- package/dist/path-marker-layer/create-path-markers.js +78 -0
- package/dist/path-marker-layer/path-marker-layer.d.ts +40 -0
- package/dist/path-marker-layer/path-marker-layer.js +124 -0
- package/dist/path-marker-layer/polyline.d.ts +18 -0
- package/dist/path-marker-layer/polyline.js +40 -0
- package/dist/path-outline-layer/outline.d.ts +8 -0
- package/dist/path-outline-layer/outline.js +100 -0
- package/dist/path-outline-layer/path-outline-layer.d.ts +34 -0
- package/dist/path-outline-layer/path-outline-layer.js +116 -0
- package/dist/tile-source-layer/tile-source-layer.d.ts +43 -0
- package/dist/tile-source-layer/tile-source-layer.js +109 -0
- package/package.json +27 -13
- package/src/index.ts +7 -4
- package/src/path-marker-layer/arrow-2d-geometry.ts +65 -0
- package/src/path-marker-layer/create-path-markers.ts +122 -0
- package/src/path-marker-layer/path-marker-layer.ts +183 -0
- package/src/path-marker-layer/polyline.ts +44 -0
- package/src/path-outline-layer/outline.ts +107 -0
- package/src/path-outline-layer/path-outline-layer.ts +159 -0
- package/src/{tile-source-layer.ts → tile-source-layer/tile-source-layer.ts} +30 -22
- package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js +0 -193
- package/dist/data-driven-tile-3d-layer/data-driven-tile-3d-layer.js.map +0 -1
- package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js +0 -31
- package/dist/data-driven-tile-3d-layer/utils/colorize-tile.js.map +0 -1
- package/dist/data-driven-tile-3d-layer/utils/filter-tile.js +0 -146
- package/dist/data-driven-tile-3d-layer/utils/filter-tile.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/tile-source-layer.js +0 -112
- package/dist/tile-source-layer.js.map +0 -1
- package/src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts +0 -261
- package/src/data-driven-tile-3d-layer/utils/colorize-tile.ts +0 -53
- package/src/data-driven-tile-3d-layer/utils/filter-tile.ts +0 -179
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ShaderModule} from '@luma.gl/shadertools';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable camelcase */
|
|
8
|
+
const INITIAL_STATE: Record<string, any> = {
|
|
9
|
+
outlineEnabled: false,
|
|
10
|
+
outlineRenderShadowmap: false,
|
|
11
|
+
outlineShadowmap: null
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function getUniforms({outlineEnabled, outlineRenderShadowmap, outlineShadowmap} = INITIAL_STATE) {
|
|
15
|
+
const uniforms: Record<string, any> = {};
|
|
16
|
+
if (outlineEnabled !== undefined) {
|
|
17
|
+
// ? 1.0 : 0.0;
|
|
18
|
+
uniforms.outline_uEnabled = outlineEnabled;
|
|
19
|
+
}
|
|
20
|
+
if (outlineRenderShadowmap !== undefined) {
|
|
21
|
+
// ? 1.0 : 0.0;
|
|
22
|
+
uniforms.outline_uRenderOutlines = outlineRenderShadowmap;
|
|
23
|
+
}
|
|
24
|
+
if (outlineShadowmap !== undefined) {
|
|
25
|
+
uniforms.outline_uShadowmap = outlineShadowmap;
|
|
26
|
+
}
|
|
27
|
+
return uniforms;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const vs = `\
|
|
31
|
+
#version 300 es
|
|
32
|
+
in float instanceZLevel;
|
|
33
|
+
out float outline_vzLevel;
|
|
34
|
+
out vec4 outline_vPosition;
|
|
35
|
+
|
|
36
|
+
// Set the z level for the outline shadowmap rendering
|
|
37
|
+
void outline_setZLevel(float zLevel) {
|
|
38
|
+
outline_vzLevel = zLevel;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Store an adjusted position for texture2DProj
|
|
42
|
+
void outline_setUV(vec4 position) {
|
|
43
|
+
// mat4(
|
|
44
|
+
// 0.5, 0.0, 0.0, 0.0,
|
|
45
|
+
// 0.0, 0.5, 0.0, 0.0,
|
|
46
|
+
// 0.0, 0.0, 0.5, 0.0,
|
|
47
|
+
// 0.5, 0.5, 0.5, 1.0
|
|
48
|
+
// ) * position;
|
|
49
|
+
outline_vPosition = vec4(position.xyz * 0.5 + position.w * 0.5, position.w);
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const fs = `\
|
|
54
|
+
uniform bool outline_uEnabled;
|
|
55
|
+
uniform bool outline_uRenderOutlines;
|
|
56
|
+
uniform sampler2D outline_uShadowmap;
|
|
57
|
+
|
|
58
|
+
in float outline_vzLevel;
|
|
59
|
+
// in vec2 outline_vUV;
|
|
60
|
+
in vec4 outline_vPosition;
|
|
61
|
+
|
|
62
|
+
out vec4 fragColor;
|
|
63
|
+
|
|
64
|
+
const float OUTLINE_Z_LEVEL_ERROR = 0.01;
|
|
65
|
+
|
|
66
|
+
// Return a darker color in shadowmap
|
|
67
|
+
vec4 outline_filterShadowColor(vec4 color) {
|
|
68
|
+
return vec4(outline_vzLevel / 255., outline_vzLevel / 255., outline_vzLevel / 255., 1.);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Return a darker color if in shadowmap
|
|
72
|
+
vec4 outline_filterDarkenColor(vec4 color) {
|
|
73
|
+
if (outline_uEnabled) {
|
|
74
|
+
float maxZLevel;
|
|
75
|
+
if (outline_vPosition.q > 0.0) {
|
|
76
|
+
maxZLevel = texture2DProj(outline_uShadowmap, outline_vPosition).r * 255.;
|
|
77
|
+
} else {
|
|
78
|
+
discard;
|
|
79
|
+
}
|
|
80
|
+
if (maxZLevel < outline_vzLevel + OUTLINE_Z_LEVEL_ERROR) {
|
|
81
|
+
vec4(color.rgb * 0.5, color.a);
|
|
82
|
+
} else {
|
|
83
|
+
discard;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return color;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// if enabled and rendering outlines - Render depth to shadowmap
|
|
90
|
+
// if enabled and rendering colors - Return a darker color if in shadowmap
|
|
91
|
+
// if disabled, just return color
|
|
92
|
+
vec4 outline_filterColor(vec4 color) {
|
|
93
|
+
if (outline_uEnabled) {
|
|
94
|
+
return outline_uRenderOutlines ?
|
|
95
|
+
outline_filterShadowColor(color) :
|
|
96
|
+
outline_filterDarkenColor(color);
|
|
97
|
+
}
|
|
98
|
+
return color;
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
export const outline = {
|
|
103
|
+
name: 'outline',
|
|
104
|
+
vs,
|
|
105
|
+
fs,
|
|
106
|
+
getUniforms
|
|
107
|
+
} as const satisfies ShaderModule;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// deck.gl-community
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {PathLayer, PathLayerProps} from '@deck.gl/layers';
|
|
6
|
+
import type {DefaultProps, LayerContext} from '@deck.gl/core';
|
|
7
|
+
import {GL} from '@luma.gl/constants';
|
|
8
|
+
import {Framebuffer, Texture} from '@luma.gl/core';
|
|
9
|
+
import {outline} from './outline';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Unit literal to shader unit number conversion.
|
|
13
|
+
*/
|
|
14
|
+
export const UNIT = {
|
|
15
|
+
common: 0,
|
|
16
|
+
meters: 1,
|
|
17
|
+
pixels: 2
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// TODO - this should be built into assembleShaders
|
|
21
|
+
function injectShaderCode({source, code = ''}) {
|
|
22
|
+
const INJECT_CODE = /}[^{}]*$/;
|
|
23
|
+
return source.replace(INJECT_CODE, code.concat('\n}\n'));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const VS_CODE = `\
|
|
27
|
+
outline_setUV(gl_Position);
|
|
28
|
+
outline_setZLevel(instanceZLevel);
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const FS_CODE = `\
|
|
32
|
+
fragColor = outline_filterColor(fragColor);
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export type PathOutlineLayerProps<DataT> = PathLayerProps<DataT> & {
|
|
36
|
+
dashJustified?: boolean;
|
|
37
|
+
getDashArray?: [number, number] | ((d: DataT) => [number, number] | null);
|
|
38
|
+
getZLevel?: (d: DataT, index: number) => number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const defaultProps: DefaultProps<PathOutlineLayerProps<any>> = {
|
|
42
|
+
getZLevel: () => 0
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class PathOutlineLayer<DataT = any, ExtraPropsT = Record<string, unknown>> extends PathLayer<
|
|
46
|
+
DataT,
|
|
47
|
+
ExtraPropsT & Required<PathOutlineLayerProps<DataT>>
|
|
48
|
+
> {
|
|
49
|
+
static layerName = 'PathOutlineLayer';
|
|
50
|
+
static defaultProps = defaultProps;
|
|
51
|
+
|
|
52
|
+
state: {
|
|
53
|
+
model?: any;
|
|
54
|
+
pathTesselator: any;
|
|
55
|
+
outlineFramebuffer: Framebuffer;
|
|
56
|
+
dummyTexture: Texture;
|
|
57
|
+
} = undefined!;
|
|
58
|
+
|
|
59
|
+
// Override getShaders to inject the outline module
|
|
60
|
+
getShaders() {
|
|
61
|
+
const shaders = super.getShaders();
|
|
62
|
+
return Object.assign({}, shaders, {
|
|
63
|
+
modules: shaders.modules.concat([outline]),
|
|
64
|
+
vs: injectShaderCode({source: shaders.vs, code: VS_CODE}),
|
|
65
|
+
fs: injectShaderCode({source: shaders.fs, code: FS_CODE})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error PathLayer is missing LayerContext arg
|
|
70
|
+
initializeState(context: LayerContext) {
|
|
71
|
+
super.initializeState();
|
|
72
|
+
|
|
73
|
+
// Create an outline "shadow" map
|
|
74
|
+
// TODO - we should create a single outlineMap for all layers
|
|
75
|
+
this.setState({
|
|
76
|
+
outlineFramebuffer: context.device.createFramebuffer({}),
|
|
77
|
+
dummyTexture: context.device.createTexture({})
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Create an attribute manager
|
|
81
|
+
// @ts-expect-error check whether this.getAttributeManager works here
|
|
82
|
+
this.state.attributeManager.addInstanced({
|
|
83
|
+
instanceZLevel: {
|
|
84
|
+
size: 1,
|
|
85
|
+
type: GL.UNSIGNED_BYTE,
|
|
86
|
+
accessor: 'getZLevel'
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Override draw to add render module
|
|
92
|
+
draw({moduleParameters = {}, parameters, uniforms, context}) {
|
|
93
|
+
// Need to calculate same uniforms as base layer
|
|
94
|
+
const {
|
|
95
|
+
jointRounded,
|
|
96
|
+
capRounded,
|
|
97
|
+
billboard,
|
|
98
|
+
miterLimit,
|
|
99
|
+
widthUnits,
|
|
100
|
+
widthScale,
|
|
101
|
+
widthMinPixels,
|
|
102
|
+
widthMaxPixels
|
|
103
|
+
} = this.props;
|
|
104
|
+
|
|
105
|
+
uniforms = Object.assign({}, uniforms, {
|
|
106
|
+
jointType: Number(jointRounded),
|
|
107
|
+
capType: Number(capRounded),
|
|
108
|
+
billboard,
|
|
109
|
+
widthUnits: UNIT[widthUnits],
|
|
110
|
+
widthScale,
|
|
111
|
+
miterLimit,
|
|
112
|
+
widthMinPixels,
|
|
113
|
+
widthMaxPixels
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Render the outline shadowmap (based on segment z orders)
|
|
117
|
+
const {outlineFramebuffer, dummyTexture} = this.state;
|
|
118
|
+
// TODO(v9): resize, see 'sf' example.
|
|
119
|
+
// outlineFramebuffer.resize();
|
|
120
|
+
// TODO(v9) clear FBO
|
|
121
|
+
// outlineFramebuffer.clear({ color: true, depth: true, stencil: true });
|
|
122
|
+
|
|
123
|
+
this.state.model.updateModuleSettings({
|
|
124
|
+
outlineEnabled: true,
|
|
125
|
+
outlineRenderShadowmap: true,
|
|
126
|
+
outlineShadowmap: dummyTexture
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
this.state.model.draw({
|
|
130
|
+
uniforms: Object.assign({}, uniforms, {
|
|
131
|
+
jointType: 0,
|
|
132
|
+
widthScale: this.props.widthScale * 1.3
|
|
133
|
+
}),
|
|
134
|
+
parameters: {
|
|
135
|
+
depthTest: false,
|
|
136
|
+
// Biggest value needs to go into buffer
|
|
137
|
+
blendEquation: GL.MAX
|
|
138
|
+
},
|
|
139
|
+
framebuffer: outlineFramebuffer
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Now use the outline shadowmap to render the lines (with outlines)
|
|
143
|
+
this.state.model.updateModuleSettings({
|
|
144
|
+
outlineEnabled: true,
|
|
145
|
+
outlineRenderShadowmap: false,
|
|
146
|
+
outlineShadowmap: outlineFramebuffer
|
|
147
|
+
});
|
|
148
|
+
this.state.model.draw({
|
|
149
|
+
uniforms: Object.assign({}, uniforms, {
|
|
150
|
+
jointType: Number(jointRounded),
|
|
151
|
+
capType: Number(capRounded),
|
|
152
|
+
widthScale: this.props.widthScale
|
|
153
|
+
}),
|
|
154
|
+
parameters: {
|
|
155
|
+
depthTest: false
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -11,7 +11,7 @@ import type {TileSource} from '@loaders.gl/loader-utils';
|
|
|
11
11
|
const devicePixelRatio = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
|
|
12
12
|
|
|
13
13
|
export type TileSourceLayerProps = TileLayerProps & {
|
|
14
|
-
tileSource: TileSource
|
|
14
|
+
tileSource: TileSource<any>;
|
|
15
15
|
showTileBorders?: boolean;
|
|
16
16
|
};
|
|
17
17
|
|
|
@@ -29,8 +29,8 @@ export class TileSourceLayer extends CompositeLayer<TileSourceLayerProps> {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
state: {
|
|
32
|
-
tileSource: TileSource | null;
|
|
33
|
-
}
|
|
32
|
+
tileSource: TileSource<any> | null;
|
|
33
|
+
} = undefined!;
|
|
34
34
|
|
|
35
35
|
initializeState() {
|
|
36
36
|
this.setState({
|
|
@@ -45,7 +45,7 @@ export class TileSourceLayer extends CompositeLayer<TileSourceLayerProps> {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
renderLayers() {
|
|
48
|
-
const {tileSource, showTileBorders, metadata, onTilesLoad} = this.props;
|
|
48
|
+
const {tileSource, showTileBorders, metadata, onTilesLoad} = this.props as any;
|
|
49
49
|
const minZoom = metadata?.minZoom || 0;
|
|
50
50
|
const maxZoom = metadata?.maxZoom || 30;
|
|
51
51
|
|
|
@@ -56,7 +56,7 @@ export class TileSourceLayer extends CompositeLayer<TileSourceLayerProps> {
|
|
|
56
56
|
getTileData: tileSource.getTileData,
|
|
57
57
|
// Assume the pmtiles file support HTTP/2, so we aren't limited by the browser to a certain number per domain.
|
|
58
58
|
maxRequests: 20,
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
pickable: true,
|
|
61
61
|
onViewportLoad: onTilesLoad,
|
|
62
62
|
autoHighlight: showTileBorders,
|
|
@@ -66,25 +66,29 @@ export class TileSourceLayer extends CompositeLayer<TileSourceLayerProps> {
|
|
|
66
66
|
tileSize: 256,
|
|
67
67
|
// TOOD - why is this needed?
|
|
68
68
|
zoomOffset: devicePixelRatio === 1 ? -1 : 0,
|
|
69
|
-
renderSubLayers,
|
|
70
|
-
|
|
69
|
+
renderSubLayers: renderSubLayers as any,
|
|
70
|
+
|
|
71
71
|
// Custom prop
|
|
72
72
|
tileSource,
|
|
73
73
|
showTileBorders
|
|
74
74
|
})
|
|
75
75
|
];
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function renderSubLayers(
|
|
79
|
+
function renderSubLayers(
|
|
80
|
+
props: TileSourceLayerProps & {tile: {index; bbox: {west; south; east; north}}}
|
|
81
|
+
) {
|
|
80
82
|
const {
|
|
81
|
-
tileSource,
|
|
82
|
-
showTileBorders,
|
|
83
|
+
tileSource,
|
|
84
|
+
showTileBorders,
|
|
83
85
|
minZoom,
|
|
84
86
|
maxZoom,
|
|
85
|
-
tile: {
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
tile: {
|
|
88
|
+
index: {z: zoom},
|
|
89
|
+
bbox: {west, south, east, north}
|
|
90
|
+
}
|
|
91
|
+
} = props as any;
|
|
88
92
|
|
|
89
93
|
const layers: Layer[] = [];
|
|
90
94
|
|
|
@@ -95,7 +99,7 @@ function renderSubLayers(props: TileSourceLayerProps & {tile: {index, bbox: {wes
|
|
|
95
99
|
layers.push(
|
|
96
100
|
new GeoJsonLayer({
|
|
97
101
|
id: `${props.id}-geojson`,
|
|
98
|
-
data: props.data,
|
|
102
|
+
data: props.data as any,
|
|
99
103
|
pickable: true,
|
|
100
104
|
getFillColor: [0, 190, 80, 255],
|
|
101
105
|
lineWidthScale: 500,
|
|
@@ -109,16 +113,20 @@ function renderSubLayers(props: TileSourceLayerProps & {tile: {index, bbox: {wes
|
|
|
109
113
|
case 'image/webp':
|
|
110
114
|
case 'image/avif':
|
|
111
115
|
layers.push(
|
|
112
|
-
new BitmapLayer(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
new BitmapLayer(
|
|
117
|
+
props as any,
|
|
118
|
+
{
|
|
119
|
+
data: null,
|
|
120
|
+
image: props.data,
|
|
121
|
+
bounds: [west, south, east, north],
|
|
122
|
+
pickable: true
|
|
123
|
+
} as any
|
|
124
|
+
)
|
|
118
125
|
);
|
|
119
126
|
break;
|
|
120
127
|
|
|
121
128
|
default:
|
|
129
|
+
// eslint-disable-next-line no-console
|
|
122
130
|
console.error('Unknown tile mimeType', tileSource?.mimeType);
|
|
123
131
|
}
|
|
124
132
|
|
|
@@ -137,7 +145,7 @@ function renderSubLayers(props: TileSourceLayerProps & {tile: {index, bbox: {wes
|
|
|
137
145
|
]
|
|
138
146
|
],
|
|
139
147
|
getPath: (d) => d,
|
|
140
|
-
getColor: borderColor,
|
|
148
|
+
getColor: borderColor as any,
|
|
141
149
|
widthMinPixels: 4
|
|
142
150
|
})
|
|
143
151
|
);
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { Tile3DLayer } from '@deck.gl/geo-layers';
|
|
2
|
-
import { TILE_TYPE, Tileset3D } from '@loaders.gl/tiles';
|
|
3
|
-
import { load } from '@loaders.gl/core';
|
|
4
|
-
const defaultProps = {
|
|
5
|
-
colorsByAttribute: null,
|
|
6
|
-
filtersByAttribute: null
|
|
7
|
-
};
|
|
8
|
-
export class DataDrivenTile3DLayer extends Tile3DLayer {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(...arguments);
|
|
11
|
-
this.state = void 0;
|
|
12
|
-
}
|
|
13
|
-
initializeState() {
|
|
14
|
-
super.initializeState();
|
|
15
|
-
this.setState({
|
|
16
|
-
colorsByAttribute: this.props.colorsByAttribute,
|
|
17
|
-
filtersByAttribute: this.props.filtersByAttribute,
|
|
18
|
-
loadingCounter: 0
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
updateState(params) {
|
|
22
|
-
const {
|
|
23
|
-
props,
|
|
24
|
-
oldProps,
|
|
25
|
-
changeFlags
|
|
26
|
-
} = params;
|
|
27
|
-
if (props.data && props.data !== oldProps.data) {
|
|
28
|
-
this._loadTileset(props.data);
|
|
29
|
-
} else if (props.colorsByAttribute !== oldProps.colorsByAttribute) {
|
|
30
|
-
this.setState({
|
|
31
|
-
colorsByAttribute: props.colorsByAttribute
|
|
32
|
-
});
|
|
33
|
-
this._colorizeTileset();
|
|
34
|
-
} else if (props.filtersByAttribute !== oldProps.filtersByAttribute) {
|
|
35
|
-
this.setState({
|
|
36
|
-
filtersByAttribute: props.filtersByAttribute
|
|
37
|
-
});
|
|
38
|
-
this._filterTileset();
|
|
39
|
-
} else if (changeFlags.viewportChanged) {
|
|
40
|
-
const {
|
|
41
|
-
activeViewports
|
|
42
|
-
} = this.state;
|
|
43
|
-
const viewportsNumber = Object.keys(activeViewports).length;
|
|
44
|
-
if (viewportsNumber) {
|
|
45
|
-
if (!this.state.loadingCounter) {
|
|
46
|
-
super._updateTileset(activeViewports);
|
|
47
|
-
}
|
|
48
|
-
this.state.lastUpdatedViewports = activeViewports;
|
|
49
|
-
this.state.activeViewports = {};
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
super.updateState(params);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async _loadTileset(tilesetUrl) {
|
|
56
|
-
const {
|
|
57
|
-
loadOptions = {}
|
|
58
|
-
} = this.props;
|
|
59
|
-
let loader = this.props.loader || this.props.loaders;
|
|
60
|
-
if (Array.isArray(loader)) {
|
|
61
|
-
loader = loader[0];
|
|
62
|
-
}
|
|
63
|
-
const options = {
|
|
64
|
-
loadOptions: {
|
|
65
|
-
...loadOptions
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
if (loader.preload) {
|
|
69
|
-
const preloadOptions = await loader.preload(tilesetUrl, loadOptions);
|
|
70
|
-
if (preloadOptions.headers) {
|
|
71
|
-
options.loadOptions.fetch = {
|
|
72
|
-
...options.loadOptions.fetch,
|
|
73
|
-
headers: preloadOptions.headers
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
Object.assign(options, preloadOptions);
|
|
77
|
-
}
|
|
78
|
-
const tilesetJson = await load(tilesetUrl, loader, options.loadOptions);
|
|
79
|
-
const tileset3d = new Tileset3D(tilesetJson, {
|
|
80
|
-
onTileLoad: this._onTileLoad.bind(this),
|
|
81
|
-
onTileUnload: super._onTileUnload.bind(this),
|
|
82
|
-
onTileError: this.props.onTileError,
|
|
83
|
-
onTraversalComplete: this._onTraversalComplete.bind(this),
|
|
84
|
-
...options
|
|
85
|
-
});
|
|
86
|
-
this.setState({
|
|
87
|
-
tileset3d,
|
|
88
|
-
layerMap: {}
|
|
89
|
-
});
|
|
90
|
-
super._updateTileset(this.state.activeViewports);
|
|
91
|
-
this.props.onTilesetLoad(tileset3d);
|
|
92
|
-
}
|
|
93
|
-
_onTileLoad(tileHeader) {
|
|
94
|
-
const {
|
|
95
|
-
lastUpdatedViewports
|
|
96
|
-
} = this.state;
|
|
97
|
-
this._colorizeTiles([tileHeader]);
|
|
98
|
-
this._filterTiles([tileHeader]);
|
|
99
|
-
this.props.onTileLoad(tileHeader);
|
|
100
|
-
if (!this.state.colorsByAttribute && !this.state.filtersByAttribute) {
|
|
101
|
-
super._updateTileset(lastUpdatedViewports);
|
|
102
|
-
this.setNeedsUpdate();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
_onTraversalComplete(selectedTiles) {
|
|
106
|
-
this._colorizeTiles(selectedTiles);
|
|
107
|
-
this._filterTiles(selectedTiles);
|
|
108
|
-
return this.props.onTraversalComplete ? this.props.onTraversalComplete(selectedTiles) : selectedTiles;
|
|
109
|
-
}
|
|
110
|
-
_colorizeTiles(tiles) {
|
|
111
|
-
var _tiles$;
|
|
112
|
-
if (this.props.customizeColors && ((_tiles$ = tiles[0]) === null || _tiles$ === void 0 ? void 0 : _tiles$.type) === TILE_TYPE.MESH) {
|
|
113
|
-
const {
|
|
114
|
-
layerMap,
|
|
115
|
-
colorsByAttribute
|
|
116
|
-
} = this.state;
|
|
117
|
-
const promises = [];
|
|
118
|
-
for (const tile of tiles) {
|
|
119
|
-
promises.push(this.props.customizeColors(tile, colorsByAttribute));
|
|
120
|
-
}
|
|
121
|
-
this.setState({
|
|
122
|
-
loadingCounter: this.state.loadingCounter + 1
|
|
123
|
-
});
|
|
124
|
-
Promise.allSettled(promises).then(result => {
|
|
125
|
-
this.setState({
|
|
126
|
-
loadingCounter: this.state.loadingCounter - 1
|
|
127
|
-
});
|
|
128
|
-
let isTileChanged = false;
|
|
129
|
-
for (const item of result) {
|
|
130
|
-
if (item.status === 'fulfilled' && item.value.isColored) {
|
|
131
|
-
isTileChanged = true;
|
|
132
|
-
delete layerMap[item.value.id];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (isTileChanged && !this.state.loadingCounter) {
|
|
136
|
-
super._updateTileset(this.state.activeViewports);
|
|
137
|
-
this.setNeedsUpdate();
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
_colorizeTileset() {
|
|
143
|
-
const {
|
|
144
|
-
tileset3d
|
|
145
|
-
} = this.state;
|
|
146
|
-
if (tileset3d) {
|
|
147
|
-
this._colorizeTiles(tileset3d.selectedTiles);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
_filterTiles(tiles) {
|
|
151
|
-
var _tiles$2;
|
|
152
|
-
if (this.props.filterTile && ((_tiles$2 = tiles[0]) === null || _tiles$2 === void 0 ? void 0 : _tiles$2.type) === TILE_TYPE.MESH) {
|
|
153
|
-
const {
|
|
154
|
-
layerMap,
|
|
155
|
-
filtersByAttribute
|
|
156
|
-
} = this.state;
|
|
157
|
-
const promises = [];
|
|
158
|
-
for (const tile of tiles) {
|
|
159
|
-
promises.push(this.props.filterTile(tile, filtersByAttribute));
|
|
160
|
-
}
|
|
161
|
-
this.setState({
|
|
162
|
-
loadingCounter: this.state.loadingCounter + 1
|
|
163
|
-
});
|
|
164
|
-
Promise.allSettled(promises).then(result => {
|
|
165
|
-
this.setState({
|
|
166
|
-
loadingCounter: this.state.loadingCounter - 1
|
|
167
|
-
});
|
|
168
|
-
let isTileChanged = false;
|
|
169
|
-
for (const item of result) {
|
|
170
|
-
if (item.status === 'fulfilled' && item.value.isFiltered) {
|
|
171
|
-
isTileChanged = true;
|
|
172
|
-
delete layerMap[item.value.id];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (isTileChanged && !this.state.loadingCounter) {
|
|
176
|
-
super._updateTileset(this.state.activeViewports);
|
|
177
|
-
this.setNeedsUpdate();
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
_filterTileset() {
|
|
183
|
-
const {
|
|
184
|
-
tileset3d
|
|
185
|
-
} = this.state;
|
|
186
|
-
if (tileset3d) {
|
|
187
|
-
this._filterTiles(tileset3d.selectedTiles);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
DataDrivenTile3DLayer.layerName = 'DataDrivenTile3DLayer';
|
|
192
|
-
DataDrivenTile3DLayer.defaultProps = defaultProps;
|
|
193
|
-
//# sourceMappingURL=data-driven-tile-3d-layer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"data-driven-tile-3d-layer.js","names":["Tile3DLayer","TILE_TYPE","Tileset3D","load","defaultProps","colorsByAttribute","filtersByAttribute","DataDrivenTile3DLayer","constructor","arguments","state","initializeState","setState","props","loadingCounter","updateState","params","oldProps","changeFlags","data","_loadTileset","_colorizeTileset","_filterTileset","viewportChanged","activeViewports","viewportsNumber","Object","keys","length","_updateTileset","lastUpdatedViewports","tilesetUrl","loadOptions","loader","loaders","Array","isArray","options","preload","preloadOptions","headers","fetch","assign","tilesetJson","tileset3d","onTileLoad","_onTileLoad","bind","onTileUnload","_onTileUnload","onTileError","onTraversalComplete","_onTraversalComplete","layerMap","onTilesetLoad","tileHeader","_colorizeTiles","_filterTiles","setNeedsUpdate","selectedTiles","tiles","_tiles$","customizeColors","type","MESH","promises","tile","push","Promise","allSettled","then","result","isTileChanged","item","status","value","isColored","id","_tiles$2","filterTile","isFiltered","layerName"],"sources":["../../src/data-driven-tile-3d-layer/data-driven-tile-3d-layer.ts"],"sourcesContent":["// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {Tile3DLayer, Tile3DLayerProps} from '@deck.gl/geo-layers';\nimport {UpdateParameters, Viewport, DefaultProps} from '@deck.gl/core';\nimport {TILE_TYPE, Tile3D, Tileset3D} from '@loaders.gl/tiles';\nimport {load} from '@loaders.gl/core';\n\nconst defaultProps: DefaultProps<DataDrivenTile3DLayerProps> = {\n colorsByAttribute: null,\n filtersByAttribute: null\n};\n\ntype DataDrivenTile3DLayerProps<DataT = any> = _DataDrivenTile3DLayerProps &\n Tile3DLayerProps<DataT>;\n\ntype _DataDrivenTile3DLayerProps = {\n onTraversalComplete?: (selectedTiles: Tile3D[]) => Tile3D[];\n colorsByAttribute?: ColorsByAttribute | null;\n customizeColors?: (\n tile: Tile3D,\n colorsByAttribute: ColorsByAttribute | null\n ) => Promise<{isColored: boolean; id: string}>;\n filtersByAttribute?: FiltersByAttribute | null;\n filterTile?: (\n tile: Tile3D,\n filtersByAttribute: FiltersByAttribute | null\n ) => Promise<{isFiltered: boolean; id: string}>;\n};\n\nexport type ColorsByAttribute = {\n /** Feature attribute name */\n attributeName: string;\n /** Minimum attribute value */\n minValue: number;\n /** Maximum attribute value */\n maxValue: number;\n /** Minimum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */\n minColor: [number, number, number, number];\n /** Maximum color. 3DObject will be colorized with gradient from `minColor to `maxColor` */\n maxColor: [number, number, number, number];\n /** Colorization mode. `replace` - replace vertex colors with a new colors, `multiply` - multiply vertex colors with new colors */\n mode: string;\n};\n\nexport type FiltersByAttribute = {\n /** Feature attribute name */\n attributeName: string;\n /** Filter value */\n value: number;\n};\n\n//@ts-expect-error call of private method of the base class\nexport class DataDrivenTile3DLayer<DataT = any, ExtraProps extends {} = {}> extends Tile3DLayer<\n DataT,\n Required<_DataDrivenTile3DLayerProps> & ExtraProps\n> {\n static layerName = 'DataDrivenTile3DLayer';\n static defaultProps = defaultProps as any;\n\n state!: {\n activeViewports: any;\n frameNumber?: number;\n lastUpdatedViewports: {[viewportId: string]: Viewport} | null;\n layerMap: {[layerId: string]: any};\n tileset3d: Tileset3D | null;\n\n colorsByAttribute: ColorsByAttribute | null;\n filtersByAttribute: FiltersByAttribute | null;\n loadingCounter: number;\n };\n\n initializeState() {\n super.initializeState();\n\n this.setState({\n colorsByAttribute: this.props.colorsByAttribute,\n filtersByAttribute: this.props.filtersByAttribute,\n loadingCounter: 0\n });\n }\n\n updateState(params: UpdateParameters<this>): void {\n const {props, oldProps, changeFlags} = params;\n\n if (props.data && props.data !== oldProps.data) {\n this._loadTileset(props.data);\n } else if (props.colorsByAttribute !== oldProps.colorsByAttribute) {\n this.setState({\n colorsByAttribute: props.colorsByAttribute\n });\n this._colorizeTileset();\n } else if (props.filtersByAttribute !== oldProps.filtersByAttribute) {\n this.setState({\n filtersByAttribute: props.filtersByAttribute\n });\n this._filterTileset();\n } else if (changeFlags.viewportChanged) {\n const {activeViewports} = this.state;\n const viewportsNumber = Object.keys(activeViewports).length;\n if (viewportsNumber) {\n if (!this.state.loadingCounter) {\n //@ts-expect-error call of private method of the base class\n super._updateTileset(activeViewports);\n }\n this.state.lastUpdatedViewports = activeViewports;\n this.state.activeViewports = {};\n }\n } else {\n super.updateState(params);\n }\n }\n\n private override async _loadTileset(tilesetUrl) {\n const {loadOptions = {}} = this.props;\n\n // TODO: deprecate `loader` in v9.0\n let loader = this.props.loader || this.props.loaders;\n if (Array.isArray(loader)) {\n loader = loader[0];\n }\n\n const options = {loadOptions: {...loadOptions}};\n if (loader.preload) {\n const preloadOptions = await loader.preload(tilesetUrl, loadOptions);\n\n if (preloadOptions.headers) {\n options.loadOptions.fetch = {\n ...options.loadOptions.fetch,\n headers: preloadOptions.headers\n };\n }\n Object.assign(options, preloadOptions);\n }\n //@ts-expect-error loader\n const tilesetJson = await load(tilesetUrl, loader, options.loadOptions);\n\n const tileset3d = new Tileset3D(tilesetJson, {\n onTileLoad: this._onTileLoad.bind(this),\n //@ts-expect-error call of private method of the base class\n onTileUnload: super._onTileUnload.bind(this),\n onTileError: this.props.onTileError,\n // New code ------------------\n onTraversalComplete: this._onTraversalComplete.bind(this),\n // ---------------------------\n ...options\n });\n\n this.setState({\n tileset3d,\n layerMap: {}\n });\n\n //@ts-expect-error call of private method of the base class\n super._updateTileset(this.state.activeViewports);\n this.props.onTilesetLoad(tileset3d);\n }\n\n private override _onTileLoad(tileHeader: Tile3D): void {\n const {lastUpdatedViewports} = this.state;\n // New code ------------------\n this._colorizeTiles([tileHeader]);\n this._filterTiles([tileHeader]);\n // ---------------------------\n this.props.onTileLoad(tileHeader);\n // New code ------------------ condition is added\n if (!this.state.colorsByAttribute && !this.state.filtersByAttribute) {\n // ---------------------------\n //@ts-expect-error call of private method of the base class\n super._updateTileset(lastUpdatedViewports);\n this.setNeedsUpdate();\n // New code ------------------\n }\n // ------------------\n }\n\n private _onTraversalComplete(selectedTiles: Tile3D[]): Tile3D[] {\n this._colorizeTiles(selectedTiles);\n this._filterTiles(selectedTiles);\n return this.props.onTraversalComplete\n ? this.props.onTraversalComplete(selectedTiles)\n : selectedTiles;\n }\n\n private _colorizeTiles(tiles: Tile3D[]): void {\n if (this.props.customizeColors && tiles[0]?.type === TILE_TYPE.MESH) {\n const {layerMap, colorsByAttribute} = this.state;\n const promises: Promise<{isColored: boolean; id: string}>[] = [];\n for (const tile of tiles) {\n promises.push(this.props.customizeColors(tile, colorsByAttribute));\n }\n this.setState({\n loadingCounter: this.state.loadingCounter + 1\n });\n Promise.allSettled(promises).then((result) => {\n this.setState({\n loadingCounter: this.state.loadingCounter - 1\n });\n let isTileChanged = false;\n for (const item of result) {\n if (item.status === 'fulfilled' && item.value.isColored) {\n isTileChanged = true;\n delete layerMap[item.value.id];\n }\n }\n if (isTileChanged && !this.state.loadingCounter) {\n //@ts-expect-error call of private method of the base class\n super._updateTileset(this.state.activeViewports);\n this.setNeedsUpdate();\n }\n });\n }\n }\n\n private _colorizeTileset(): void {\n const {tileset3d} = this.state;\n\n if (tileset3d) {\n this._colorizeTiles(tileset3d.selectedTiles);\n }\n }\n\n private _filterTiles(tiles: Tile3D[]): void {\n if (this.props.filterTile && tiles[0]?.type === TILE_TYPE.MESH) {\n const {layerMap, filtersByAttribute} = this.state;\n const promises: Promise<{isFiltered: boolean; id: string}>[] = [];\n for (const tile of tiles) {\n promises.push(this.props.filterTile(tile, filtersByAttribute));\n }\n this.setState({\n loadingCounter: this.state.loadingCounter + 1\n });\n Promise.allSettled(promises).then((result) => {\n this.setState({\n loadingCounter: this.state.loadingCounter - 1\n });\n let isTileChanged = false;\n for (const item of result) {\n if (item.status === 'fulfilled' && item.value.isFiltered) {\n isTileChanged = true;\n delete layerMap[item.value.id];\n }\n }\n if (isTileChanged && !this.state.loadingCounter) {\n //@ts-expect-error call of private method of the base class\n super._updateTileset(this.state.activeViewports);\n this.setNeedsUpdate();\n }\n });\n }\n }\n\n private _filterTileset(): void {\n const {tileset3d} = this.state;\n\n if (tileset3d) {\n this._filterTiles(tileset3d.selectedTiles);\n }\n }\n}\n"],"mappings":"AAIA,SAAQA,WAAW,QAAyB,qBAAqB;AAEjE,SAAQC,SAAS,EAAUC,SAAS,QAAO,mBAAmB;AAC9D,SAAQC,IAAI,QAAO,kBAAkB;AAErC,MAAMC,YAAsD,GAAG;EAC7DC,iBAAiB,EAAE,IAAI;EACvBC,kBAAkB,EAAE;AACtB,CAAC;AA0CD,OAAO,MAAMC,qBAAqB,SAAkDP,WAAW,CAG7F;EAAAQ,YAAA;IAAA,SAAAC,SAAA;IAAA,KAIAC,KAAK;EAAA;EAYLC,eAAeA,CAAA,EAAG;IAChB,KAAK,CAACA,eAAe,CAAC,CAAC;IAEvB,IAAI,CAACC,QAAQ,CAAC;MACZP,iBAAiB,EAAE,IAAI,CAACQ,KAAK,CAACR,iBAAiB;MAC/CC,kBAAkB,EAAE,IAAI,CAACO,KAAK,CAACP,kBAAkB;MACjDQ,cAAc,EAAE;IAClB,CAAC,CAAC;EACJ;EAEAC,WAAWA,CAACC,MAA8B,EAAQ;IAChD,MAAM;MAACH,KAAK;MA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AAqB,CAKzBH,YAAY,GAAGA,YAAY"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { customizeColors } from '@loaders.gl/i3s';
|
|
2
|
-
export const colorizeTile = async (tile, colorsByAttribute) => {
|
|
3
|
-
const result = {
|
|
4
|
-
isColored: false,
|
|
5
|
-
id: tile.id
|
|
6
|
-
};
|
|
7
|
-
if (tile.content.customColors !== colorsByAttribute) {
|
|
8
|
-
if (tile.content && colorsByAttribute) {
|
|
9
|
-
if (!tile.content.originalColorsAttributes) {
|
|
10
|
-
tile.content.originalColorsAttributes = {
|
|
11
|
-
...tile.content.attributes.colors,
|
|
12
|
-
value: new Uint8Array(tile.content.attributes.colors.value)
|
|
13
|
-
};
|
|
14
|
-
} else if (colorsByAttribute.mode === 'multiply') {
|
|
15
|
-
tile.content.attributes.colors.value.set(tile.content.originalColorsAttributes.value);
|
|
16
|
-
}
|
|
17
|
-
tile.content.customColors = colorsByAttribute;
|
|
18
|
-
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);
|
|
19
|
-
if (tile.content.customColors === colorsByAttribute) {
|
|
20
|
-
tile.content.attributes.colors = newColors;
|
|
21
|
-
result.isColored = true;
|
|
22
|
-
}
|
|
23
|
-
} else if (tile.content && tile.content.originalColorsAttributes) {
|
|
24
|
-
tile.content.attributes.colors.value = tile.content.originalColorsAttributes.value;
|
|
25
|
-
tile.content.customColors = null;
|
|
26
|
-
result.isColored = true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=colorize-tile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colorize-tile.js","names":["customizeColors","colorizeTile","tile","colorsByAttribute","result","isColored","id","content","customColors","originalColorsAttributes","attributes","colors","value","Uint8Array","mode","set","newColors","featureIds","header","attributeUrls","tileset","fields","attributeStorageInfo","loadOptions","i3s","token"],"sources":["../../../src/data-driven-tile-3d-layer/utils/colorize-tile.ts"],"sourcesContent":["// deck.gl-community\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {customizeColors} from '@loaders.gl/i3s';\nimport {Tile3D} from '@loaders.gl/tiles';\nimport {ColorsByAttribute} from '../data-driven-tile-3d-layer';\n\n/**\n * Update tile colors with the custom colors assigned to the I3S Loader\n * @returns {Promise<{isColored: boolean; id: string}>} Result of the tile colorization - isColored: true/false and tile id\n */\nexport const colorizeTile = async (\n tile: Tile3D,\n colorsByAttribute: ColorsByAttribute | null\n): Promise<{isColored: boolean; id: string}> => {\n const result = {isColored: false, id: tile.id};\n\n if (tile.content.customColors !== colorsByAttribute) {\n if (tile.content && colorsByAttribute) {\n if (!tile.content.originalColorsAttributes) {\n tile.content.originalColorsAttributes = {\n ...tile.content.attributes.colors,\n value: new Uint8Array(tile.content.attributes.colors.value)\n };\n } else if (colorsByAttribute.mode === 'multiply') {\n tile.content.attributes.colors.value.set(tile.content.originalColorsAttributes.value);\n }\n\n tile.content.customColors = colorsByAttribute;\n\n const newColors = await customizeColors(\n tile.content.attributes.colors,\n tile.content.featureIds,\n tile.header.attributeUrls,\n tile.tileset.tileset.fields,\n tile.tileset.tileset.attributeStorageInfo,\n colorsByAttribute,\n (tile.tileset.loadOptions as any).i3s.token\n );\n // Make sure custom colors is not changed during async customizeColors execution\n if (tile.content.customColors === colorsByAttribute) {\n tile.content.attributes.colors = newColors;\n result.isColored = true;\n }\n } else if (tile.content && tile.content.originalColorsAttributes) {\n tile.content.attributes.colors.value = tile.content.originalColorsAttributes.value;\n tile.content.customColors = null;\n result.isColored = true;\n }\n }\n return result;\n};\n"],"mappings":"AAIA,SAAQA,eAAe,QAAO,iBAAiB;AAQ/C,OAAO,MAAMC,YAAY,GAAG,MAAAA,CAC1BC,IAAY,EACZC,iBAA2C,KACG;EAC9C,MAAM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