@loaders.gl/tiles 5.0.0-alpha.2 → 5.0.0-alpha.4

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 (109) hide show
  1. package/LICENSE +1 -1
  2. package/dist/dist.dev.js +17325 -5650
  3. package/dist/dist.min.js +4 -1
  4. package/dist/index.cjs +1924 -178
  5. package/dist/index.cjs.map +3 -3
  6. package/dist/index.d.ts +9 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +6 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/point-cloud/point-cloud-tileset.d.ts +4 -0
  11. package/dist/point-cloud/point-cloud-tileset.d.ts.map +1 -1
  12. package/dist/point-cloud/point-cloud-tileset.js +51 -12
  13. package/dist/point-cloud/point-cloud-tileset.js.map +1 -1
  14. package/dist/point-cloud/types.d.ts +17 -0
  15. package/dist/point-cloud/types.d.ts.map +1 -1
  16. package/dist/raster-set.d.ts +10 -8
  17. package/dist/raster-set.d.ts.map +1 -1
  18. package/dist/raster-set.js +18 -1
  19. package/dist/raster-set.js.map +1 -1
  20. package/dist/spatial/format-spatial-reference.d.ts +67 -0
  21. package/dist/spatial/format-spatial-reference.d.ts.map +1 -0
  22. package/dist/spatial/format-spatial-reference.js +233 -0
  23. package/dist/spatial/format-spatial-reference.js.map +1 -0
  24. package/dist/spatial/get-spatial-coordinate-frame.d.ts +9 -0
  25. package/dist/spatial/get-spatial-coordinate-frame.d.ts.map +1 -0
  26. package/dist/spatial/get-spatial-coordinate-frame.js +58 -0
  27. package/dist/spatial/get-spatial-coordinate-frame.js.map +1 -0
  28. package/dist/spatial/i3s-elevation.d.ts +20 -0
  29. package/dist/spatial/i3s-elevation.d.ts.map +1 -0
  30. package/dist/spatial/i3s-elevation.js +90 -0
  31. package/dist/spatial/i3s-elevation.js.map +1 -0
  32. package/dist/spatial/i3s-spatial-transformer.d.ts +189 -0
  33. package/dist/spatial/i3s-spatial-transformer.d.ts.map +1 -0
  34. package/dist/spatial/i3s-spatial-transformer.js +686 -0
  35. package/dist/spatial/i3s-spatial-transformer.js.map +1 -0
  36. package/dist/spatial/spatial-coordinate-transformer.d.ts +48 -0
  37. package/dist/spatial/spatial-coordinate-transformer.d.ts.map +1 -0
  38. package/dist/spatial/spatial-coordinate-transformer.js +211 -0
  39. package/dist/spatial/spatial-coordinate-transformer.js.map +1 -0
  40. package/dist/spatial/spatial-resource-registry.d.ts +44 -0
  41. package/dist/spatial/spatial-resource-registry.d.ts.map +1 -0
  42. package/dist/spatial/spatial-resource-registry.js +67 -0
  43. package/dist/spatial/spatial-resource-registry.js.map +1 -0
  44. package/dist/spatial/spatial-types.d.ts +190 -0
  45. package/dist/spatial/spatial-types.d.ts.map +1 -0
  46. package/dist/spatial/spatial-types.js +192 -0
  47. package/dist/spatial/spatial-types.js.map +1 -0
  48. package/dist/tileset-3d/common/tile-3d.d.ts +49 -1
  49. package/dist/tileset-3d/common/tile-3d.d.ts.map +1 -1
  50. package/dist/tileset-3d/common/tile-3d.js +132 -64
  51. package/dist/tileset-3d/common/tile-3d.js.map +1 -1
  52. package/dist/tileset-3d/common/tileset-3d.d.ts +25 -0
  53. package/dist/tileset-3d/common/tileset-3d.d.ts.map +1 -1
  54. package/dist/tileset-3d/common/tileset-3d.js +49 -7
  55. package/dist/tileset-3d/common/tileset-3d.js.map +1 -1
  56. package/dist/tileset-3d/common/tileset-source.d.ts +14 -0
  57. package/dist/tileset-3d/common/tileset-source.d.ts.map +1 -1
  58. package/dist/tileset-3d/common/tileset-source.js.map +1 -1
  59. package/dist/tileset-3d/common/tileset-traverser.d.ts +6 -1
  60. package/dist/tileset-3d/common/tileset-traverser.d.ts.map +1 -1
  61. package/dist/tileset-3d/common/tileset-traverser.js +11 -6
  62. package/dist/tileset-3d/common/tileset-traverser.js.map +1 -1
  63. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts +26 -1
  64. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts.map +1 -1
  65. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js +62 -18
  66. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js.map +1 -1
  67. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts +1 -7
  68. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts.map +1 -1
  69. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js +32 -55
  70. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js.map +1 -1
  71. package/dist/tileset-3d/format-i3s/i3s-source.d.ts +14 -1
  72. package/dist/tileset-3d/format-i3s/i3s-source.d.ts.map +1 -1
  73. package/dist/tileset-3d/format-i3s/i3s-source.js +107 -17
  74. package/dist/tileset-3d/format-i3s/i3s-source.js.map +1 -1
  75. package/dist/tileset-3d/helpers/bounding-volume.d.ts.map +1 -1
  76. package/dist/tileset-3d/helpers/bounding-volume.js +3 -33
  77. package/dist/tileset-3d/helpers/bounding-volume.js.map +1 -1
  78. package/dist/tileset-3d/helpers/frame-state.d.ts +3 -1
  79. package/dist/tileset-3d/helpers/frame-state.d.ts.map +1 -1
  80. package/dist/tileset-3d/helpers/frame-state.js +1 -0
  81. package/dist/tileset-3d/helpers/frame-state.js.map +1 -1
  82. package/dist/tileset-3d/helpers/i3s-lod.d.ts.map +1 -1
  83. package/dist/tileset-3d/helpers/i3s-lod.js +20 -8
  84. package/dist/tileset-3d/helpers/i3s-lod.js.map +1 -1
  85. package/dist/types.d.ts +3 -0
  86. package/dist/types.d.ts.map +1 -1
  87. package/package.json +12 -9
  88. package/src/index.ts +42 -1
  89. package/src/point-cloud/point-cloud-tileset.ts +66 -12
  90. package/src/point-cloud/types.ts +17 -0
  91. package/src/raster-set.ts +46 -11
  92. package/src/spatial/format-spatial-reference.ts +311 -0
  93. package/src/spatial/get-spatial-coordinate-frame.ts +74 -0
  94. package/src/spatial/i3s-elevation.ts +96 -0
  95. package/src/spatial/i3s-spatial-transformer.ts +957 -0
  96. package/src/spatial/spatial-coordinate-transformer.ts +276 -0
  97. package/src/spatial/spatial-resource-registry.ts +79 -0
  98. package/src/spatial/spatial-types.ts +422 -0
  99. package/src/tileset-3d/common/tile-3d.ts +156 -69
  100. package/src/tileset-3d/common/tileset-3d.ts +77 -6
  101. package/src/tileset-3d/common/tileset-source.ts +15 -0
  102. package/src/tileset-3d/common/tileset-traverser.ts +11 -6
  103. package/src/tileset-3d/format-3d-tiles/implicit-tiling.ts +100 -22
  104. package/src/tileset-3d/format-3d-tiles/tiles-3d-source.ts +36 -56
  105. package/src/tileset-3d/format-i3s/i3s-source.ts +119 -18
  106. package/src/tileset-3d/helpers/bounding-volume.ts +3 -55
  107. package/src/tileset-3d/helpers/frame-state.ts +3 -0
  108. package/src/tileset-3d/helpers/i3s-lod.ts +22 -8
  109. package/src/types.ts +3 -0
