@map-colonies/react-components 3.7.3 → 3.9.0
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/CHANGELOG.md +19 -0
- package/dist/autocomplete/autocomplete.css +25 -0
- package/dist/autocomplete/autocomplete.d.ts +34 -0
- package/dist/autocomplete/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete/autocomplete.js +467 -0
- package/dist/autocomplete/autocomplete.js.map +1 -0
- package/dist/autocomplete/index.d.ts +2 -0
- package/dist/autocomplete/index.d.ts.map +1 -0
- package/dist/autocomplete/index.js +5 -0
- package/dist/autocomplete/index.js.map +1 -0
- package/dist/cesium-map/layers/3d.tileset.update.d.ts +2 -0
- package/dist/cesium-map/layers/3d.tileset.update.d.ts.map +1 -0
- package/dist/cesium-map/layers/3d.tileset.update.js +6 -0
- package/dist/cesium-map/layers/3d.tileset.update.js.map +1 -0
- package/dist/cesium-map/layers-manager.d.ts +2 -1
- package/dist/cesium-map/layers-manager.d.ts.map +1 -1
- package/dist/cesium-map/layers-manager.js.map +1 -1
- package/dist/cesium-map/map.d.ts +2 -1
- package/dist/cesium-map/map.d.ts.map +1 -1
- package/dist/cesium-map/map.js.map +1 -1
- package/dist/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.d.ts +4 -0
- package/dist/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.d.ts.map +1 -0
- package/dist/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.js +245 -0
- package/dist/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.js.map +1 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-decoder.d.ts +10 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-decoder.d.ts.map +1 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-decoder.js +201 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-decoder.js.map +1 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.d.ts +51 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.d.ts.map +1 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.js +137 -0
- package/dist/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.js.map +1 -0
- package/dist/date-picker/date-picker.css +9 -0
- package/dist/date-picker/date-picker.d.ts +15 -0
- package/dist/date-picker/date-picker.d.ts.map +1 -0
- package/dist/date-picker/date-picker.js +65 -0
- package/dist/date-picker/date-picker.js.map +1 -0
- package/dist/date-picker/index.d.ts +2 -0
- package/dist/date-picker/index.d.ts.map +1 -0
- package/dist/date-picker/index.js +7 -0
- package/dist/date-picker/index.js.map +1 -0
- package/dist/date-range-picker/date-range-picker.d.ts.map +1 -1
- package/dist/date-range-picker/date-range-picker.form-control.d.ts.map +1 -1
- package/dist/date-range-picker/date-range-picker.form-control.js +9 -7
- package/dist/date-range-picker/date-range-picker.form-control.js.map +1 -1
- package/dist/date-range-picker/date-range-picker.js +10 -10
- package/dist/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/models/defaults.d.ts +11 -0
- package/dist/models/defaults.d.ts.map +1 -1
- package/dist/models/defaults.js +12 -0
- package/dist/models/defaults.js.map +1 -1
- package/package.json +100 -95
- package/src/lib/autocomplete/autocomplete.css +25 -0
- package/src/lib/autocomplete/autocomplete.stories.tsx +101 -0
- package/src/lib/autocomplete/autocomplete.tsx +683 -0
- package/src/lib/autocomplete/get-input-selection.d.ts +1 -0
- package/src/lib/autocomplete/index.ts +1 -0
- package/src/lib/cesium-map/context-menu.stories.tsx +1 -2
- package/src/lib/cesium-map/layers/3d.tileset.stories.tsx +1 -2
- package/src/lib/cesium-map/layers/3d.tileset.update.ts +72 -0
- package/src/lib/cesium-map/layers/layers.rect.stories.tsx +171 -0
- package/src/lib/cesium-map/layers-manager.stories.tsx +2 -3
- package/src/lib/cesium-map/layers-manager.ts +3 -1
- package/src/lib/cesium-map/map.stories.tsx +3 -3
- package/src/lib/cesium-map/map.tsx +2 -0
- package/src/lib/cesium-map/terrain-providers/custom/dummy-quantized-mesh-tile.ts +243 -0
- package/src/lib/cesium-map/terrain-providers/custom/quantized-mesh-decoder.ts +321 -0
- package/src/lib/cesium-map/terrain-providers/custom/quantized-mesh-terrain-provider.ts +237 -0
- package/src/lib/cesium-map/terrain-providers/terrain-provider.stories.tsx +183 -0
- package/src/lib/date-picker/date-picker.css +9 -0
- package/src/lib/date-picker/date-picker.stories.tsx +130 -0
- package/src/lib/date-picker/date-picker.tsx +90 -0
- package/src/lib/date-picker/index.ts +1 -0
- package/src/lib/date-range-picker/date-range-picker.form-control.tsx +9 -7
- package/src/lib/date-range-picker/date-range-picker.tsx +12 -10
- package/src/lib/index.ts +2 -0
- package/src/lib/models/defaults.ts +12 -0
- package/src/types/quantized-mesh-decoder.d.ts +1 -0
- /package/storybook-static/mock/{tileset → tileset_1}/ll.b3dm +0 -0
- /package/storybook-static/mock/{tileset → tileset_1}/lr.b3dm +0 -0
- /package/storybook-static/mock/{tileset → tileset_1}/parent.b3dm +0 -0
- /package/storybook-static/mock/{tileset → tileset_1}/tileset.json +0 -0
- /package/storybook-static/mock/{tileset → tileset_1}/ul.b3dm +0 -0
- /package/storybook-static/mock/{tileset → tileset_1}/ur.b3dm +0 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
+
import {
|
|
3
|
+
IDecodedTile,
|
|
4
|
+
IDecodedTileHeader,
|
|
5
|
+
IExtensions,
|
|
6
|
+
} from './quantized-mesh-terrain-provider';
|
|
7
|
+
|
|
8
|
+
const LITTLE_ENDIAN = true;
|
|
9
|
+
const MAX_VERTEX_COUNT = 65536;
|
|
10
|
+
|
|
11
|
+
export const DECODING_STEPS = {
|
|
12
|
+
header: 0,
|
|
13
|
+
vertices: 1,
|
|
14
|
+
triangleIndices: 2,
|
|
15
|
+
edgeIndices: 3,
|
|
16
|
+
extensions: 4,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const QUANTIZED_MESH_HEADER = {
|
|
20
|
+
centerX: Float64Array.BYTES_PER_ELEMENT,
|
|
21
|
+
centerY: Float64Array.BYTES_PER_ELEMENT,
|
|
22
|
+
centerZ: Float64Array.BYTES_PER_ELEMENT,
|
|
23
|
+
|
|
24
|
+
minHeight: Float32Array.BYTES_PER_ELEMENT,
|
|
25
|
+
maxHeight: Float32Array.BYTES_PER_ELEMENT,
|
|
26
|
+
|
|
27
|
+
boundingSphereCenterX: Float64Array.BYTES_PER_ELEMENT,
|
|
28
|
+
boundingSphereCenterY: Float64Array.BYTES_PER_ELEMENT,
|
|
29
|
+
boundingSphereCenterZ: Float64Array.BYTES_PER_ELEMENT,
|
|
30
|
+
boundingSphereRadius: Float64Array.BYTES_PER_ELEMENT,
|
|
31
|
+
|
|
32
|
+
horizonOcclusionPointX: Float64Array.BYTES_PER_ELEMENT,
|
|
33
|
+
horizonOcclusionPointY: Float64Array.BYTES_PER_ELEMENT,
|
|
34
|
+
horizonOcclusionPointZ: Float64Array.BYTES_PER_ELEMENT,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const decodeZigZag = (value: number): number => {
|
|
38
|
+
return (value >> 1) ^ -(value & 1);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const decodeIndex = (
|
|
42
|
+
buffer: ArrayBufferLike,
|
|
43
|
+
position: number,
|
|
44
|
+
indicesCount: number,
|
|
45
|
+
bytesPerIndex: number,
|
|
46
|
+
encoded: boolean
|
|
47
|
+
): Uint16Array | Uint32Array => {
|
|
48
|
+
let indices;
|
|
49
|
+
|
|
50
|
+
if (bytesPerIndex === 2) {
|
|
51
|
+
indices = new Uint16Array(buffer, position, indicesCount);
|
|
52
|
+
} else {
|
|
53
|
+
indices = new Uint32Array(buffer, position, indicesCount);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!encoded) {
|
|
57
|
+
return indices;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let highest = 0;
|
|
61
|
+
|
|
62
|
+
for (let i = 0; i < indices.length; ++i) {
|
|
63
|
+
const code = indices[i];
|
|
64
|
+
|
|
65
|
+
indices[i] = highest - code;
|
|
66
|
+
|
|
67
|
+
if (code === 0) {
|
|
68
|
+
++highest;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return indices;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const convertFromTypedArrayToNumbersArray = (
|
|
76
|
+
array: Uint16Array | Uint32Array
|
|
77
|
+
): number[] => {
|
|
78
|
+
const numbersArray: number[] = [];
|
|
79
|
+
for (let i = 0; i < array.length; ++i) {
|
|
80
|
+
numbersArray.push(array[i]);
|
|
81
|
+
}
|
|
82
|
+
return numbersArray;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const decode = (data: ArrayBufferLike): IDecodedTile => {
|
|
86
|
+
const maxDecodingStep = DECODING_STEPS.extensions;
|
|
87
|
+
const view = new DataView(data);
|
|
88
|
+
const header = {} as IDecodedTileHeader;
|
|
89
|
+
let position = 0;
|
|
90
|
+
|
|
91
|
+
// Decode Header
|
|
92
|
+
|
|
93
|
+
Object.keys(QUANTIZED_MESH_HEADER).forEach(
|
|
94
|
+
(key: string, bytesCount: number) => {
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
// eslint-disable-next-line
|
|
97
|
+
header[key] =
|
|
98
|
+
bytesCount === 8
|
|
99
|
+
? view.getFloat64(position, LITTLE_ENDIAN)
|
|
100
|
+
: view.getFloat32(position, LITTLE_ENDIAN);
|
|
101
|
+
position += bytesCount;
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const headerEndPosition = position;
|
|
106
|
+
|
|
107
|
+
// if (maxDecodingStep < DECODING_STEPS.vertices) {
|
|
108
|
+
// return { header };
|
|
109
|
+
// }
|
|
110
|
+
|
|
111
|
+
// Decode Vertex Data
|
|
112
|
+
|
|
113
|
+
position = headerEndPosition;
|
|
114
|
+
|
|
115
|
+
let vertexCount = view.getUint32(position, LITTLE_ENDIAN);
|
|
116
|
+
|
|
117
|
+
const vertexData = new Uint16Array(vertexCount * 3);
|
|
118
|
+
|
|
119
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
120
|
+
|
|
121
|
+
const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
|
|
122
|
+
const elementArrayLength = vertexCount * bytesPerArrayElement;
|
|
123
|
+
const uArrayStartPosition = position;
|
|
124
|
+
const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
|
|
125
|
+
const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
|
|
126
|
+
|
|
127
|
+
let u = 0;
|
|
128
|
+
let v = 0;
|
|
129
|
+
let height = 0;
|
|
130
|
+
|
|
131
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
132
|
+
u += decodeZigZag(
|
|
133
|
+
view.getUint16(
|
|
134
|
+
uArrayStartPosition + bytesPerArrayElement * i,
|
|
135
|
+
LITTLE_ENDIAN
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
v += decodeZigZag(
|
|
139
|
+
view.getUint16(
|
|
140
|
+
vArrayStartPosition + bytesPerArrayElement * i,
|
|
141
|
+
LITTLE_ENDIAN
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
height += decodeZigZag(
|
|
145
|
+
view.getUint16(
|
|
146
|
+
heightArrayStartPosition + bytesPerArrayElement * i,
|
|
147
|
+
LITTLE_ENDIAN
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
vertexData[i] = u;
|
|
152
|
+
vertexData[i + vertexCount] = v;
|
|
153
|
+
vertexData[i + vertexCount * 2] = height;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
position += elementArrayLength * 3;
|
|
157
|
+
|
|
158
|
+
const vertexDataEndPosition = position;
|
|
159
|
+
|
|
160
|
+
// if (maxDecodingStep < DECODING_STEPS.triangleIndices) {
|
|
161
|
+
// return { header, vertexData };
|
|
162
|
+
// }
|
|
163
|
+
|
|
164
|
+
// Decode Triangle Indices
|
|
165
|
+
|
|
166
|
+
position = vertexDataEndPosition;
|
|
167
|
+
|
|
168
|
+
vertexCount = vertexData.length / 3;
|
|
169
|
+
|
|
170
|
+
const bytesPerIndex =
|
|
171
|
+
vertexCount > MAX_VERTEX_COUNT
|
|
172
|
+
? Uint32Array.BYTES_PER_ELEMENT
|
|
173
|
+
: Uint16Array.BYTES_PER_ELEMENT;
|
|
174
|
+
|
|
175
|
+
if (position % bytesPerIndex !== 0) {
|
|
176
|
+
position += bytesPerIndex - (position % bytesPerIndex);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const triangleCount = view.getUint32(position, LITTLE_ENDIAN);
|
|
180
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
181
|
+
|
|
182
|
+
const triangleIndicesCount = triangleCount * 3;
|
|
183
|
+
const triangleIndices = decodeIndex(
|
|
184
|
+
view.buffer,
|
|
185
|
+
position,
|
|
186
|
+
triangleIndicesCount,
|
|
187
|
+
bytesPerIndex,
|
|
188
|
+
true
|
|
189
|
+
);
|
|
190
|
+
position += triangleIndicesCount * bytesPerIndex;
|
|
191
|
+
|
|
192
|
+
const triangleIndicesEndPosition = position;
|
|
193
|
+
|
|
194
|
+
// if (maxDecodingStep < DECODING_STEPS.edgeIndices) {
|
|
195
|
+
// return { header, vertexData, triangleIndices };
|
|
196
|
+
// }
|
|
197
|
+
|
|
198
|
+
// Decode Edge Indices
|
|
199
|
+
|
|
200
|
+
position = triangleIndicesEndPosition;
|
|
201
|
+
|
|
202
|
+
vertexCount = vertexData.length / 3;
|
|
203
|
+
|
|
204
|
+
// bytesPerIndex = vertexCount > MAX_VERTEX_COUNT
|
|
205
|
+
// ? Uint32Array.BYTES_PER_ELEMENT
|
|
206
|
+
// : Uint16Array.BYTES_PER_ELEMENT;
|
|
207
|
+
|
|
208
|
+
const westVertexCount = view.getUint32(position, LITTLE_ENDIAN);
|
|
209
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
210
|
+
|
|
211
|
+
const westIndices = convertFromTypedArrayToNumbersArray(
|
|
212
|
+
decodeIndex(view.buffer, position, westVertexCount, bytesPerIndex, false)
|
|
213
|
+
);
|
|
214
|
+
position += westVertexCount * bytesPerIndex;
|
|
215
|
+
|
|
216
|
+
const southVertexCount = view.getUint32(position, LITTLE_ENDIAN);
|
|
217
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
218
|
+
|
|
219
|
+
const southIndices = convertFromTypedArrayToNumbersArray(
|
|
220
|
+
decodeIndex(view.buffer, position, southVertexCount, bytesPerIndex, false)
|
|
221
|
+
);
|
|
222
|
+
position += southVertexCount * bytesPerIndex;
|
|
223
|
+
|
|
224
|
+
const eastVertexCount = view.getUint32(position, LITTLE_ENDIAN);
|
|
225
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
226
|
+
|
|
227
|
+
const eastIndices = convertFromTypedArrayToNumbersArray(
|
|
228
|
+
decodeIndex(view.buffer, position, eastVertexCount, bytesPerIndex, false)
|
|
229
|
+
);
|
|
230
|
+
position += eastVertexCount * bytesPerIndex;
|
|
231
|
+
|
|
232
|
+
const northVertexCount = view.getUint32(position, LITTLE_ENDIAN);
|
|
233
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
234
|
+
|
|
235
|
+
const northIndices = convertFromTypedArrayToNumbersArray(
|
|
236
|
+
decodeIndex(view.buffer, position, northVertexCount, bytesPerIndex, false)
|
|
237
|
+
);
|
|
238
|
+
position += northVertexCount * bytesPerIndex;
|
|
239
|
+
|
|
240
|
+
const edgeIndicesEndPosition = position;
|
|
241
|
+
|
|
242
|
+
if (maxDecodingStep < DECODING_STEPS.extensions) {
|
|
243
|
+
return {
|
|
244
|
+
header,
|
|
245
|
+
vertexData,
|
|
246
|
+
triangleIndices,
|
|
247
|
+
westIndices,
|
|
248
|
+
northIndices,
|
|
249
|
+
eastIndices,
|
|
250
|
+
southIndices,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Decode Extensions
|
|
255
|
+
|
|
256
|
+
const extensions = {} as IExtensions;
|
|
257
|
+
|
|
258
|
+
if (view.byteLength > edgeIndicesEndPosition) {
|
|
259
|
+
position = edgeIndicesEndPosition;
|
|
260
|
+
|
|
261
|
+
while (position < view.byteLength) {
|
|
262
|
+
const extensionId = view.getUint8(position);
|
|
263
|
+
position += Uint8Array.BYTES_PER_ELEMENT;
|
|
264
|
+
|
|
265
|
+
const extensionLength = view.getUint32(position, true);
|
|
266
|
+
position += Uint32Array.BYTES_PER_ELEMENT;
|
|
267
|
+
|
|
268
|
+
const extensionView = new DataView(
|
|
269
|
+
view.buffer,
|
|
270
|
+
position,
|
|
271
|
+
extensionLength
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
switch (extensionId) {
|
|
275
|
+
case 1: {
|
|
276
|
+
extensions.vertexNormals = new Uint8Array(
|
|
277
|
+
extensionView.buffer,
|
|
278
|
+
extensionView.byteOffset,
|
|
279
|
+
extensionView.byteLength
|
|
280
|
+
);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 2: {
|
|
284
|
+
extensions.waterMask = extensionView.buffer.slice(
|
|
285
|
+
extensionView.byteOffset,
|
|
286
|
+
extensionView.byteOffset + extensionView.byteLength
|
|
287
|
+
);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case 4: {
|
|
291
|
+
const jsonLength = extensionView.getUint32(0, LITTLE_ENDIAN);
|
|
292
|
+
let jsonString = '';
|
|
293
|
+
for (let i = 0; i < jsonLength; ++i) {
|
|
294
|
+
jsonString += String.fromCharCode(
|
|
295
|
+
extensionView.getUint8(Uint32Array.BYTES_PER_ELEMENT + i)
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
// eslint-disable-next-line
|
|
299
|
+
extensions.metadata = JSON.parse(jsonString);
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
default: {
|
|
303
|
+
console.warn(`Unknown extension with id ${extensionId}`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
position += extensionLength;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return {
|
|
312
|
+
header,
|
|
313
|
+
vertexData,
|
|
314
|
+
triangleIndices,
|
|
315
|
+
westIndices,
|
|
316
|
+
northIndices,
|
|
317
|
+
eastIndices,
|
|
318
|
+
southIndices,
|
|
319
|
+
extensions,
|
|
320
|
+
};
|
|
321
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
7
|
+
import {
|
|
8
|
+
BoundingSphere,
|
|
9
|
+
Cartesian3,
|
|
10
|
+
Cartographic,
|
|
11
|
+
Credit,
|
|
12
|
+
Ellipsoid,
|
|
13
|
+
Math,
|
|
14
|
+
OrientedBoundingBox,
|
|
15
|
+
QuantizedMeshTerrainData,
|
|
16
|
+
Rectangle,
|
|
17
|
+
TerrainProvider,
|
|
18
|
+
TilingScheme,
|
|
19
|
+
WebMercatorTilingScheme,
|
|
20
|
+
} from 'cesium';
|
|
21
|
+
import decode from '@here/quantized-mesh-decoder';
|
|
22
|
+
import dummyTileBuffer from './dummy-quantized-mesh-tile';
|
|
23
|
+
|
|
24
|
+
const TILE_IMAGE_WIDTH = 65;
|
|
25
|
+
|
|
26
|
+
export interface IDecodedTileHeader {
|
|
27
|
+
centerX: number;
|
|
28
|
+
centerY: number;
|
|
29
|
+
centerZ: number;
|
|
30
|
+
minHeight: number;
|
|
31
|
+
maxHeight: number;
|
|
32
|
+
boundingSphereCenterX: number;
|
|
33
|
+
boundingSphereCenterY: number;
|
|
34
|
+
boundingSphereCenterZ: number;
|
|
35
|
+
boundingSphereRadius: number;
|
|
36
|
+
horizonOcclusionPointX: number;
|
|
37
|
+
horizonOcclusionPointY: number;
|
|
38
|
+
horizonOcclusionPointZ: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IExtensions {
|
|
42
|
+
vertexNormals?: Uint8Array;
|
|
43
|
+
waterMask?: ArrayBufferLike;
|
|
44
|
+
metadata?: unknown;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface IDecodedTile {
|
|
48
|
+
header: IDecodedTileHeader;
|
|
49
|
+
vertexData: Uint16Array;
|
|
50
|
+
triangleIndices: Uint16Array | Uint32Array;
|
|
51
|
+
westIndices: number[];
|
|
52
|
+
northIndices: number[];
|
|
53
|
+
eastIndices: number[];
|
|
54
|
+
southIndices: number[];
|
|
55
|
+
extensions?: IExtensions;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default class QuantizedMeshTerrainProvider /*extends TerrainProvider*/ {
|
|
59
|
+
public tilingScheme: TilingScheme;
|
|
60
|
+
public ready: boolean;
|
|
61
|
+
public readyPromise: Promise<boolean>;
|
|
62
|
+
private readonly dummyTile: IDecodedTile;
|
|
63
|
+
private readonly getUrl: (x: number, y: number, level: number) => string;
|
|
64
|
+
private readonly credits: Credit[] | undefined;
|
|
65
|
+
|
|
66
|
+
public constructor(options: {
|
|
67
|
+
getUrl?: (x: number, y: number, level: number) => string;
|
|
68
|
+
credit?: string;
|
|
69
|
+
tilingScheme?: TilingScheme;
|
|
70
|
+
}) {
|
|
71
|
+
// super();
|
|
72
|
+
this.ready = false;
|
|
73
|
+
this.dummyTile = decode(dummyTileBuffer);
|
|
74
|
+
this.tilingScheme = options.tilingScheme ?? new WebMercatorTilingScheme();
|
|
75
|
+
|
|
76
|
+
if (options.getUrl === undefined) {
|
|
77
|
+
throw new Error('getUrl option is missing');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (options.credit !== undefined) {
|
|
81
|
+
this.credits = [new Credit(options.credit)];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.getUrl = options.getUrl;
|
|
85
|
+
|
|
86
|
+
this.readyPromise = Promise.resolve(true);
|
|
87
|
+
this.ready = true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public requestTileGeometry(
|
|
91
|
+
x: number,
|
|
92
|
+
y: number,
|
|
93
|
+
level: number
|
|
94
|
+
): Promise<void | QuantizedMeshTerrainData> | undefined {
|
|
95
|
+
const url = this.getUrl(x, y, level);
|
|
96
|
+
|
|
97
|
+
return window
|
|
98
|
+
.fetch(url)
|
|
99
|
+
.then((res: Response) => {
|
|
100
|
+
if (res.status !== 200) {
|
|
101
|
+
return this.generateDummyTile(x, y, level);
|
|
102
|
+
}
|
|
103
|
+
return this.decodeResponse(res, x, y, level);
|
|
104
|
+
})
|
|
105
|
+
.then((decodedTile: IDecodedTile) => {
|
|
106
|
+
return this.createQuantizedMeshData(decodedTile, x, y, level);
|
|
107
|
+
})
|
|
108
|
+
.catch((err: unknown) => {
|
|
109
|
+
console.error(err);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public getTileDataAvailable(x: number, y: number, level: number): boolean {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public getLevelMaximumGeometricError(level: number): number {
|
|
118
|
+
const levelZeroMaximumGeometricError = TerrainProvider.getEstimatedLevelZeroGeometricErrorForAHeightmap(
|
|
119
|
+
this.tilingScheme.ellipsoid,
|
|
120
|
+
TILE_IMAGE_WIDTH,
|
|
121
|
+
this.tilingScheme.getNumberOfXTilesAtLevel(0)
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return levelZeroMaximumGeometricError / (1 << level);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private generateDummyTileHeader(
|
|
128
|
+
x: number,
|
|
129
|
+
y: number,
|
|
130
|
+
level: number
|
|
131
|
+
): IDecodedTileHeader {
|
|
132
|
+
const tileRect = this.tilingScheme.tileXYToRectangle(x, y, level);
|
|
133
|
+
const tileNativeRect = this.tilingScheme.tileXYToNativeRectangle(
|
|
134
|
+
x,
|
|
135
|
+
y,
|
|
136
|
+
level
|
|
137
|
+
);
|
|
138
|
+
const tileCenter = Cartographic.toCartesian(Rectangle.center(tileRect));
|
|
139
|
+
const horizonOcclusionPoint = Ellipsoid.WGS84.transformPositionToScaledSpace(
|
|
140
|
+
tileCenter
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
centerX: tileCenter.x,
|
|
145
|
+
centerY: tileCenter.y,
|
|
146
|
+
centerZ: tileCenter.z,
|
|
147
|
+
minHeight: 0,
|
|
148
|
+
maxHeight: 0,
|
|
149
|
+
boundingSphereCenterX: tileCenter.x,
|
|
150
|
+
boundingSphereCenterY: tileCenter.y,
|
|
151
|
+
boundingSphereCenterZ: tileCenter.z,
|
|
152
|
+
boundingSphereRadius: tileNativeRect.height,
|
|
153
|
+
horizonOcclusionPointX: horizonOcclusionPoint.x,
|
|
154
|
+
horizonOcclusionPointY: horizonOcclusionPoint.y,
|
|
155
|
+
horizonOcclusionPointZ: horizonOcclusionPoint.z,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private createQuantizedMeshData(
|
|
160
|
+
decodedTile: IDecodedTile,
|
|
161
|
+
x: number,
|
|
162
|
+
y: number,
|
|
163
|
+
level: number
|
|
164
|
+
): QuantizedMeshTerrainData {
|
|
165
|
+
const tileRect = this.tilingScheme.tileXYToRectangle(x, y, level);
|
|
166
|
+
const boundingSphereCenter = new Cartesian3(
|
|
167
|
+
decodedTile.header.boundingSphereCenterX,
|
|
168
|
+
decodedTile.header.boundingSphereCenterY,
|
|
169
|
+
decodedTile.header.boundingSphereCenterZ
|
|
170
|
+
);
|
|
171
|
+
const boundingSphere = new BoundingSphere(
|
|
172
|
+
boundingSphereCenter,
|
|
173
|
+
decodedTile.header.boundingSphereRadius
|
|
174
|
+
);
|
|
175
|
+
const horizonOcclusionPoint = new Cartesian3(
|
|
176
|
+
decodedTile.header.horizonOcclusionPointX,
|
|
177
|
+
decodedTile.header.horizonOcclusionPointY,
|
|
178
|
+
decodedTile.header.horizonOcclusionPointZ
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
let orientedBoundingBox;
|
|
182
|
+
|
|
183
|
+
if (tileRect.width < Math.PI_OVER_TWO + Math.EPSILON5) {
|
|
184
|
+
orientedBoundingBox = OrientedBoundingBox.fromRectangle(
|
|
185
|
+
tileRect,
|
|
186
|
+
decodedTile.header.minHeight,
|
|
187
|
+
decodedTile.header.maxHeight
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return new QuantizedMeshTerrainData({
|
|
192
|
+
minimumHeight: decodedTile.header.minHeight,
|
|
193
|
+
maximumHeight: decodedTile.header.maxHeight,
|
|
194
|
+
quantizedVertices: decodedTile.vertexData,
|
|
195
|
+
indices: decodedTile.triangleIndices,
|
|
196
|
+
boundingSphere: boundingSphere,
|
|
197
|
+
orientedBoundingBox: orientedBoundingBox,
|
|
198
|
+
horizonOcclusionPoint: horizonOcclusionPoint,
|
|
199
|
+
westIndices: decodedTile.westIndices,
|
|
200
|
+
southIndices: decodedTile.southIndices,
|
|
201
|
+
eastIndices: decodedTile.eastIndices,
|
|
202
|
+
northIndices: decodedTile.northIndices,
|
|
203
|
+
westSkirtHeight: 100,
|
|
204
|
+
southSkirtHeight: 100,
|
|
205
|
+
eastSkirtHeight: 100,
|
|
206
|
+
northSkirtHeight: 100,
|
|
207
|
+
childTileMask: 15,
|
|
208
|
+
credits: this.credits,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private generateDummyTile(x: number, y: number, level: number): IDecodedTile {
|
|
213
|
+
return {
|
|
214
|
+
...this.dummyTile,
|
|
215
|
+
...this.generateDummyTileHeader(x, y, level),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private decodeResponse(
|
|
220
|
+
res: any,
|
|
221
|
+
x: number,
|
|
222
|
+
y: number,
|
|
223
|
+
level: number
|
|
224
|
+
): IDecodedTile {
|
|
225
|
+
return res
|
|
226
|
+
.arrayBuffer()
|
|
227
|
+
.then((buffer: ArrayBufferLike) => {
|
|
228
|
+
return decode(buffer);
|
|
229
|
+
})
|
|
230
|
+
.catch((err: unknown) => {
|
|
231
|
+
console.error(`Decoding failed on tile ${this.getUrl(x, y, level)}`);
|
|
232
|
+
console.error(err);
|
|
233
|
+
|
|
234
|
+
return this.generateDummyTile(x, y, level);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|