@@ -0,0 +1,422 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {
6
+ createSpatialReference,
7
+ inferCRSRepresentation,
8
+ type ReadonlyCRSDefinition,
9
+ type SpatialReference,
10
+ type SpatialReferenceAlternative,
11
+ type SpatialReferenceCoordinateFrame,
12
+ type SpatialReferenceProvenance,
13
+ type SpatialReferenceRepresentation,
14
+ type SpatialReferenceState
15
+ } from '@math.gl/crs';
16
+ import type {Geoid} from '@math.gl/geoid';
17
+ import {getSpatialCoordinateFrame} from './get-spatial-coordinate-frame';
18
+
19
+ /** How height values in a 3D dataset relate to the earth. */
20
+ export type TilesetHeightReference = 'native' | 'ellipsoidal' | 'orthometric' | 'unknown';
21
+
22
+ /** Height reference that an application may request for transformed output. */
23
+ export type TilesetTargetHeightReference = 'native' | 'ellipsoidal' | 'orthometric';
24
+
25
+ /** I3S placement rule applied after source-height interpretation. */
26
+ export type TilesetElevationMode =
27
+ | 'absoluteHeight'
28
+ | 'onTheGround'
29
+ | 'relativeToGround'
30
+ | 'relativeToScene';
31
+
32
+ /** One WGS84 longitude/latitude location requested from an elevation provider. */
33
+ export type TilesetElevationSample = readonly [longitude: number, latitude: number];
34
+
35
+ /** WGS84 geographic footprint passed to an elevation provider. */
36
+ export type TilesetElevationBounds = {
37
+ /** Western longitude in degrees. Greater than `east` when crossing the antimeridian. */
38
+ readonly west: number;
39
+ /** Southern latitude in degrees. */
40
+ readonly south: number;
41
+ /** Eastern longitude in degrees. Less than `west` when crossing the antimeridian. */
42
+ readonly east: number;
43
+ /** Northern latitude in degrees. */
44
+ readonly north: number;
45
+ };
46
+
47
+ /** Conservative elevation extrema over one geographic footprint. */
48
+ export type TilesetElevationRange = {
49
+ /** Minimum elevation anywhere inside the footprint. */
50
+ readonly minimum: number;
51
+ /** Maximum elevation anywhere inside the footprint. */
52
+ readonly maximum: number;
53
+ };
54
+
55
+ /**
56
+ * Application-owned source of terrain or scene-surface heights.
57
+ *
58
+ * Providers receive WGS84 longitude/latitude locations and may batch asynchronous requests. They
59
+ * never need to transform horizontal coordinates. Returned heights default to meters in the
60
+ * layer's source height reference unless `unit` or `heightReference` says otherwise.
61
+ */
62
+ export type TilesetElevationProvider = {
63
+ /** Height reference used by sampled values. Omit to use the layer's source height reference. */
64
+ readonly heightReference?: Exclude<TilesetHeightReference, 'native' | 'unknown'>;
65
+ /** Linear unit used by sampled values. Defaults to `meter`. */
66
+ readonly unit?: string;
67
+ /**
68
+ * Samples one height for every supplied location, preserving input order.
69
+ * @param positions - WGS84 longitude/latitude locations.
70
+ * @returns Finite heights with the same length and order as `positions`.
71
+ */
72
+ sampleElevations(
73
+ positions: readonly TilesetElevationSample[]
74
+ ): readonly number[] | Promise<readonly number[]>;
75
+ /**
76
+ * Returns conservative elevation extrema over an entire geographic footprint.
77
+ *
78
+ * Bounds preparation requires this operation because point samples cannot detect an interior
79
+ * peak or depression and therefore cannot produce a culling-safe traversal volume.
80
+ *
81
+ * @param bounds - WGS84 geographic footprint in degrees.
82
+ * @returns Minimum and maximum elevations in this provider's declared unit and height reference.
83
+ */
84
+ getElevationRange(
85
+ bounds: TilesetElevationBounds
86
+ ): TilesetElevationRange | Promise<TilesetElevationRange>;
87
+ };
88
+
89
+ /** Coordinate representation requested from a 3D tileset. */
90
+ export type TilesetOutputCoordinates = 'auto' | 'ecef' | 'local-enu' | 'target-crs';
91
+
92
+ /** Broad coordinate frame used by a 3D dataset. */
93
+ export type TilesetCoordinateFrame = SpatialReferenceCoordinateFrame;
94
+
95
+ /** Origin of a normalized spatial-reference value. */
96
+ export type TilesetSpatialReferenceProvenance = SpatialReferenceProvenance;
97
+
98
+ /**
99
+ * Simple application-facing spatial options shared by 3D Tiles and I3S.
100
+ *
101
+ * Source CRS details are normally discovered from dataset metadata. The source overrides are
102
+ * expert recovery controls for incomplete or non-standard datasets.
103
+ */
104
+ export type TilesetSpatialOptions = {
105
+ /** CRS of transformed output coordinates. Omit to retain the format's natural world frame. */
106
+ targetCrs?: ReadonlyCRSDefinition;
107
+ /** Height reference of transformed output coordinates. Defaults to `native`. */
108
+ targetHeightReference?: TilesetTargetHeightReference;
109
+ /** Output coordinate representation. Defaults to `auto`. */
110
+ outputCoordinates?: TilesetOutputCoordinates;
111
+ /** Expert override used when source metadata is absent or incorrect. */
112
+ sourceCrs?: ReadonlyCRSDefinition;
113
+ /** Expert override for a dynamic coordinate reference epoch. */
114
+ coordinateEpoch?: number;
115
+ /** Registered geoid model name or an already parsed geoid model. */
116
+ geoidModel?: string | Geoid;
117
+ /** Terrain heights used by I3S `onTheGround` and `relativeToGround` placement. */
118
+ terrainElevationProvider?: TilesetElevationProvider;
119
+ /** Scene-surface heights used by I3S `relativeToScene` placement. */
120
+ sceneElevationProvider?: TilesetElevationProvider;
121
+ };
122
+
123
+ /**
124
+ * Normalized, readonly spatial metadata discovered for a 3D tileset.
125
+ *
126
+ * This is diagnostic output. Applications normally do not construct it.
127
+ */
128
+ export type TilesetSpatialReference = SpatialReference & {
129
+ /** Source horizontal or compound CRS, when it can be identified. */
130
+ readonly sourceCrs?: ReadonlyCRSDefinition;
131
+ /** Source vertical CRS, when independently identified. */
132
+ readonly verticalCrs?: ReadonlyCRSDefinition;
133
+ /** Number of meters represented by one source Z unit. */
134
+ readonly verticalUnitScale: number;
135
+ /** Coordinate epoch attached to the source coordinates. */
136
+ readonly coordinateEpoch?: number;
137
+ /** Source height interpretation. */
138
+ readonly heightReference: TilesetHeightReference;
139
+ /** I3S placement rule, when the source layer declares one. */
140
+ readonly elevationMode?: TilesetElevationMode;
141
+ /** Declared I3S elevation offset before unit normalization. */
142
+ readonly elevationOffset?: number;
143
+ /** Unit of the I3S elevation offset. Defaults to `meter` when a mode is declared. */
144
+ readonly elevationUnit?: string;
145
+ /** Number of meters represented by one elevation-offset unit. */
146
+ readonly elevationUnitScale: number;
147
+ /** Broad frame in which source coordinates are encoded. */
148
+ readonly coordinateFrame: TilesetCoordinateFrame;
149
+ /** Coordinate component order used by the format wire representation. */
150
+ readonly axisOrder: 'xy' | 'yx' | 'xyz' | 'unknown';
151
+ /** How the source CRS was established. */
152
+ readonly provenance: TilesetSpatialReferenceProvenance;
153
+ /** Target CRS selected by application options, if any. */
154
+ readonly targetCrs?: ReadonlyCRSDefinition;
155
+ /** Target height interpretation selected by application options. */
156
+ readonly targetHeightReference: TilesetTargetHeightReference;
157
+ /** Output representation selected by application options. */
158
+ readonly outputCoordinates: TilesetOutputCoordinates;
159
+ /** Whether coordinates are native, ready to transform, transformed, or unresolved. */
160
+ readonly status: 'native' | 'transformable' | 'transformed' | 'unresolved';
161
+ /** Non-fatal qualifications retained for diagnostics and user interfaces. */
162
+ readonly warnings: readonly string[];
163
+ };
164
+
165
+ /** Input used by format adapters to create normalized spatial metadata. */
166
+ export type CreateTilesetSpatialReferenceOptions = {
167
+ /** Discovered source CRS. */
168
+ sourceCrs?: ReadonlyCRSDefinition;
169
+ /** Whether the source CRS was explicit, defaulted, unknown, or absent. */
170
+ sourceCrsState?: SpatialReferenceState;
171
+ /** Serialization or naming form used by the source CRS. */
172
+ sourceCrsRepresentation?: SpatialReferenceRepresentation;
173
+ /** Additional source CRS representations retained by the format. */
174
+ sourceCrsAlternatives?: readonly SpatialReferenceAlternative[];
175
+ /** Discovered vertical CRS. */
176
+ verticalCrs?: ReadonlyCRSDefinition;
177
+ /** Per-component source units, aligned with the stored coordinate order. */
178
+ units?: readonly string[];
179
+ /** Number of meters represented by one discovered source Z unit. */
180
+ verticalUnitScale?: number;
181
+ /** Discovered coordinate epoch. */
182
+ coordinateEpoch?: number;
183
+ /** Discovered height interpretation. */
184
+ heightReference?: TilesetHeightReference;
185
+ /** Format-specific elevation placement rule. */
186
+ elevationMode?: TilesetElevationMode;
187
+ /** Format-specific elevation offset before unit normalization. */
188
+ elevationOffset?: number;
189
+ /** Unit of the format-specific elevation offset. */
190
+ elevationUnit?: string;
191
+ /** Number of meters represented by one elevation-offset unit. */
192
+ elevationUnitScale?: number;
193
+ /** Discovered broad coordinate frame. */
194
+ coordinateFrame?: TilesetCoordinateFrame;
195
+ /** Format wire-axis order. */
196
+ axisOrder?: 'xy' | 'yx' | 'xyz' | 'unknown';
197
+ /** Metadata provenance. */
198
+ provenance?: TilesetSpatialReferenceProvenance;
199
+ /** Non-fatal discovery qualifications. */
200
+ warnings?: readonly string[];
201
+ };
202
+
203
+ /**
204
+ * Combines format discovery with the intentionally small application option surface.
205
+ *
206
+ * @param discovered - Values derived from dataset metadata and format defaults.
207
+ * @param options - Application target options and expert recovery overrides.
208
+ * @returns Normalized immutable spatial metadata.
209
+ */
210
+ export function createTilesetSpatialReference(
211
+ discovered: CreateTilesetSpatialReferenceOptions,
212
+ options: TilesetSpatialOptions = {}
213
+ ): TilesetSpatialReference {
214
+ const hasSourceCrsOverride = options.sourceCrs !== undefined;
215
+ const sourceCrs = options.sourceCrs || discovered.sourceCrs;
216
+ const outputCoordinates = options.outputCoordinates || 'auto';
217
+ const targetCrs = options.targetCrs || (outputCoordinates === 'ecef' ? 'EPSG:4978' : undefined);
218
+ const targetHeightReference = options.targetHeightReference || 'native';
219
+ const verticalUnitScale = discovered.verticalUnitScale ?? 1;
220
+ const elevationUnitScale = discovered.elevationUnitScale ?? 1;
221
+ const elevationOffset = discovered.elevationOffset || 0;
222
+ const requiresSurface =
223
+ discovered.elevationMode === 'onTheGround' ||
224
+ discovered.elevationMode === 'relativeToGround' ||
225
+ discovered.elevationMode === 'relativeToScene';
226
+ const hasElevationProvider =
227
+ discovered.elevationMode === 'relativeToScene'
228
+ ? Boolean(options.sceneElevationProvider)
229
+ : !requiresSurface || Boolean(options.terrainElevationProvider);
230
+ const hasFormatVerticalOperation =
231
+ verticalUnitScale !== 1 ||
232
+ elevationUnitScale !== 1 ||
233
+ (discovered.elevationMode !== undefined &&
234
+ (requiresSurface ||
235
+ (discovered.elevationMode === 'absoluteHeight' && elevationOffset !== 0)));
236
+ const needsHeightTransform =
237
+ targetHeightReference !== 'native' && targetHeightReference !== discovered.heightReference;
238
+ const hasRequestedTransform =
239
+ Boolean(targetCrs) ||
240
+ targetHeightReference !== 'native' ||
241
+ outputCoordinates !== 'auto' ||
242
+ hasFormatVerticalOperation;
243
+ const hasRequiredTarget = outputCoordinates !== 'target-crs' || Boolean(targetCrs);
244
+ const hasHeightMetadata =
245
+ !needsHeightTransform || (discovered.heightReference || 'unknown') !== 'unknown';
246
+ const hasVerticalUnits =
247
+ Number.isFinite(verticalUnitScale) &&
248
+ verticalUnitScale > 0 &&
249
+ Number.isFinite(elevationUnitScale) &&
250
+ elevationUnitScale > 0;
251
+ const canTransform =
252
+ Boolean(sourceCrs) &&
253
+ hasRequestedTransform &&
254
+ hasRequiredTarget &&
255
+ hasHeightMetadata &&
256
+ hasVerticalUnits &&
257
+ hasElevationProvider &&
258
+ outputCoordinates !== 'local-enu';
259
+
260
+ const provenance = hasSourceCrsOverride ? 'caller-override' : discovered.provenance || 'unknown';
261
+ const coordinateFrame =
262
+ hasSourceCrsOverride && sourceCrs
263
+ ? getSpatialCoordinateFrame(sourceCrs)
264
+ : discovered.coordinateFrame;
265
+ const sourceCrsState = hasSourceCrsOverride
266
+ ? 'explicit'
267
+ : discovered.sourceCrsState ||
268
+ (sourceCrs ? (provenance === 'format-default' ? 'default' : 'explicit') : 'absent');
269
+ const spatialReference = createSpatialReference({
270
+ crs: sourceCrs
271
+ ? {
272
+ state: sourceCrsState === 'default' ? 'default' : 'explicit',
273
+ definition: sourceCrs,
274
+ representation:
275
+ (!hasSourceCrsOverride && discovered.sourceCrsRepresentation) ||
276
+ inferCRSRepresentation(sourceCrs),
277
+ provenance,
278
+ alternatives: hasSourceCrsOverride ? undefined : discovered.sourceCrsAlternatives
279
+ }
280
+ : {
281
+ state: sourceCrsState === 'unknown' ? 'unknown' : 'absent',
282
+ provenance
283
+ },
284
+ vertical: discovered.verticalCrs
285
+ ? {
286
+ state: 'explicit',
287
+ definition: discovered.verticalCrs,
288
+ representation: inferCRSRepresentation(discovered.verticalCrs),
289
+ provenance: discovered.provenance || 'metadata'
290
+ }
291
+ : undefined,
292
+ coordinateEpoch: options.coordinateEpoch ?? discovered.coordinateEpoch,
293
+ coordinateFrame,
294
+ coordinateOrder: getCoordinateOrder(discovered.axisOrder),
295
+ units: hasSourceCrsOverride ? undefined : discovered.units
296
+ });
297
+ const normalizedSourceCrs = getKnownCRSDefinition(spatialReference.crs);
298
+ const normalizedVerticalCrs = spatialReference.vertical
299
+ ? getKnownCRSDefinition(spatialReference.vertical)
300
+ : undefined;
301
+ const normalizedTargetCrs = targetCrs ? cloneReadonlyCRSDefinition(targetCrs) : undefined;
302
+
303
+ return Object.freeze({
304
+ ...spatialReference,
305
+ sourceCrs: normalizedSourceCrs,
306
+ verticalCrs: normalizedVerticalCrs,
307
+ verticalUnitScale,
308
+ coordinateEpoch: options.coordinateEpoch ?? discovered.coordinateEpoch,
309
+ heightReference: discovered.heightReference || 'unknown',
310
+ elevationMode: discovered.elevationMode,
311
+ elevationOffset: discovered.elevationOffset,
312
+ elevationUnit: discovered.elevationUnit,
313
+ elevationUnitScale,
314
+ coordinateFrame: coordinateFrame || 'unknown',
315
+ axisOrder: discovered.axisOrder || 'unknown',
316
+ provenance,
317
+ targetCrs: normalizedTargetCrs,
318
+ targetHeightReference,
319
+ outputCoordinates,
320
+ status: hasRequestedTransform ? (canTransform ? 'transformable' : 'unresolved') : 'native',
321
+ warnings: Object.freeze([...(discovered.warnings || [])])
322
+ });
323
+ }
324
+
325
+ /**
326
+ * Applies application target and recovery options to format-discovered spatial metadata.
327
+ *
328
+ * @param discovered - Readonly metadata returned by a format adapter.
329
+ * @param options - Application target options and expert recovery overrides.
330
+ * @returns A new normalized immutable descriptor.
331
+ */
332
+ export function applyTilesetSpatialOptions(
333
+ discovered: TilesetSpatialReference | undefined,
334
+ options: TilesetSpatialOptions = {}
335
+ ): TilesetSpatialReference {
336
+ return createTilesetSpatialReference(
337
+ {
338
+ sourceCrs: discovered?.sourceCrs,
339
+ sourceCrsState: discovered?.crs.state,
340
+ sourceCrsRepresentation:
341
+ discovered?.crs.state === 'explicit' || discovered?.crs.state === 'default'
342
+ ? discovered.crs.representation
343
+ : undefined,
344
+ sourceCrsAlternatives:
345
+ discovered?.crs.state === 'explicit' || discovered?.crs.state === 'default'
346
+ ? discovered.crs.alternatives
347
+ : undefined,
348
+ verticalCrs: discovered?.verticalCrs,
349
+ units: discovered?.units,
350
+ verticalUnitScale: discovered?.verticalUnitScale,
351
+ coordinateEpoch: discovered?.coordinateEpoch,
352
+ heightReference: discovered?.heightReference,
353
+ elevationMode: discovered?.elevationMode,
354
+ elevationOffset: discovered?.elevationOffset,
355
+ elevationUnit: discovered?.elevationUnit,
356
+ elevationUnitScale: discovered?.elevationUnitScale,
357
+ coordinateFrame: discovered?.coordinateFrame,
358
+ axisOrder: discovered?.axisOrder,
359
+ provenance: discovered?.provenance,
360
+ warnings: discovered?.warnings
361
+ },
362
+ options
363
+ );
364
+ }
365
+
366
+ /** Return a known definition from a canonical CRS reference. */
367
+ function getKnownCRSDefinition(
368
+ reference: SpatialReference['crs']
369
+ ): ReadonlyCRSDefinition | undefined {
370
+ return reference.state === 'explicit' || reference.state === 'default'
371
+ ? reference.definition
372
+ : undefined;
373
+ }
374
+
375
+ /** Clone and deeply freeze a target CRS through the canonical math.gl constructor. */
376
+ function cloneReadonlyCRSDefinition(definition: ReadonlyCRSDefinition): ReadonlyCRSDefinition {
377
+ const spatialReference = createSpatialReference({
378
+ crs: {
379
+ state: 'explicit',
380
+ definition,
381
+ representation: inferCRSRepresentation(definition),
382
+ provenance: 'caller-override'
383
+ }
384
+ });
385
+ const clonedDefinition = getKnownCRSDefinition(spatialReference.crs);
386
+ if (!clonedDefinition) {
387
+ throw new Error('Failed to normalize a known target CRS definition');
388
+ }
389
+ return clonedDefinition;
390
+ }
391
+
392
+ /** Convert the legacy tileset axis label to the common stored-coordinate order. */
393
+ function getCoordinateOrder(
394
+ axisOrder: CreateTilesetSpatialReferenceOptions['axisOrder']
395
+ ): readonly string[] {
396
+ switch (axisOrder) {
397
+ case 'xy':
398
+ return ['x', 'y'];
399
+ case 'yx':
400
+ return ['y', 'x'];
401
+ case 'xyz':
402
+ return ['x', 'y', 'z'];
403
+ default:
404
+ return [];
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Marks a normalized descriptor after every returned coordinate and bound has entered its target
410
+ * frame.
411
+ *
412
+ * @param spatialReference - Transformable spatial descriptor.
413
+ * @returns An immutable descriptor with `status: 'transformed'`.
414
+ */
415
+ export function markTilesetSpatialReferenceTransformed(
416
+ spatialReference: TilesetSpatialReference
417
+ ): TilesetSpatialReference {
418
+ if (spatialReference.status !== 'transformable' && spatialReference.status !== 'transformed') {
419
+ throw new Error('Only a transformable spatial reference can be marked as transformed');
420
+ }
421
+ return Object.freeze({...spatialReference, status: 'transformed'});
422
+ }