@spacexr/tiles 0.0.0-stage → 0.1.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.
Files changed (119) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +57 -2
  3. package/dist/addressing/index.d.ts +16 -0
  4. package/dist/addressing/index.js +4 -0
  5. package/dist/addressing/index.js.map +1 -0
  6. package/dist/bake/index.d.ts +91 -0
  7. package/dist/bake/index.js +3 -0
  8. package/dist/bake/index.js.map +1 -0
  9. package/dist/celestial-dataset-CUIsplKO.d.ts +99 -0
  10. package/dist/chunk-2HLQXRDD.js +246 -0
  11. package/dist/chunk-2HLQXRDD.js.map +1 -0
  12. package/dist/chunk-6YNCRDEE.js +170 -0
  13. package/dist/chunk-6YNCRDEE.js.map +1 -0
  14. package/dist/chunk-7AWV2IEK.js +79 -0
  15. package/dist/chunk-7AWV2IEK.js.map +1 -0
  16. package/dist/chunk-ESLGXWQR.js +219 -0
  17. package/dist/chunk-ESLGXWQR.js.map +1 -0
  18. package/dist/chunk-FB57CZDK.js +312 -0
  19. package/dist/chunk-FB57CZDK.js.map +1 -0
  20. package/dist/chunk-GRTG4WNA.js +44 -0
  21. package/dist/chunk-GRTG4WNA.js.map +1 -0
  22. package/dist/chunk-HVYN4AIT.js +45 -0
  23. package/dist/chunk-HVYN4AIT.js.map +1 -0
  24. package/dist/chunk-IGNRXAW3.js +77 -0
  25. package/dist/chunk-IGNRXAW3.js.map +1 -0
  26. package/dist/chunk-QGTREKHS.js +145 -0
  27. package/dist/chunk-QGTREKHS.js.map +1 -0
  28. package/dist/chunk-SPDRAY37.js +56 -0
  29. package/dist/chunk-SPDRAY37.js.map +1 -0
  30. package/dist/chunk-TA4BEVHL.js +81 -0
  31. package/dist/chunk-TA4BEVHL.js.map +1 -0
  32. package/dist/chunk-TGOB5HT5.js +149 -0
  33. package/dist/chunk-TGOB5HT5.js.map +1 -0
  34. package/dist/chunk-X6ZJ2PDY.js +104 -0
  35. package/dist/chunk-X6ZJ2PDY.js.map +1 -0
  36. package/dist/chunk-XTY4HCPY.js +22 -0
  37. package/dist/chunk-XTY4HCPY.js.map +1 -0
  38. package/dist/chunk-Y66PNDG2.js +107 -0
  39. package/dist/chunk-Y66PNDG2.js.map +1 -0
  40. package/dist/chunk-YEACOJOC.js +51 -0
  41. package/dist/chunk-YEACOJOC.js.map +1 -0
  42. package/dist/cube/index.d.ts +160 -0
  43. package/dist/cube/index.js +9 -0
  44. package/dist/cube/index.js.map +1 -0
  45. package/dist/datasets/index.d.ts +75 -0
  46. package/dist/datasets/index.js +11 -0
  47. package/dist/datasets/index.js.map +1 -0
  48. package/dist/index.d.ts +22 -0
  49. package/dist/index.js +18 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/mercator/index.d.ts +24 -0
  52. package/dist/mercator/index.js +8 -0
  53. package/dist/mercator/index.js.map +1 -0
  54. package/dist/metrics-HGbzqj6L.d.ts +45 -0
  55. package/dist/pyramid/index.d.ts +156 -0
  56. package/dist/pyramid/index.js +4 -0
  57. package/dist/pyramid/index.js.map +1 -0
  58. package/dist/raster-registration-CgBxrhDB.d.ts +19 -0
  59. package/dist/reference-surface-CsTtrNsc.d.ts +49 -0
  60. package/dist/reprojection/index.d.ts +255 -0
  61. package/dist/reprojection/index.js +6 -0
  62. package/dist/reprojection/index.js.map +1 -0
  63. package/dist/sources/index.d.ts +55 -0
  64. package/dist/sources/index.js +7 -0
  65. package/dist/sources/index.js.map +1 -0
  66. package/dist/surface/index.d.ts +15 -0
  67. package/dist/surface/index.js +4 -0
  68. package/dist/surface/index.js.map +1 -0
  69. package/dist/tile-D-jjIRRA.d.ts +53 -0
  70. package/dist/tile-address-BkfSftp6.d.ts +66 -0
  71. package/dist/tile-http-client-BHZOtGX7.d.ts +73 -0
  72. package/dist/tile-neighbors-LfvV7oiX.d.ts +48 -0
  73. package/dist/tile-surface-s9Zi6X9_.d.ts +40 -0
  74. package/dist/tile-topology-B6xHYqPb.d.ts +51 -0
  75. package/dist/web-mercator-dataset-Dmou8byO.d.ts +125 -0
  76. package/dist/web-tile-source-DrZDBIm6.d.ts +92 -0
  77. package/package.json +122 -5
  78. package/src/addressing/index.ts +8 -0
  79. package/src/addressing/metrics.ts +48 -0
  80. package/src/addressing/raster-registration.ts +22 -0
  81. package/src/addressing/tile-address.ts +130 -0
  82. package/src/addressing/tile-edge-rotation.ts +13 -0
  83. package/src/addressing/tile-neighbors.ts +73 -0
  84. package/src/addressing/tile-surface.ts +44 -0
  85. package/src/addressing/tile-topology.ts +86 -0
  86. package/src/addressing/tile.ts +73 -0
  87. package/src/bake/bake-pyramid.ts +106 -0
  88. package/src/bake/index.ts +2 -0
  89. package/src/bake/pyramid-levels.ts +63 -0
  90. package/src/cube/celestial-dataset.ts +182 -0
  91. package/src/cube/cube-face.ts +51 -0
  92. package/src/cube/cube-geometric-error.ts +30 -0
  93. package/src/cube/cube-mapping.ts +101 -0
  94. package/src/cube/cube-neighbors.ts +198 -0
  95. package/src/cube/cube-tile-surface.ts +30 -0
  96. package/src/cube/index.ts +6 -0
  97. package/src/datasets/index.ts +1 -0
  98. package/src/datasets/tile-dataset.ts +121 -0
  99. package/src/index.ts +9 -0
  100. package/src/mercator/index.ts +3 -0
  101. package/src/mercator/web-mercator-dataset.ts +215 -0
  102. package/src/mercator/web-mercator-tile-metrics.ts +119 -0
  103. package/src/mercator/web-mercator-tile-surface.ts +52 -0
  104. package/src/pyramid/index.ts +2 -0
  105. package/src/pyramid/resident-tiles.ts +81 -0
  106. package/src/pyramid/tile-pyramid.ts +285 -0
  107. package/src/reprojection/cube-resampling.ts +159 -0
  108. package/src/reprojection/index.ts +4 -0
  109. package/src/reprojection/source-projection.ts +196 -0
  110. package/src/reprojection/source-tile-matrix.ts +100 -0
  111. package/src/reprojection/wmts-capabilities.ts +112 -0
  112. package/src/sources/index.ts +4 -0
  113. package/src/sources/tile-http-client.ts +154 -0
  114. package/src/sources/tile-layer-changes.ts +88 -0
  115. package/src/sources/url-template.ts +96 -0
  116. package/src/sources/web-tile-source.ts +73 -0
  117. package/src/surface/directions.ts +27 -0
  118. package/src/surface/index.ts +2 -0
  119. package/src/surface/reference-surface.ts +88 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/reprojection/source-tile-matrix.ts","../src/reprojection/cube-resampling.ts","../src/reprojection/source-projection.ts","../src/reprojection/wmts-capabilities.ts"],"names":["periodPixels"],"mappings":";;;;;AA4CO,SAAS,sBAAA,CAAuB,QAA2B,QAAA,EAAkC,MAAA,GAAuB,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE,EAAiB;AACrJ,EAAA,wBAAA,CAAyB,OAAO,YAAY,CAAA;AAC5C,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,YAAA,KAAiB,MAAA,GAAS,GAAA,GAAM,CAAA;AACtD,EAAA,MAAA,CAAO,KAAK,QAAA,CAAS,CAAA,GAAI,MAAA,CAAO,OAAA,IAAW,OAAO,SAAA,GAAY,MAAA;AAC9D,EAAA,MAAA,CAAO,KAAK,MAAA,CAAO,OAAA,GAAU,QAAA,CAAS,CAAA,IAAK,OAAO,SAAA,GAAY,MAAA;AAC9D,EAAA,OAAO,MAAA;AACX;AAQO,SAAS,aAAA,CAAc,MAAA,EAA2B,MAAA,EAAgB,MAAA,EAAgBA,aAAAA,EAAiD;AACtI,EAAA,IAAI,CAAA,GAAI,MAAA;AACR,EAAA,IAAIA,aAAAA,KAAiB,MAAA,EAAW,CAAA,GAAA,CAAM,CAAA,GAAIA,gBAAgBA,aAAAA,IAAgBA,aAAAA;AAC1E,EAAA,IAAI,CAAA,GAAI,CAAA,IAAK,MAAA,GAAS,CAAA,EAAG,OAAO,MAAA;AAChC,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,CAAA,GAAI,OAAO,SAAS,CAAA;AAC9C,EAAA,MAAM,GAAA,GAAM,IAAA,CAAK,KAAA,CAAM,MAAA,GAAS,OAAO,UAAU,CAAA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A;AAAA,IAC5B,KAAA,EAAA,CAAQ,KAAA,IAAS,IAAA,CAAK,KAAA,EAAO,gBAAgB,CAAA,KAAM,SAAA;AAAA,IACnD,aAAA,EAAe,GAAA;AAAA,IACf,WAAA,EAAa,MAAM,MAAA,KAAW,CAAA,IAAK,MAAM,MAAA,KAAW,CAAA,GAAI,CAAC,KAAA,CAAM,CAAC,GAAI,KAAA,CAAM,CAAC,GAAI,KAAA,CAAM,CAAC,GAAI,KAAA,CAAM,CAAC,CAAE,CAAA,GAAI,MAAA;AAAA,IACvG,WAAA,EAAa,uCAAA,CAAwC,IAAA,CAAK,KAAK,IAAI,CAAC,CAAA;AAAA,IACpE;AAAA,GACJ;AACJ;AAOO,SAAS,WAAA,CAAY,KAAA,EAAmB,MAAA,EAA2B,GAAA,EAAa,MAAA,EAAwB;AAC3G,EAAA,IAAI,KAAA,CAAM,gBAAgB,MAAA,EAAW,MAAM,IAAI,UAAA,CAAW,CAAA,UAAA,EAAa,KAAA,CAAM,UAAU,CAAA,sBAAA,CAAwB,CAAA;AAC/G,EAAA,MAAM,GAAA,GAAM,KAAA,CAAM,WAAA,CACb,UAAA,CAAW,WAAW,KAAA,CAAM,KAAK,CAAA,CACjC,UAAA,CAAW,SAAA,EAAW,KAAA,CAAM,KAAK,CAAA,CACjC,WAAW,iBAAA,EAAmB,KAAA,CAAM,aAAa,CAAA,CACjD,UAAA,CAAW,cAAA,EAAgB,MAAA,CAAO,UAAU,EAC5C,UAAA,CAAW,WAAA,EAAa,MAAA,CAAO,GAAG,CAAC,CAAA,CACnC,UAAA,CAAW,WAAA,EAAa,MAAA,CAAO,MAAM,CAAC,CAAA;AAC3C,EAAA,OAAO,GAAA,CAAI,OAAA,CAAQ,gBAAA,EAAkB,KAAK,CAAA;AAC9C","file":"chunk-FB57CZDK.js","sourcesContent":["import { assertRasterRegistration, type RasterRegistration } from \"../addressing\";\n\nimport type { IMapPosition } from \"./source-projection\";\n\n/**\n * One level of the tiles of a raster source. The pixel size is explicit: it cannot always be read from a WMTS\n * `ScaleDenominator`, and the matrix may be larger than the map: a A provider polar matrix of 2 x 1 tiles has its whole map\n * in the first column.\n */\nexport interface ISourceTileMatrix {\n identifier: string;\n /** Where the pixels lie, required: a WMTS or XYZ tile is `area`; a GeoTIFF declares it in its `GTRasterTypeGeoKey`. */\n registration: RasterRegistration;\n /** Map position of the outer corner of the first pixel in `area` registration, of its centre in `point` registration. */\n originX: number;\n originY: number;\n /** Map units per pixel. Rows run toward decreasing `y`. */\n pixelSize: number;\n tileWidth: number;\n tileHeight: number;\n matrixWidth: number;\n matrixHeight: number;\n}\n\n/** A pixel of a source tile. */\nexport interface ISourcePixel {\n column: number;\n row: number;\n /** Pixel in the tile, 0 at its west and north. */\n x: number;\n y: number;\n}\n\n/** Tile of a source. */\nexport interface ISourceTile {\n column: number;\n row: number;\n}\n\n/**\n * Fractional pixel of a map position, over the whole matrix: pixel `n` has its centre at `n`.\n *\n * @throws TypeError When the matrix does not declare its registration.\n */\nexport function sourcePixelCoordinates(matrix: ISourceTileMatrix, position: Readonly<IMapPosition>, target: IMapPosition = { x: 0, y: 0 }): IMapPosition {\n assertRasterRegistration(matrix.registration);\n const offset = matrix.registration === \"area\" ? 0.5 : 0;\n target.x = (position.x - matrix.originX) / matrix.pixelSize - offset;\n target.y = (matrix.originY - position.y) / matrix.pixelSize - offset;\n return target;\n}\n\n/**\n * The tile and the pixel holding a pixel of the matrix.\n *\n * @param periodPixels - Width of the map in pixels when it wraps around the body; columns then wrap.\n * @returns `undefined` beyond the matrix.\n */\nexport function sourcePixelAt(matrix: ISourceTileMatrix, pixelX: number, pixelY: number, periodPixels?: number): ISourcePixel | undefined {\n let x = pixelX;\n if (periodPixels !== undefined) x = ((x % periodPixels) + periodPixels) % periodPixels;\n if (x < 0 || pixelY < 0) return undefined;\n const column = Math.floor(x / matrix.tileWidth);\n const row = Math.floor(pixelY / matrix.tileHeight);\n if (column >= matrix.matrixWidth || row >= matrix.matrixHeight) return undefined;\n return { column, row, x: x - column * matrix.tileWidth, y: pixelY - row * matrix.tileHeight };\n}\n\n/** The tile matrix of a level of an XYZ Web Mercator pyramid, EPSG:3857: rows from the north, 2^level tiles per side. */\nexport function webMercatorTileMatrix(level: number, tileSize = 256, semiMajorAxis: number): ISourceTileMatrix {\n const half = Math.PI * semiMajorAxis;\n const tiles = 2 ** level;\n return {\n identifier: String(level),\n registration: \"area\",\n originX: -half,\n originY: half,\n pixelSize: (2 * half) / (tiles * tileSize),\n tileWidth: tileSize,\n tileHeight: tileSize,\n matrixWidth: tiles,\n matrixHeight: tiles,\n };\n}\n\n/** The tile matrix of a level of a global geographic pyramid, such as A provider: 2 x 1 tiles at level 0, from -180 and 90. */\nexport function geographicTileMatrix(level: number, tileSize = 256): ISourceTileMatrix {\n const tiles = 2 ** level;\n return {\n identifier: String(level),\n registration: \"area\",\n originX: -180,\n originY: 90,\n pixelSize: 180 / (tiles * tileSize),\n tileWidth: tileSize,\n tileHeight: tileSize,\n matrixWidth: 2 * tiles,\n matrixHeight: tiles,\n };\n}\n","import type { ICartesian3 } from \"@spacexr/geodesy\";\n\nimport { tileCount, type ITileAddress } from \"../addressing/tile-address\";\nimport { cubeTileDirection } from \"../cube/cube-mapping\";\nimport type { ReferenceSurface } from \"../surface/reference-surface\";\nimport type { IMapPosition, ISourceProjection } from \"./source-projection\";\nimport { sourcePixelAt, sourcePixelCoordinates, type ISourceTile, type ISourceTileMatrix } from \"./source-tile-matrix\";\n\n/** A raster source seen from the cube: its projection and the level it is read at. */\nexport interface ICubeSourceLevel {\n projection: ISourceProjection;\n matrix: ISourceTileMatrix;\n}\n\n/** Period of a map, in pixels of a matrix, when it wraps around the body. */\nfunction periodPixels({ projection, matrix }: ICubeSourceLevel): number | undefined {\n return projection.periodX === undefined ? undefined : projection.periodX / matrix.pixelSize;\n}\n\n/**\n * Coarsest level of a source at least as fine as a level of the cube, the last one otherwise. It depends on the level of\n * the cube alone, so both sides of a tile edge read the same level. On a global geographic source, it is `lod + 1`.\n *\n * @param bodyRadius - Radius of the body, in metres.\n * @param lod - Level of the cube.\n * @param tileSize - Cells per side of the tiles of the cube.\n * @param matrices - Levels of the source, from the coarsest.\n * @throws RangeError When the source has no level.\n */\nexport function cubeSourceMatrix(projection: ISourceProjection, matrices: readonly ISourceTileMatrix[], bodyRadius: number, lod: number, tileSize = 256): ISourceTileMatrix {\n if (matrices.length === 0) throw new RangeError(\"The source has no level.\");\n const spacing = (Math.PI / 2) * (bodyRadius / (tileSize * tileCount(lod)));\n return matrices.find((matrix) => matrix.pixelSize * projection.metresPerUnit <= spacing * (1 + 1e-9)) ?? matrices[matrices.length - 1]!;\n}\n\n/** Runs through the `(tileSize + 1)^2` samples of a tile of the cube, in rows from its north-west corner. */\nfunction forEachSample(address: ITileAddress, tileSize: number, visit: (index: number, direction: Readonly<ICartesian3>) => void): void {\n const side = tileSize + 1;\n const direction: ICartesian3 = { x: 0, y: 0, z: 0 };\n for (let row = 0; row < side; row++) {\n for (let column = 0; column < side; column++) {\n cubeTileDirection(address, column / tileSize, row / tileSize, direction);\n visit(row * side + column, direction);\n }\n }\n}\n\n/**\n * The tiles of a source that the samples of a tile of the cube read, to load before {@link resampleCubeTile}.\n *\n * @param tileSize - Cells per side of the tile of the cube. Defaults to 256.\n */\nexport function cubeTileSourceTiles(address: ITileAddress, source: ICubeSourceLevel, tileSize = 256): ISourceTile[] {\n const found = new Map<string, ISourceTile>();\n const period = periodPixels(source);\n const position: IMapPosition = { x: 0, y: 0 };\n const pixel: IMapPosition = { x: 0, y: 0 };\n forEachSample(address, tileSize, (_index, direction) => {\n sourcePixelCoordinates(source.matrix, source.projection.forward(direction, position), pixel);\n const left = Math.floor(pixel.x);\n const top = Math.floor(pixel.y);\n for (const [dx, dy] of [\n [0, 0],\n [1, 0],\n [0, 1],\n [1, 1],\n ] as const) {\n const at = sourcePixelAt(source.matrix, left + dx, top + dy, period);\n if (at) found.set(`${at.column}/${at.row}`, { column: at.column, row: at.row });\n }\n });\n return [...found.values()];\n}\n\n/**\n * Value of a source at a pixel of a loaded tile, `NaN` where it has none: a missing tile, or its no-data value.\n *\n * @param column - Column of the tile.\n * @param row - Row of the tile.\n * @param x - Pixel in the tile.\n * @param y - Pixel in the tile.\n * @param channel - Channel of the pixel.\n */\nexport type SourcePixelReader = (column: number, row: number, x: number, y: number, channel: number) => number;\n\nexport interface IResampleCubeTileOptions {\n /** Cells per side of the tile of the cube. Defaults to 256: 257 samples per side. */\n tileSize?: number;\n /** Channels per sample. Defaults to 1. */\n channels?: number;\n /** Receives the samples, channels interleaved. Defaults to a new array. */\n target?: Float32Array;\n}\n\n/**\n * Reads a source at the samples of a tile of the cube, bilinearly in its pixels: `(tileSize + 1)^2` samples in point\n * registration. A sample depends on its direction alone, so tiles sharing an edge hold the same samples on it, across cube\n * faces included. Pixels without data are left out of the interpolation; a sample with none is `NaN`.\n *\n * @throws RangeError When a supplied target has another length.\n */\nexport function resampleCubeTile(address: ITileAddress, source: ICubeSourceLevel, read: SourcePixelReader, options: IResampleCubeTileOptions = {}): Float32Array {\n const tileSize = options.tileSize ?? 256;\n const channels = options.channels ?? 1;\n const length = (tileSize + 1) ** 2 * channels;\n const data = options.target ?? new Float32Array(length);\n if (data.length !== length) throw new RangeError(`A tile of ${tileSize} cells needs ${length} values, not ${data.length}.`);\n const period = periodPixels(source);\n const position: IMapPosition = { x: 0, y: 0 };\n const pixel: IMapPosition = { x: 0, y: 0 };\n forEachSample(address, tileSize, (index, direction) => {\n sourcePixelCoordinates(source.matrix, source.projection.forward(direction, position), pixel);\n const left = Math.floor(pixel.x);\n const top = Math.floor(pixel.y);\n const fx = pixel.x - left;\n const fy = pixel.y - top;\n for (let channel = 0; channel < channels; channel++) {\n let sum = 0;\n let weights = 0;\n for (const [dx, dy, weight] of [\n [0, 0, (1 - fx) * (1 - fy)],\n [1, 0, fx * (1 - fy)],\n [0, 1, (1 - fx) * fy],\n [1, 1, fx * fy],\n ] as const) {\n if (weight === 0) continue;\n const at = sourcePixelAt(source.matrix, left + dx, top + dy, period);\n const value = at ? read(at.column, at.row, at.x, at.y, channel) : Number.NaN;\n if (Number.isNaN(value)) continue;\n sum += value * weight;\n weights += weight;\n }\n data[index * channels + channel] = weights > 0 ? sum / weights : Number.NaN;\n }\n });\n return data;\n}\n\n/**\n * Radial height over a reference surface of a source whose heights are radial over a sphere, such as LOLA over 1737.4 km:\n * `h + sourceRadius - radius(direction)`. It is the height itself when both surfaces are that sphere.\n */\nexport function rebaseRadialHeight(height: number, sourceRadius: number, reference: ReferenceSurface, direction: Readonly<ICartesian3>): number {\n return height + sourceRadius - reference.radius(direction);\n}\n\n/**\n * Weight of a polar source against a global one, from a unit direction: 0 up to `fromDegrees` of latitude, 1 from\n * `toDegrees`, smooth in between. It depends on the direction alone, so shared edges stay identical. Latitudes are\n * planetocentric and absolute.\n *\n * @throws RangeError When `toDegrees` does not exceed `fromDegrees`.\n */\nexport function capBlendWeight(direction: Readonly<ICartesian3>, fromDegrees: number, toDegrees: number): number {\n if (!(toDegrees > fromDegrees)) throw new RangeError(\"A cap blend must end beyond its start.\");\n const latitude = (Math.atan2(Math.abs(direction.z), Math.hypot(direction.x, direction.y)) * 180) / Math.PI;\n const t = Math.min(Math.max((latitude - fromDegrees) / (toDegrees - fromDegrees), 0), 1);\n return t * t * (3 - 2 * t);\n}\n","import type { ICartesian3 } from \"@spacexr/geodesy\";\n\nconst DEGREES = 180 / Math.PI;\n\n/** Position in the map of a source: degrees for a geographic source, metres for a projected one. */\nexport interface IMapPosition {\n x: number;\n y: number;\n}\n\n/**\n * Projection of a raster source: from a unit direction of the body-fixed frame to the map of the source, and back. The\n * unit directions go through it, whatever the source. Latitude conventions are explicit: each\n * projection states which latitude its source uses.\n */\nexport interface ISourceProjection {\n /** Map position of a unit direction. */\n forward(direction: Readonly<ICartesian3>, target?: IMapPosition): IMapPosition;\n /** Unit direction of a map position. */\n inverse(x: number, y: number, target?: ICartesian3): ICartesian3;\n /** Metres on the ground per map unit, at the reference of the map. */\n readonly metresPerUnit: number;\n /** Width of the map along `x` when it wraps around the body, as a global geographic map does. */\n readonly periodX: number | undefined;\n}\n\nexport interface IGeographicProjectionOptions {\n /** Equatorial radius of the body, in metres. */\n semiMajorAxis: number;\n /**\n * Polar radius of the ellipsoid of the source, for a source with geodetic latitudes such as EPSG:4326. Defaults to\n * `semiMajorAxis`: on a sphere, latitudes are planetocentric.\n */\n semiMinorAxis?: number;\n /** Longitude of the centre of the map, in degrees. Defaults to 0: longitudes run from -180 to 180. */\n centralMeridianDegrees?: number;\n}\n\n/** Geographic map, plate carree: `x` is the longitude and `y` the latitude, in degrees. */\nexport class GeographicProjection implements ISourceProjection {\n public readonly metresPerUnit: number;\n public readonly periodX = 360;\n private readonly squaredRatio: number;\n private readonly centralMeridian: number;\n\n public constructor(options: IGeographicProjectionOptions) {\n const { semiMajorAxis: a, semiMinorAxis: b = a } = options;\n if (!(a > 0) || !(b > 0)) throw new RangeError(\"The radii of a projection must be positive.\");\n this.metresPerUnit = (Math.PI / 180) * a;\n this.squaredRatio = (a * a) / (b * b);\n this.centralMeridian = options.centralMeridianDegrees ?? 0;\n }\n\n public forward(direction: Readonly<ICartesian3>, target: IMapPosition = { x: 0, y: 0 }): IMapPosition {\n // tan(geodetic) = (a^2 / b^2) tan(planetocentric); the ratio is 1 on a sphere.\n target.y = Math.atan2(direction.z * this.squaredRatio, Math.hypot(direction.x, direction.y)) * DEGREES;\n target.x = wrapDegrees(Math.atan2(direction.y, direction.x) * DEGREES - this.centralMeridian);\n return target;\n }\n\n public inverse(x: number, y: number, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n const longitude = (x + this.centralMeridian) / DEGREES;\n const latitude = Math.atan2(Math.sin(y / DEGREES), Math.cos(y / DEGREES) * this.squaredRatio);\n target.x = Math.cos(latitude) * Math.cos(longitude);\n target.y = Math.cos(latitude) * Math.sin(longitude);\n target.z = Math.sin(latitude);\n return target;\n }\n}\n\nfunction wrapDegrees(degrees: number): number {\n if (degrees < -180) return degrees + 360;\n if (degrees >= 180) return degrees - 360;\n return degrees;\n}\n\nexport interface IPolarStereographicProjectionOptions {\n pole: \"north\" | \"south\";\n /** Radius of the sphere of the map, in metres. */\n radius: number;\n /** `central_meridian` of the source, in degrees. Defaults to 0. */\n centralMeridianDegrees?: number;\n /** Defaults to 0. */\n falseEasting?: number;\n /** Defaults to 0. */\n falseNorthing?: number;\n}\n\n/**\n * Polar stereographic map on a sphere, true to scale at the pole, in metres. It reads the direction without any latitude\n * or longitude, so the pole is a point like any other:\n *\n * ```text\n * south: x = 2R dy / (1 - dz), y = 2R dx / (1 - dz)\n * north: x = 2R dy / (1 + dz), y = -2R dx / (1 + dz)\n * ```\n *\n * with `dx`, `dy` turned by the central meridian. It matches `Stereographic_South_Pole` of ESRI and EPSG on a sphere.\n */\nexport class PolarStereographicProjection implements ISourceProjection {\n public readonly metresPerUnit = 1;\n public readonly periodX = undefined;\n private readonly south: boolean;\n private readonly diameter: number;\n private readonly cosine: number;\n private readonly sine: number;\n private readonly falseEasting: number;\n private readonly falseNorthing: number;\n\n public constructor(options: IPolarStereographicProjectionOptions) {\n if (!(options.radius > 0)) throw new RangeError(\"The radius of a projection must be positive.\");\n this.south = options.pole === \"south\";\n this.diameter = 2 * options.radius;\n const meridian = (options.centralMeridianDegrees ?? 0) / DEGREES;\n this.cosine = Math.cos(meridian);\n this.sine = Math.sin(meridian);\n this.falseEasting = options.falseEasting ?? 0;\n this.falseNorthing = options.falseNorthing ?? 0;\n }\n\n public forward(direction: Readonly<ICartesian3>, target: IMapPosition = { x: 0, y: 0 }): IMapPosition {\n const { x, y, z } = direction;\n const dx = x * this.cosine + y * this.sine;\n const dy = y * this.cosine - x * this.sine;\n const scale = this.diameter / (this.south ? 1 - z : 1 + z);\n target.x = dy * scale + this.falseEasting;\n target.y = (this.south ? dx : -dx) * scale + this.falseNorthing;\n return target;\n }\n\n public inverse(x: number, y: number, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n const mapX = (x - this.falseEasting) / this.diameter;\n const mapY = ((this.south ? y : -y) - (this.south ? this.falseNorthing : -this.falseNorthing)) / this.diameter;\n const squared = mapX * mapX + mapY * mapY;\n const denominator = 1 + squared;\n const along = (2 * mapY) / denominator;\n const across = (2 * mapX) / denominator;\n target.x = along * this.cosine - across * this.sine;\n target.y = along * this.sine + across * this.cosine;\n target.z = ((this.south ? -1 : 1) * (1 - squared)) / denominator;\n return target;\n }\n}\n\nexport interface IWebMercatorProjectionOptions {\n /** Radius of the map, in metres. Supplied explicitly in metres. */\n semiMajorAxis: number;\n /** Polar radius of the ellipsoid of the latitudes. Supplied explicitly by the caller. */\n semiMinorAxis?: number;\n}\n\n/**\n * Web Mercator map, EPSG:3857, in metres: spherical formulas applied to geodetic latitudes. It stops at 85.05 degrees: the\n * positions beyond it fall outside the tile matrices, so another source must cover the caps.\n */\nexport class WebMercatorProjection implements ISourceProjection {\n public readonly metresPerUnit = 1;\n public readonly periodX: number;\n private readonly radius: number;\n private readonly squaredRatio: number;\n\n public constructor(options: IWebMercatorProjectionOptions) {\n this.radius = options.semiMajorAxis;\n if (!(this.radius > 0) || !Number.isFinite(this.radius)) throw new RangeError(\"A projection requires a positive finite radius.\");\n const b = options.semiMinorAxis ?? options.semiMajorAxis;\n this.squaredRatio = (this.radius * this.radius) / (b * b);\n this.periodX = 2 * Math.PI * this.radius;\n }\n\n public forward(direction: Readonly<ICartesian3>, target: IMapPosition = { x: 0, y: 0 }): IMapPosition {\n const latitude = Math.atan2(direction.z * this.squaredRatio, Math.hypot(direction.x, direction.y));\n target.x = this.radius * Math.atan2(direction.y, direction.x);\n // Infinite at the poles: those positions fall outside every tile matrix.\n target.y = this.radius * Math.log(Math.tan(Math.PI / 4 + latitude / 2));\n return target;\n }\n\n public inverse(x: number, y: number, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n const longitude = x / this.radius;\n const geodetic = 2 * Math.atan(Math.exp(y / this.radius)) - Math.PI / 2;\n const latitude = Math.atan2(Math.sin(geodetic), Math.cos(geodetic) * this.squaredRatio);\n target.x = Math.cos(latitude) * Math.cos(longitude);\n target.y = Math.cos(latitude) * Math.sin(longitude);\n target.z = Math.sin(latitude);\n return target;\n }\n}\n\n/** Longitude and geodetic latitude of a unit direction on a biaxial ellipsoid, in degrees, for the sources that use them. */\nexport function geodeticOfDirection(direction: Readonly<ICartesian3>, semiMajorAxis: number, semiMinorAxis: number): { latitude: number; longitude: number } {\n const ratio = (semiMajorAxis * semiMajorAxis) / (semiMinorAxis * semiMinorAxis);\n return {\n latitude: Math.atan2(direction.z * ratio, Math.hypot(direction.x, direction.y)) * DEGREES,\n longitude: Math.atan2(direction.y, direction.x) * DEGREES,\n };\n}\n","import type { ISourceTileMatrix } from \"./source-tile-matrix\";\n\n/** A layer read from a WMTS capabilities document. */\nexport interface IWmtsLayer {\n identifier: string;\n /** `SupportedCRS` as written: A provider polar layers write `EPSG::0`, so the projection must come from elsewhere. */\n crs: string | undefined;\n /** Media type of the tiles. An 8-bit format is for display: it holds no elevation. */\n format: string | undefined;\n style: string;\n tileMatrixSet: string;\n /** Coverage of the layer in map units, `[minX, minY, maxX, maxY]`. */\n boundingBox: readonly [number, number, number, number] | undefined;\n /** REST template, with `{Style}`, `{TileMatrixSet}`, `{TileMatrix}`, `{TileRow}` and `{TileCol}`. */\n resourceUrl: string | undefined;\n /** Levels from the coarsest. */\n matrices: readonly ISourceTileMatrix[];\n}\n\n/** Metres per pixel of a WMTS scale denominator: 0.28 mm per pixel on the sheet. */\nconst METRES_PER_SCALE = 0.00028;\n\nfunction block(source: string, tag: string): string[] {\n return [...source.matchAll(new RegExp(`<${tag}(?:\\\\s[^>]*)?>([\\\\s\\\\S]*?)</${tag}>`, \"g\"))].map((match) => match[1]!);\n}\n\nfunction text(source: string, tag: string): string | undefined {\n return new RegExp(`<${tag}(?:\\\\s[^>]*)?>\\\\s*([^<]*?)\\\\s*</${tag}>`).exec(source)?.[1];\n}\n\nfunction numbers(value: string | undefined): number[] {\n return (value ?? \"\").trim().split(/\\s+/).filter(Boolean).map(Number);\n}\n\nfunction required(value: string | undefined, name: string): string {\n if (value === undefined || value === \"\") throw new RangeError(`The WMTS capabilities miss ${name}.`);\n return value;\n}\n\n/**\n * Reads a WMTS capabilities document, whose tiles are images, so in `area` registration, without any XML library, so that it also runs in a Cloudflare Worker, which has no\n * `DOMParser`. Comments are ignored: A provider leaves old tile matrices in them.\n *\n * Pixel sizes come from the geometry of the matrix: the rows of a level span the origin symmetrically, so a pixel is\n * `2 * originY / (MatrixHeight * TileHeight)`, in degrees or in metres. `ScaleDenominator` is not reliable: it assumes\n * source-specific unit assumptions on geographic layers. Geometry-derived pixel size is preferred; the scale is used only when the origin is 0.\n *\n * @param xml - The document.\n * @param layerIdentifier - Layer to read. Defaults to the first one.\n * @throws RangeError When the document, the layer or a value it needs is missing or invalid.\n */\nexport function parseWmtsCapabilities(xml: string, layerIdentifier?: string): IWmtsLayer {\n const source = xml.replace(/<!--[\\s\\S]*?-->/g, \"\");\n const layers = block(source, \"Layer\");\n const layer = layerIdentifier === undefined ? layers[0] : layers.find((candidate) => text(candidate, \"ows:Identifier\") === layerIdentifier);\n if (layer === undefined) throw new RangeError(`The WMTS capabilities have no layer ${layerIdentifier ?? \"\"}.`.trim());\n const set = required(text(required(block(layer, \"TileMatrixSetLink\")[0], \"TileMatrixSetLink\"), \"TileMatrixSet\"), \"TileMatrixSet\");\n const definition = block(source, \"TileMatrixSet\").find((candidate) => text(candidate, \"ows:Identifier\") === set);\n if (definition === undefined) throw new RangeError(`The WMTS capabilities do not define the tile matrix set ${set}.`);\n\n const matrices = block(definition, \"TileMatrix\").map((matrix): ISourceTileMatrix => {\n const identifier = required(text(matrix, \"ows:Identifier\"), \"a TileMatrix identifier\");\n let corner = numbers(text(matrix, \"TopLeftCorner\"));\n // WMTS may write geographic corners latitude first.\n if (corner.length === 2 && Math.abs(corner[1]!) > 90 && Math.abs(corner[1]!) <= 180 && Math.abs(corner[0]!) <= 90) corner = [corner[1]!, corner[0]!];\n const [originX, originY] = corner;\n const scale = Number(text(matrix, \"ScaleDenominator\"));\n const tileWidth = Number(text(matrix, \"TileWidth\"));\n const tileHeight = Number(text(matrix, \"TileHeight\"));\n const matrixWidth = Number(text(matrix, \"MatrixWidth\"));\n const matrixHeight = Number(text(matrix, \"MatrixHeight\"));\n if (![originX, originY, tileWidth, tileHeight, matrixWidth, matrixHeight].every((value) => Number.isFinite(value)) || !(tileWidth > 0)) {\n throw new RangeError(`The tile matrix ${identifier} is invalid.`);\n }\n const pixelSize = originY !== 0 ? (2 * Math.abs(originY!)) / (matrixHeight * tileHeight) : scale * METRES_PER_SCALE;\n if (!(pixelSize > 0)) throw new RangeError(`The tile matrix ${identifier} has no pixel size.`);\n return { identifier, registration: \"area\", originX: originX!, originY: originY!, pixelSize, tileWidth, tileHeight, matrixWidth, matrixHeight };\n });\n if (matrices.length === 0) throw new RangeError(`The tile matrix set ${set} has no tile matrix.`);\n\n const box = block(layer, \"ows:BoundingBox\")[0];\n const lower = numbers(box && text(box, \"ows:LowerCorner\"));\n const upper = numbers(box && text(box, \"ows:UpperCorner\"));\n const style = block(layer, \"Style\")[0];\n return {\n identifier: required(text(layer, \"ows:Identifier\"), \"a layer identifier\"),\n crs: text(definition, \"ows:SupportedCRS\"),\n format: text(layer, \"Format\"),\n style: (style && text(style, \"ows:Identifier\")) ?? \"default\",\n tileMatrixSet: set,\n boundingBox: lower.length === 2 && upper.length === 2 ? [lower[0]!, lower[1]!, upper[0]!, upper[1]!] : undefined,\n resourceUrl: /<ResourceURL[^>]*\\stemplate=\"([^\"]+)\"/.exec(layer)?.[1],\n matrices,\n };\n}\n\n/**\n * URL of a tile of a WMTS layer. Empty path segments are removed: A provider templates hold `1.0.0//{Style}`.\n *\n * @throws RangeError When the layer has no REST template.\n */\nexport function wmtsTileUrl(layer: IWmtsLayer, matrix: ISourceTileMatrix, row: number, column: number): string {\n if (layer.resourceUrl === undefined) throw new RangeError(`The layer ${layer.identifier} has no REST template.`);\n const url = layer.resourceUrl\n .replaceAll(\"{Style}\", layer.style)\n .replaceAll(\"{style}\", layer.style)\n .replaceAll(\"{TileMatrixSet}\", layer.tileMatrixSet)\n .replaceAll(\"{TileMatrix}\", matrix.identifier)\n .replaceAll(\"{TileRow}\", String(row))\n .replaceAll(\"{TileCol}\", String(column));\n return url.replace(/([^:/])\\/{2,}/g, \"$1/\");\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import { tileCount, assertValidTileAddress, formatTileAddress } from './chunk-Y66PNDG2.js';
2
+
3
+ // src/mercator/web-mercator-tile-surface.ts
4
+ var WebMercatorTileSurface = class {
5
+ /** @param system - Geodetic system of the ellipsoid. Supplied explicitly by the caller. */
6
+ constructor(system) {
7
+ this.system = system;
8
+ if (!system) throw new TypeError("An explicit geodetic system is required.");
9
+ }
10
+ system;
11
+ point(address, s, t, height = 0, target = { x: 0, y: 0, z: 0 }) {
12
+ this.assertAddress(address);
13
+ const count = tileCount(address.lod);
14
+ return this.system.geodeticRadiansToEcef(latitudeOf((address.y + t) / count), longitudeOf((address.x + s) / count), height, target);
15
+ }
16
+ up(address, s, t, target = { x: 0, y: 0, z: 0 }) {
17
+ this.assertAddress(address);
18
+ const count = tileCount(address.lod);
19
+ const latitude = latitudeOf((address.y + t) / count);
20
+ const longitude = longitudeOf((address.x + s) / count);
21
+ target.x = Math.cos(latitude) * Math.cos(longitude);
22
+ target.y = Math.cos(latitude) * Math.sin(longitude);
23
+ target.z = Math.sin(latitude);
24
+ return target;
25
+ }
26
+ shape(address) {
27
+ this.assertAddress(address);
28
+ return { key: `${address.lod}/${address.y}`, rotation: longitudeOf((address.x + 0.5) / tileCount(address.lod)) };
29
+ }
30
+ assertAddress(address) {
31
+ assertValidTileAddress(address);
32
+ if (address.face) throw new RangeError(`Tile ${formatTileAddress(address)} does not exist: a Web Mercator pyramid has one root.`);
33
+ }
34
+ };
35
+ function latitudeOf(y) {
36
+ return Math.atan(Math.sinh(Math.PI * (1 - 2 * y)));
37
+ }
38
+ function longitudeOf(x) {
39
+ return (2 * x - 1) * Math.PI;
40
+ }
41
+
42
+ export { WebMercatorTileSurface };
43
+ //# sourceMappingURL=chunk-GRTG4WNA.js.map
44
+ //# sourceMappingURL=chunk-GRTG4WNA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mercator/web-mercator-tile-surface.ts"],"names":[],"mappings":";;;AASO,IAAM,yBAAN,MAAqD;AAAA;AAAA,EAEjD,YAA6B,MAAA,EAAwB;AAAxB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAChC,IAAA,IAAI,CAAC,MAAA,EAAQ,MAAM,IAAI,UAAU,0CAA0C,CAAA;AAAA,EAC/E;AAAA,EAFoC,MAAA;AAAA,EAI7B,KAAA,CAAM,OAAA,EAAuB,CAAA,EAAW,CAAA,EAAW,SAAS,CAAA,EAAG,MAAA,GAAsB,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,GAAE,EAAgB;AAC3H,IAAA,IAAA,CAAK,cAAc,OAAO,CAAA;AAC1B,IAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,OAAA,CAAQ,GAAG,CAAA;AACnC,IAAA,OAAO,KAAK,MAAA,CAAO,qBAAA,CAAsB,UAAA,CAAA,CAAY,OAAA,CAAQ,IAAI,CAAA,IAAK,KAAK,CAAA,EAAG,WAAA,CAAA,CAAa,QAAQ,CAAA,GAAI,CAAA,IAAK,KAAK,CAAA,EAAG,QAAQ,MAAM,CAAA;AAAA,EACtI;AAAA,EAEO,EAAA,CAAG,OAAA,EAAuB,CAAA,EAAW,CAAA,EAAW,MAAA,GAAsB,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE,EAAgB;AAC5G,IAAA,IAAA,CAAK,cAAc,OAAO,CAAA;AAC1B,IAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,OAAA,CAAQ,GAAG,CAAA;AACn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AQ,CAAA,GAAI,CAAA,GAAI,CAAA,IAAK,IAAA,CAAK,EAAA;AAC9B","file":"chunk-GRTG4WNA.js","sourcesContent":["import { GeodeticSystem, type ICartesian3 } from \"@spacexr/geodesy\";\n\nimport { assertValidTileAddress, formatTileAddress, tileCount, type ITileAddress } from \"../addressing/tile-address\";\nimport type { ITileShapeFrame, ITileSurface } from \"../addressing/tile-surface\";\n\n/**\n * Tiles of a Web Mercator pyramid on an ellipsoid. Heights are geodetic, along the normal of the ellipsoid. Tiles of\n * one level and row are the same shape turned about the polar axis.\n */\nexport class WebMercatorTileSurface implements ITileSurface {\n /** @param system - Geodetic system of the ellipsoid. Supplied explicitly by the caller. */\n public constructor(private readonly system: GeodeticSystem) {\n if (!system) throw new TypeError(\"An explicit geodetic system is required.\");\n }\n\n public point(address: ITileAddress, s: number, t: number, height = 0, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n this.assertAddress(address);\n const count = tileCount(address.lod);\n return this.system.geodeticRadiansToEcef(latitudeOf((address.y + t) / count), longitudeOf((address.x + s) / count), height, target);\n }\n\n public up(address: ITileAddress, s: number, t: number, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n this.assertAddress(address);\n const count = tileCount(address.lod);\n const latitude = latitudeOf((address.y + t) / count);\n const longitude = longitudeOf((address.x + s) / count);\n target.x = Math.cos(latitude) * Math.cos(longitude);\n target.y = Math.cos(latitude) * Math.sin(longitude);\n target.z = Math.sin(latitude);\n return target;\n }\n\n public shape(address: ITileAddress): ITileShapeFrame {\n this.assertAddress(address);\n return { key: `${address.lod}/${address.y}`, rotation: longitudeOf((address.x + 0.5) / tileCount(address.lod)) };\n }\n\n private assertAddress(address: ITileAddress): void {\n assertValidTileAddress(address);\n if (address.face) throw new RangeError(`Tile ${formatTileAddress(address)} does not exist: a Web Mercator pyramid has one root.`);\n }\n}\n\n/** Latitude in radians of a Web Mercator ordinate, southward in `[0, 1]` over the whole pyramid. */\nfunction latitudeOf(y: number): number {\n return Math.atan(Math.sinh(Math.PI * (1 - 2 * y)));\n}\n\n/** Longitude in radians of a Web Mercator abscissa, eastward in `[0, 1]` over the whole pyramid. */\nfunction longitudeOf(x: number): number {\n return (2 * x - 1) * Math.PI;\n}\n"]}
@@ -0,0 +1,45 @@
1
+ // src/sources/tile-layer-changes.ts
2
+ function unionGeoBounds(a, b) {
3
+ const crosses = a.west > a.east || b.west > b.east;
4
+ return {
5
+ west: crosses ? -180 : Math.min(a.west, b.west),
6
+ south: Math.min(a.south, b.south),
7
+ east: crosses ? 180 : Math.max(a.east, b.east),
8
+ north: Math.max(a.north, b.north)
9
+ };
10
+ }
11
+ function touchedTileLayers(before, after) {
12
+ const previous = new Map(before.map((layer) => [layer.id, layer]));
13
+ const next = new Map(after.map((layer) => [layer.id, layer]));
14
+ const touched = [];
15
+ for (const layer of before) if (next.get(layer.id) !== layer) touched.push(layer);
16
+ for (const layer of after) if (previous.get(layer.id) !== layer) touched.push(layer);
17
+ const keptBefore = before.filter((layer) => next.has(layer.id)).map((layer) => layer.id);
18
+ const keptAfter = after.filter((layer) => previous.has(layer.id)).map((layer) => layer.id);
19
+ if (keptBefore.some((id, index) => keptAfter[index] !== id)) for (const id of keptAfter) touched.push(previous.get(id), next.get(id));
20
+ return touched;
21
+ }
22
+ function tileLayerChange(before, after) {
23
+ let bounds;
24
+ for (const layer of touchedTileLayers(before, after)) {
25
+ if (!layer.bounds) return { kind: "all" };
26
+ bounds = bounds ? unionGeoBounds(bounds, layer.bounds) : { ...layer.bounds };
27
+ }
28
+ return bounds ? { kind: "area", bounds } : { kind: "none" };
29
+ }
30
+ function planTileLayerUpdate(change, canInvalidate) {
31
+ if (change.kind === "none") return "none";
32
+ return canInvalidate ? "invalidate" : "rebuild";
33
+ }
34
+ function applyTileLayers(current, next, invalidate, replace) {
35
+ const change = tileLayerChange(current, next);
36
+ const plan = planTileLayerUpdate(change, !!invalidate);
37
+ if (plan === "rebuild") return false;
38
+ replace(next);
39
+ if (plan === "invalidate") invalidate(change.kind === "area" ? change.bounds : void 0);
40
+ return true;
41
+ }
42
+
43
+ export { applyTileLayers, planTileLayerUpdate, tileLayerChange, touchedTileLayers, unionGeoBounds };
44
+ //# sourceMappingURL=chunk-HVYN4AIT.js.map
45
+ //# sourceMappingURL=chunk-HVYN4AIT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sources/tile-layer-changes.ts"],"names":[],"mappings":";AAwBO,SAAS,cAAA,CAAe,GAAe,CAAA,EAA2B;AACrE,EAAA,MAAM,UAAU,CAAA,CAAE,IAAA,GAAO,EAAE,IAAA,IAAQ,CAAA,CAAE,OAAO,CAAA,CAAE,IAAA;AAC9C,EAAA,OAAO;AAAA,IACH,IAAA,EAAM,UAAU,IAAA,GAAO,IAAA,CAAK,IAAI,CAAA,CAAE,IAAA,EAAM,EAAE,IAAI,CAAA;AAAA,IAC9C,OAAO,IAAA,CAAK,GAAA,CAAI,CAAA,CAAE,KAAA,EAAO,EAAE,KAAK,CAAA;AAAA,IAChC,IAAA,EAAM,UAAU,GAAA,GAAM,IAAA,CAAK,IAAI,CAAA,CAAE,IAAA,EAAM,EAAE,IAAI,CAAA;AAAA,IAC7C,OAAO,IAAA,CAAK,GAAA,CAAI,CAAA,CAAE,KAAA,EAAO,EAAE,KAAK;AAAA,GACpC;AACJ;AAOO,SAAS,iBAAA,CAAwC,QAAsB,KAAA,EAA0B;AACpG,EAAA,MAAM,QAAA,GAAW,IAAI,GAAA,CAAI,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,KAAU,CAAC,KAAA,CAAM,EAAA,EAAI,KAAK,CAAC,CAAC,CAAA;AACjE,EAAA,MAAM,IAAA,GAAO,IAAI,GAAA,CAAI,KAAA,CAAM,GAAA,CAAI,CAAC,KAAA,KAAU,CAAC,KAAA,CAAM,EAAA,EAAI,KAAK,CAAC,CAAC,CAAA;AAC5D,EAAA,MAAM,UAAe,EAAC;AACtB,EAAA,KAAA,MAAW,KAAA,IAAS,MA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,CAAM,MAAA,EAAO;AAAA,EAC/E;AACA,EAAA,OAAO,MAAA,GAAS,EAAE,IAAA,EAAM,MAAA,EAAQ,QAAO,GAAI,EAAE,MAAM,MAAA,EAAO;AAC9D;AAMO,SAAS,mBAAA,CAAoB,QAAyB,aAAA,EAA2D;AACpH,EAAA,IAAI,MAAA,CAAO,IAAA,KAAS,MAAA,EAAQ,OAAO,MAAA;AACnC,EAAA,OAAO,gBAAgB,YAAA,GAAe,SAAA;AAC1C;AAOO,SAAS,eAAA,CACZ,OAAA,EACA,IAAA,EACA,UAAA,EACA,OAAA,EACO;AACP,EAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,OAAA,EAAS,IAAI,CAAA;AAC5C,EAAA,MAAM,IAAA,GAAO,mBAAA,CAAoB,MAAA,EAAQ,CAAC,CAAC,UAAU,CAAA;AACrD,EAAA,IAAI,IAAA,KAAS,WAAW,OAAO,KAAA;AAC/B,EAAA,OAAA,CAAQ,IAAI,CAAA;AACZ,EAAA,IAAI,IAAA,KAAS,cAAc,UAAA,CAAY,MAAA,CAAO,SAAS,MAAA,GAAS,MAAA,CAAO,SAAS,MAAS,CAAA;AACzF,EAAA,OAAO,IAAA;AACX","file":"chunk-HVYN4AIT.js","sourcesContent":["import type { IGeoBounds } from \"../addressing/tile\";\n\n/**\n * A layer laid over the tiles of a source, such as a vector or a raster draped on imagery: identified by `id`, and\n * covering `bounds`, the whole body without them. A layer whose look changes is a new object with the same `id`.\n */\nexport interface ITileLayer {\n readonly id: string;\n readonly bounds?: IGeoBounds;\n}\n\n/**\n * What a new set of layers changes in the tiles: nothing, the tiles of an extent, or all of them (a layer touched\n * without bounds covers the whole body).\n */\nexport type TileLayerChange = { kind: \"none\" } | { kind: \"area\"; bounds: IGeoBounds } | { kind: \"all\" };\n\n/** Throws away the tiles of an extent, all of them without one, so that they load again. */\nexport type TileInvalidator = (bounds?: IGeoBounds) => void;\n\n/**\n * Smallest extent holding both. An extent crossing the antimeridian (`west > east`) widens the union to every\n * longitude, which holds it whatever the other.\n */\nexport function unionGeoBounds(a: IGeoBounds, b: IGeoBounds): IGeoBounds {\n const crosses = a.west > a.east || b.west > b.east;\n return {\n west: crosses ? -180 : Math.min(a.west, b.west),\n south: Math.min(a.south, b.south),\n east: crosses ? 180 : Math.max(a.east, b.east),\n north: Math.max(a.north, b.north),\n };\n}\n\n/**\n * The layers a new set touches, compared with the set drawn: a layer added or taken away, a layer replaced by another\n * object of the same `id`, and, when the order of the layers kept changes, all of them, since the order is how they\n * lay over each other. A replaced layer counts with its old and its new extent.\n */\nexport function touchedTileLayers<T extends ITileLayer>(before: readonly T[], after: readonly T[]): T[] {\n const previous = new Map(before.map((layer) => [layer.id, layer]));\n const next = new Map(after.map((layer) => [layer.id, layer]));\n const touched: T[] = [];\n for (const layer of before) if (next.get(layer.id) !== layer) touched.push(layer);\n for (const layer of after) if (previous.get(layer.id) !== layer) touched.push(layer);\n const keptBefore = before.filter((layer) => next.has(layer.id)).map((layer) => layer.id);\n const keptAfter = after.filter((layer) => previous.has(layer.id)).map((layer) => layer.id);\n if (keptBefore.some((id, index) => keptAfter[index] !== id)) for (const id of keptAfter) touched.push(previous.get(id)!, next.get(id)!);\n return touched;\n}\n\n/** The part of the tiles a new set of layers changes: the union of the extents of the layers it touches. */\nexport function tileLayerChange(before: readonly ITileLayer[], after: readonly ITileLayer[]): TileLayerChange {\n let bounds: IGeoBounds | undefined;\n for (const layer of touchedTileLayers(before, after)) {\n if (!layer.bounds) return { kind: \"all\" };\n bounds = bounds ? unionGeoBounds(bounds, layer.bounds) : { ...layer.bounds };\n }\n return bounds ? { kind: \"area\", bounds } : { kind: \"none\" };\n}\n\n/**\n * What to do for a change of the layers: nothing, throw away the tiles it touches, or build the source again when its\n * tiles cannot be thrown away.\n */\nexport function planTileLayerUpdate(change: TileLayerChange, canInvalidate: boolean): \"none\" | \"invalidate\" | \"rebuild\" {\n if (change.kind === \"none\") return \"none\";\n return canInvalidate ? \"invalidate\" : \"rebuild\";\n}\n\n/**\n * Applies a new set of layers to a running source: `replace` swaps the layers its tiles read, then the tiles they\n * change are thrown away. False when it cannot be done in place (no `invalidate`): the source keeps its layers, and is\n * to be built again by the caller.\n */\nexport function applyTileLayers<T extends ITileLayer>(\n current: readonly T[],\n next: readonly T[],\n invalidate: TileInvalidator | undefined,\n replace: (layers: readonly T[]) => void\n): boolean {\n const change = tileLayerChange(current, next);\n const plan = planTileLayerUpdate(change, !!invalidate);\n if (plan === \"rebuild\") return false;\n replace(next);\n if (plan === \"invalidate\") invalidate!(change.kind === \"area\" ? change.bounds : undefined);\n return true;\n}\n"]}
@@ -0,0 +1,77 @@
1
+ import { tileCount, assertValidTileAddress } from './chunk-Y66PNDG2.js';
2
+
3
+ // src/cube/cube-face.ts
4
+ var CubeFace = /* @__PURE__ */ ((CubeFace2) => {
5
+ CubeFace2[CubeFace2["PositiveX"] = 0] = "PositiveX";
6
+ CubeFace2[CubeFace2["PositiveY"] = 1] = "PositiveY";
7
+ CubeFace2[CubeFace2["NegativeX"] = 2] = "NegativeX";
8
+ CubeFace2[CubeFace2["NegativeY"] = 3] = "NegativeY";
9
+ CubeFace2[CubeFace2["North"] = 4] = "North";
10
+ CubeFace2[CubeFace2["South"] = 5] = "South";
11
+ return CubeFace2;
12
+ })(CubeFace || {});
13
+ var CUBE_FACE_COUNT = 6;
14
+ var axis = (x, y, z) => Object.freeze({ x, y, z });
15
+ var CUBE_FACE_FRAMES = Object.freeze([
16
+ { center: axis(1, 0, 0), u: axis(0, 1, 0), v: axis(0, 0, -1) },
17
+ { center: axis(0, 1, 0), u: axis(-1, 0, 0), v: axis(0, 0, -1) },
18
+ { center: axis(-1, 0, 0), u: axis(0, -1, 0), v: axis(0, 0, -1) },
19
+ { center: axis(0, -1, 0), u: axis(1, 0, 0), v: axis(0, 0, -1) },
20
+ { center: axis(0, 0, 1), u: axis(0, 1, 0), v: axis(1, 0, 0) },
21
+ { center: axis(0, 0, -1), u: axis(0, 1, 0), v: axis(-1, 0, 0) }
22
+ ]);
23
+ function isCubeFace(face) {
24
+ return Number.isInteger(face) && face >= 0 && face < CUBE_FACE_COUNT;
25
+ }
26
+
27
+ // src/cube/cube-mapping.ts
28
+ var QUARTER_TURN = Math.PI / 4;
29
+ function normalize(x, y, z, target) {
30
+ const length = Math.hypot(x, y, z);
31
+ target.x = x / length;
32
+ target.y = y / length;
33
+ target.z = z / length;
34
+ return target;
35
+ }
36
+ function cubeFaceDirection(face, u, v, target = { x: 0, y: 0, z: 0 }) {
37
+ const frame = CUBE_FACE_FRAMES[face];
38
+ if (!frame) throw new RangeError(`Cube face ${face} does not exist.`);
39
+ const a = Math.tan(QUARTER_TURN * (2 * u - 1));
40
+ const b = Math.tan(QUARTER_TURN * (2 * v - 1));
41
+ const { center: c, u: du, v: dv } = frame;
42
+ return normalize(c.x + a * du.x + b * dv.x, c.y + a * du.y + b * dv.y, c.z + a * du.z + b * dv.z, target);
43
+ }
44
+ function cubeFaceOfDirection(direction) {
45
+ const { x, y, z } = direction;
46
+ const ax = Math.abs(x);
47
+ const ay = Math.abs(y);
48
+ const az = Math.abs(z);
49
+ if (!(ax + ay + az > 0) || !Number.isFinite(ax + ay + az)) throw new RangeError("A cube direction must be finite and non-zero.");
50
+ if (ax >= ay && ax >= az) return x > 0 ? 0 /* PositiveX */ : 2 /* NegativeX */;
51
+ if (ay >= az) return y > 0 ? 1 /* PositiveY */ : 3 /* NegativeY */;
52
+ return z > 0 ? 4 /* North */ : 5 /* South */;
53
+ }
54
+ function cubeFaceCoordinates(direction) {
55
+ const face = cubeFaceOfDirection(direction);
56
+ const { center, u, v } = CUBE_FACE_FRAMES[face];
57
+ const c = direction.x * center.x + direction.y * center.y + direction.z * center.z;
58
+ const a = (direction.x * u.x + direction.y * u.y + direction.z * u.z) / c;
59
+ const b = (direction.x * v.x + direction.y * v.y + direction.z * v.z) / c;
60
+ return { face, u: (Math.atan(a) / QUARTER_TURN + 1) / 2, v: (Math.atan(b) / QUARTER_TURN + 1) / 2 };
61
+ }
62
+ function cubeTileOfDirection(direction, lod) {
63
+ const { face, u, v } = cubeFaceCoordinates(direction);
64
+ const count = tileCount(lod);
65
+ const address = { face, lod, x: Math.min(count - 1, Math.floor(u * count)), y: Math.min(count - 1, Math.floor(v * count)) };
66
+ assertValidTileAddress(address);
67
+ return address;
68
+ }
69
+ function cubeTileDirection(address, s, t, target) {
70
+ assertValidTileAddress(address);
71
+ const count = tileCount(address.lod);
72
+ return cubeFaceDirection(address.face ?? 0, (address.x + s) / count, (address.y + t) / count, target);
73
+ }
74
+
75
+ export { CUBE_FACE_COUNT, CUBE_FACE_FRAMES, CubeFace, cubeFaceCoordinates, cubeFaceDirection, cubeFaceOfDirection, cubeTileDirection, cubeTileOfDirection, isCubeFace };
76
+ //# sourceMappingURL=chunk-IGNRXAW3.js.map
77
+ //# sourceMappingURL=chunk-IGNRXAW3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cube/cube-face.ts","../src/cube/cube-mapping.ts"],"names":["CubeFace"],"mappings":";;;AAMO,IAAK,QAAA,qBAAAA,SAAAA,KAAL;AAEH,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AAEA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AAEA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AAEA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,eAAY,CAAA,CAAA,GAAZ,WAAA;AAEA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,WAAQ,CAAA,CAAA,GAAR,OAAA;AAEA,EAAAA,SAAAA,CAAAA,SAAAA,CAAA,WAAQ,CAAA,CAAA,GAAR,OAAA;AAZQ,EAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;AAgBL,IAAM,eAAA,GAAkB;AAS/B,IAAM,IAAA,GAAO,CAAC,CAAA,E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,CAAA,GAAI,KAAK,CAAC,CAAA,EAAE;AAC1H,EAAA,sBAAA,CAAuB,OAAO,CAAA;AAC9B,EAAA,OAAO,OAAA;AACX;AAWO,SAAS,iBAAA,CAAkB,OAAA,EAAuB,CAAA,EAAW,CAAA,EAAW,MAAA,EAAmC;AAC9G,EAAA,sBAAA,CAAuB,OAAO,CAAA;AAC9B,EAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,OAAA,CAAQ,GAAG,CAAA;AACnC,EAAA,OAAO,iBAAA,CAAkB,OAAA,CAAQ,IAAA,IAAQ,CAAA,EAAA,CAAI,OAAA,CAAQ,CAAA,GAAI,CAAA,IAAK,KAAA,EAAA,CAAQ,OAAA,CAAQ,CAAA,GAAI,CAAA,IAAK,KAAA,EAAO,MAAM,CAAA;AACxG","file":"chunk-IGNRXAW3.js","sourcesContent":["import type { ICartesian3 } from \"@spacexr/geodesy\";\n\n/**\n * Face of the cube index of a celestial body. Equatorial faces are numbered eastward from the prime meridian; the\n * polar faces follow. See the repository document `docs/celestial-tiling.md`.\n */\nexport enum CubeFace {\n /** Centred on latitude 0, longitude 0, the `+X` axis. */\n PositiveX = 0,\n /** Centred on latitude 0, longitude 90 degrees east, the `+Y` axis. */\n PositiveY = 1,\n /** Centred on latitude 0, longitude 180 degrees, the `-X` axis. */\n NegativeX = 2,\n /** Centred on latitude 0, longitude 90 degrees west, the `-Y` axis. */\n NegativeY = 3,\n /** Centred on the north pole, the `+Z` axis. */\n North = 4,\n /** Centred on the south pole, the `-Z` axis. */\n South = 5,\n}\n\n/** Number of faces of the cube index. */\nexport const CUBE_FACE_COUNT = 6;\n\n/** Frame of a cube face: its centre and the directions in which its `u` and `v` coordinates grow. */\nexport interface ICubeFaceFrame {\n readonly center: Readonly<ICartesian3>;\n readonly u: Readonly<ICartesian3>;\n readonly v: Readonly<ICartesian3>;\n}\n\nconst axis = (x: number, y: number, z: number): Readonly<ICartesian3> => Object.freeze({ x, y, z });\n\n/**\n * Frames of the six faces, indexed by {@link CubeFace}. On equatorial faces `u` grows eastward and `v` southward; the\n * polar faces continue face 0 without rotation. On every face `u x v = -center`: seen from outside the body, `u` runs\n * to the right and `v` downward, like the columns and rows of an image.\n */\nexport const CUBE_FACE_FRAMES: readonly ICubeFaceFrame[] = Object.freeze([\n { center: axis(1, 0, 0), u: axis(0, 1, 0), v: axis(0, 0, -1) },\n { center: axis(0, 1, 0), u: axis(-1, 0, 0), v: axis(0, 0, -1) },\n { center: axis(-1, 0, 0), u: axis(0, -1, 0), v: axis(0, 0, -1) },\n { center: axis(0, -1, 0), u: axis(1, 0, 0), v: axis(0, 0, -1) },\n { center: axis(0, 0, 1), u: axis(0, 1, 0), v: axis(1, 0, 0) },\n { center: axis(0, 0, -1), u: axis(0, 1, 0), v: axis(-1, 0, 0) },\n]);\n\n/** Returns `true` for an integer face of the cube index. */\nexport function isCubeFace(face: number): face is CubeFace {\n return Number.isInteger(face) && face >= 0 && face < CUBE_FACE_COUNT;\n}\n","import type { ICartesian3 } from \"@spacexr/geodesy\";\n\nimport { assertValidTileAddress, tileCount, type ITileAddress } from \"../addressing/tile-address\";\nimport { CUBE_FACE_FRAMES, CubeFace } from \"./cube-face\";\n\nconst QUARTER_TURN = Math.PI / 4;\n\n/** Position on a face of the cube index: `u` and `v` in `[0, 1]`, from the north-west corner of the face. */\nexport interface ICubeFaceCoordinates {\n face: CubeFace;\n u: number;\n v: number;\n}\n\nfunction normalize(x: number, y: number, z: number, target: ICartesian3): ICartesian3 {\n const length = Math.hypot(x, y, z);\n target.x = x / length;\n target.y = y / length;\n target.z = z / length;\n return target;\n}\n\n/**\n * Direction of a point of a face, with the equi-angular mapping: `normalize(C + tan(pi/4 (2u - 1)) U + tan(pi/4\n * (2v - 1)) V)`. Coordinates outside `[0, 1]` extend the face plane, up to `-0.5` and `1.5` exclusive.\n *\n * @param face - Face of the cube index.\n * @param u - Coordinate along the face `u` axis, 0 on its west edge.\n * @param v - Coordinate along the face `v` axis, 0 on its north edge.\n * @param target - Receives the unit direction.\n */\nexport function cubeFaceDirection(face: CubeFace, u: number, v: number, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n const frame = CUBE_FACE_FRAMES[face];\n if (!frame) throw new RangeError(`Cube face ${face} does not exist.`);\n const a = Math.tan(QUARTER_TURN * (2 * u - 1));\n const b = Math.tan(QUARTER_TURN * (2 * v - 1));\n const { center: c, u: du, v: dv } = frame;\n return normalize(c.x + a * du.x + b * dv.x, c.y + a * du.y + b * dv.y, c.z + a * du.z + b * dv.z, target);\n}\n\n/**\n * Face of a direction: the face of its largest absolute component, its sign giving the face. Ties go to the first\n * axis in the order `X`, `Y`, `Z`, so a direction on a cube edge belongs to an equatorial face.\n *\n * @param direction - Any non-zero vector; it does not need to be normalized.\n * @throws RangeError When the direction is zero or not finite.\n */\nexport function cubeFaceOfDirection(direction: Readonly<ICartesian3>): CubeFace {\n const { x, y, z } = direction;\n const ax = Math.abs(x);\n const ay = Math.abs(y);\n const az = Math.abs(z);\n if (!(ax + ay + az > 0) || !Number.isFinite(ax + ay + az)) throw new RangeError(\"A cube direction must be finite and non-zero.\");\n if (ax >= ay && ax >= az) return x > 0 ? CubeFace.PositiveX : CubeFace.NegativeX;\n if (ay >= az) return y > 0 ? CubeFace.PositiveY : CubeFace.NegativeY;\n return z > 0 ? CubeFace.North : CubeFace.South;\n}\n\n/**\n * Face and face coordinates of a direction, the inverse of {@link cubeFaceDirection}.\n *\n * @param direction - Any non-zero vector; it does not need to be normalized.\n * @throws RangeError When the direction is zero or not finite.\n */\nexport function cubeFaceCoordinates(direction: Readonly<ICartesian3>): ICubeFaceCoordinates {\n const face = cubeFaceOfDirection(direction);\n const { center, u, v } = CUBE_FACE_FRAMES[face]!;\n const c = direction.x * center.x + direction.y * center.y + direction.z * center.z;\n const a = (direction.x * u.x + direction.y * u.y + direction.z * u.z) / c;\n const b = (direction.x * v.x + direction.y * v.y + direction.z * v.z) / c;\n return { face, u: (Math.atan(a) / QUARTER_TURN + 1) / 2, v: (Math.atan(b) / QUARTER_TURN + 1) / 2 };\n}\n\n/**\n * Tile of a direction at a level of detail: `floor(u * 2^lod)` and `floor(v * 2^lod)` on its face, clamped so that\n * the east and south edges of the face belong to its last tiles.\n *\n * @throws RangeError When the direction is zero or not finite, or the level is invalid.\n */\nexport function cubeTileOfDirection(direction: Readonly<ICartesian3>, lod: number): ITileAddress {\n const { face, u, v } = cubeFaceCoordinates(direction);\n const count = tileCount(lod);\n const address = { face, lod, x: Math.min(count - 1, Math.floor(u * count)), y: Math.min(count - 1, Math.floor(v * count)) };\n assertValidTileAddress(address);\n return address;\n}\n\n/**\n * Direction of a point of a tile.\n *\n * @param address - Tile of the cube index; a missing face means face 0.\n * @param s - Coordinate in the tile, 0 on its west edge and 1 on its east edge.\n * @param t - Coordinate in the tile, 0 on its north edge and 1 on its south edge.\n * @param target - Receives the unit direction.\n * @throws RangeError When the address is invalid.\n */\nexport function cubeTileDirection(address: ITileAddress, s: number, t: number, target?: ICartesian3): ICartesian3 {\n assertValidTileAddress(address);\n const count = tileCount(address.lod);\n return cubeFaceDirection(address.face ?? 0, (address.x + s) / count, (address.y + t) / count, target);\n}\n"]}
@@ -0,0 +1,145 @@
1
+ import { cubeTileDirection } from './chunk-IGNRXAW3.js';
2
+ import { validateTileUrlTemplate, TileHttpClient, expandTileUrlTemplate } from './chunk-6YNCRDEE.js';
3
+ import { ReferenceSurface } from './chunk-7AWV2IEK.js';
4
+ import { assertValidTileAddress, formatTileAddress, isValidTileAddress } from './chunk-Y66PNDG2.js';
5
+
6
+ // src/cube/cube-tile-surface.ts
7
+ var CubeTileSurface = class {
8
+ /** @param reference - Reference surface of the heights. */
9
+ constructor(reference) {
10
+ this.reference = reference;
11
+ }
12
+ reference;
13
+ point(address, s, t, height = 0, target = { x: 0, y: 0, z: 0 }) {
14
+ return this.reference.point(cubeTileDirection(address, s, t, target), height, target);
15
+ }
16
+ up(address, s, t, target) {
17
+ return cubeTileDirection(address, s, t, target);
18
+ }
19
+ shape(address) {
20
+ assertValidTileAddress(address);
21
+ return { key: formatTileAddress({ ...address, face: address.face ?? 0 }), rotation: 0 };
22
+ }
23
+ };
24
+
25
+ // src/cube/celestial-dataset.ts
26
+ var CELESTIAL_CUBE_SCHEME = "spacexr-cube-equiangular/1";
27
+ function fail(message) {
28
+ throw new RangeError(`Invalid celestial dataset: ${message}`);
29
+ }
30
+ function text(value, name) {
31
+ const member = value[name];
32
+ if (typeof member !== "string" || member.length === 0) fail(`${name} must be a non-empty string.`);
33
+ return member;
34
+ }
35
+ function level(value, name) {
36
+ const member = value[name];
37
+ if (!Number.isInteger(member) || member < 0 || member > 52) fail(`${name} must be a level from 0 to 52.`);
38
+ return member;
39
+ }
40
+ function parseCelestialDataset(value) {
41
+ if (typeof value !== "object" || value === null || Array.isArray(value)) fail("the descriptor must be an object.");
42
+ const source = value;
43
+ const scheme = text(source, "scheme");
44
+ if (scheme !== CELESTIAL_CUBE_SCHEME) fail(`scheme ${scheme} is not supported, expected ${CELESTIAL_CUBE_SCHEME}.`);
45
+ const radii = source.referenceRadii;
46
+ if (!Array.isArray(radii) || radii.length !== 3 || radii.some((radius) => typeof radius !== "number" || !Number.isFinite(radius) || radius <= 0)) {
47
+ fail("referenceRadii must be three positive numbers of metres.");
48
+ }
49
+ const content = source.content;
50
+ if (content !== "elevation" && content !== "imagery") fail("content must be elevation or imagery.");
51
+ const tileSize = source.tileSize;
52
+ if (!Number.isInteger(tileSize) || tileSize < 1) fail("tileSize must be a positive integer.");
53
+ const minLOD = level(source, "minLOD");
54
+ const maxLOD = level(source, "maxLOD");
55
+ if (minLOD > maxLOD) fail("minLOD must not exceed maxLOD.");
56
+ const rawSubtrees = source.subtrees ?? [];
57
+ if (!Array.isArray(rawSubtrees)) fail("subtrees must be an array.");
58
+ const subtrees = rawSubtrees.map((raw) => {
59
+ if (typeof raw !== "object" || raw === null) fail("each subtree must be an object.");
60
+ const subtree = raw;
61
+ const address = { face: subtree.face, lod: subtree.lod, x: subtree.x, y: subtree.y };
62
+ if (subtree.face === void 0 || !isValidTileAddress(address)) fail("each subtree needs a valid face, lod, x and y.");
63
+ const subtreeMaxLOD = level(subtree, "maxLOD");
64
+ if (subtreeMaxLOD < address.lod) fail("the maxLOD of a subtree must reach at least its lod.");
65
+ return { face: address.face, lod: address.lod, x: address.x, y: address.y, maxLOD: subtreeMaxLOD };
66
+ });
67
+ const tiles = text(source, "tiles");
68
+ validateTileUrlTemplate(tiles);
69
+ return {
70
+ scheme,
71
+ body: text(source, "body"),
72
+ frame: text(source, "frame"),
73
+ referenceRadii: [radii[0], radii[1], radii[2]],
74
+ content,
75
+ encoding: text(source, "encoding"),
76
+ tileSize,
77
+ minLOD,
78
+ maxLOD,
79
+ subtrees,
80
+ tiles
81
+ };
82
+ }
83
+ var CelestialTileSource = class {
84
+ dataset;
85
+ /** Surface of the tiles of the dataset, on its reference surface. */
86
+ surface;
87
+ /** Deepest level available anywhere. */
88
+ deepestLOD;
89
+ client;
90
+ /** Deepest level of the subtree rooted at each tile. */
91
+ subtreeDepths = /* @__PURE__ */ new Map();
92
+ /** @param dataset - The descriptor, or its JSON value, checked by {@link parseCelestialDataset}. */
93
+ constructor(dataset, options = {}) {
94
+ this.dataset = parseCelestialDataset(dataset);
95
+ const [a, b, c] = this.dataset.referenceRadii;
96
+ this.surface = new CubeTileSurface(new ReferenceSurface(a, b, c));
97
+ this.deepestLOD = this.dataset.subtrees.reduce((deepest, subtree) => Math.max(deepest, subtree.maxLOD), this.dataset.maxLOD);
98
+ this.client = options.client instanceof TileHttpClient ? options.client : new TileHttpClient(options.client);
99
+ for (const { face, lod, x, y, maxLOD } of this.dataset.subtrees) {
100
+ const root = `${face}/${lod}/${x}/${y}`;
101
+ this.subtreeDepths.set(root, Math.max(maxLOD, this.subtreeDepths.get(root) ?? 0));
102
+ }
103
+ }
104
+ /**
105
+ * Deepest level of the dataset at the place of a tile, at most the level of the tile: the level of the tile itself
106
+ * where the dataset declares it, of its deepest declared ancestor elsewhere.
107
+ */
108
+ servingLevel(address) {
109
+ const everywhere = Math.min(address.lod, this.dataset.maxLOD);
110
+ if (address.lod <= this.dataset.maxLOD || this.subtreeDepths.size === 0) return everywhere;
111
+ const face = address.face ?? 0;
112
+ let best = everywhere;
113
+ for (let lod = Math.min(address.lod, this.deepestLOD); lod >= 0; lod--) {
114
+ const shift = address.lod - lod;
115
+ const depth = this.subtreeDepths.get(`${face}/${lod}/${Math.floor(address.x / 2 ** shift)}/${Math.floor(address.y / 2 ** shift)}`);
116
+ if (depth !== void 0) best = Math.max(best, Math.min(depth, address.lod));
117
+ if (best === address.lod) break;
118
+ }
119
+ return best;
120
+ }
121
+ /** Whether the dataset declares a tile. */
122
+ isAvailable(address) {
123
+ if (!isValidTileAddress(address)) return false;
124
+ if (address.lod < this.dataset.minLOD) return false;
125
+ return this.servingLevel(address) === address.lod;
126
+ }
127
+ /** Returns the URL of a tile, whether it is available or not. */
128
+ urlOf(address) {
129
+ return expandTileUrlTemplate(this.dataset.tiles, address);
130
+ }
131
+ /**
132
+ * Fetches a tile; a tile outside the declared availability resolves as absent, like a 404, without any request.
133
+ *
134
+ * @throws RangeError When the address is invalid.
135
+ */
136
+ async fetchTile(address, signal) {
137
+ const url = this.urlOf(address);
138
+ if (!this.isAvailable(address)) return { status: "absent", url, httpStatus: 404 };
139
+ return this.client.fetchTile(url, signal);
140
+ }
141
+ };
142
+
143
+ export { CELESTIAL_CUBE_SCHEME, CelestialTileSource, CubeTileSurface, parseCelestialDataset };
144
+ //# sourceMappingURL=chunk-QGTREKHS.js.map
145
+ //# sourceMappingURL=chunk-QGTREKHS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cube/cube-tile-surface.ts","../src/cube/celestial-dataset.ts"],"names":[],"mappings":";;;;;;AAaO,IAAM,kBAAN,MAA8C;AAAA;AAAA,EAE1C,YAA4B,SAAA,EAA6B;AAA7B,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAAA,EAA8B;AAAA,EAA9B,SAAA;AA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{ ICartesian3 } from \"@spacexr/geodesy\";\n\nimport { assertValidTileAddress, formatTileAddress, type ITileAddress } from \"../addressing/tile-address\";\nimport type { ITileShapeFrame, ITileSurface } from \"../addressing/tile-surface\";\nimport { cubeTileDirection } from \"./cube-mapping\";\nimport type { ReferenceSurface } from \"../surface/reference-surface\";\n\n/**\n * Tiles of the cube index on a reference surface. Heights are radial: every point lies on the ray of its direction.\n *\n * Each tile has its own shape. The same address on another face is the same shape on a sphere only, and is never in\n * view together with the tile, so sharing would save nothing.\n */\nexport class CubeTileSurface implements ITileSurface {\n /** @param reference - Reference surface of the heights. */\n public constructor(public readonly reference: ReferenceSurface) {}\n\n public point(address: ITileAddress, s: number, t: number, height = 0, target: ICartesian3 = { x: 0, y: 0, z: 0 }): ICartesian3 {\n return this.reference.point(cubeTileDirection(address, s, t, target), height, target);\n }\n\n public up(address: ITileAddress, s: number, t: number, target?: ICartesian3): ICartesian3 {\n return cubeTileDirection(address, s, t, target);\n }\n\n public shape(address: ITileAddress): ITileShapeFrame {\n assertValidTileAddress(address);\n return { key: formatTileAddress({ ...address, face: address.face ?? 0 }), rotation: 0 };\n }\n}\n","import { isValidTileAddress, type ITileAddress } from \"../addressing/tile-address\";\nimport { TileHttpClient, type ITileHttpClientOptions, type TileFetchResult } from \"../sources/tile-http-client\";\nimport { expandTileUrlTemplate, validateTileUrlTemplate } from \"../sources/url-template\";\nimport { CubeTileSurface } from \"./cube-tile-surface\";\nimport { ReferenceSurface } from \"../surface/reference-surface\";\n\n/** Scheme of the datasets of this version of the specification. */\nexport const CELESTIAL_CUBE_SCHEME = \"spacexr-cube-equiangular/1\";\n\n/** A tile below which levels down to its own `maxLOD` are available, such as the polar caps of the Moon. */\nexport interface ICelestialDatasetSubtree {\n readonly face: number;\n readonly lod: number;\n readonly x: number;\n readonly y: number;\n readonly maxLOD: number;\n}\n\n/** Descriptor of a dataset of a tile service; see `docs/celestial-tiling.md`. */\nexport interface ICelestialDataset {\n /** This specification and its version: {@link CELESTIAL_CUBE_SCHEME}. */\n readonly scheme: string;\n /** Catalogue name of the body. */\n readonly body: string;\n /** Body-fixed frame and its version. */\n readonly frame: string;\n /** Radii `a`, `b`, `c` of the reference surface, in metres. */\n readonly referenceRadii: readonly [number, number, number];\n readonly content: \"elevation\" | \"imagery\";\n /** Tile format, such as `terrarium` for radial heights or `png`, `jpeg`, `webp` for imagery. */\n readonly encoding: string;\n /** Cells per tile side: tiles hold `tileSize + 1` samples per side. */\n readonly tileSize: number;\n /** Levels available everywhere, from `minLOD` to `maxLOD`. */\n readonly minLOD: number;\n readonly maxLOD: number;\n readonly subtrees: readonly ICelestialDatasetSubtree[];\n /** URL template. */\n readonly tiles: string;\n}\n\nfunction fail(message: string): never {\n throw new RangeError(`Invalid celestial dataset: ${message}`);\n}\n\nfunction text(value: Record<string, unknown>, name: string): string {\n const member = value[name];\n if (typeof member !== \"string\" || member.length === 0) fail(`${name} must be a non-empty string.`);\n return member;\n}\n\nfunction level(value: Record<string, unknown>, name: string): number {\n const member = value[name];\n if (!Number.isInteger(member) || (member as number) < 0 || (member as number) > 52) fail(`${name} must be a level from 0 to 52.`);\n return member as number;\n}\n\n/**\n * Checks the JSON value of a dataset descriptor.\n *\n * @returns The descriptor, with an empty `subtrees` when it has none.\n * @throws RangeError When a member is missing or invalid, naming it. A scheme of another version is rejected.\n * @throws TileUrlTemplateError When the URL template uses an unknown variable.\n */\nexport function parseCelestialDataset(value: unknown): ICelestialDataset {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) fail(\"the descriptor must be an object.\");\n const source = value as Record<string, unknown>;\n const scheme = text(source, \"scheme\");\n if (scheme !== CELESTIAL_CUBE_SCHEME) fail(`scheme ${scheme} is not supported, expected ${CELESTIAL_CUBE_SCHEME}.`);\n const radii = source.referenceRadii;\n if (!Array.isArray(radii) || radii.length !== 3 || radii.some((radius) => typeof radius !== \"number\" || !Number.isFinite(radius) || radius <= 0)) {\n fail(\"referenceRadii must be three positive numbers of metres.\");\n }\n const content = source.content;\n if (content !== \"elevation\" && content !== \"imagery\") fail(\"content must be elevation or imagery.\");\n const tileSize = source.tileSize;\n if (!Number.isInteger(tileSize) || (tileSize as number) < 1) fail(\"tileSize must be a positive integer.\");\n const minLOD = level(source, \"minLOD\");\n const maxLOD = level(source, \"maxLOD\");\n if (minLOD > maxLOD) fail(\"minLOD must not exceed maxLOD.\");\n const rawSubtrees = source.subtrees ?? [];\n if (!Array.isArray(rawSubtrees)) fail(\"subtrees must be an array.\");\n const subtrees = rawSubtrees.map((raw: unknown): ICelestialDatasetSubtree => {\n if (typeof raw !== \"object\" || raw === null) fail(\"each subtree must be an object.\");\n const subtree = raw as Record<string, unknown>;\n const address = { face: subtree.face as number, lod: subtree.lod as number, x: subtree.x as number, y: subtree.y as number };\n if (subtree.face === undefined || !isValidTileAddress(address)) fail(\"each subtree needs a valid face, lod, x and y.\");\n const subtreeMaxLOD = level(subtree, \"maxLOD\");\n if (subtreeMaxLOD < address.lod) fail(\"the maxLOD of a subtree must reach at least its lod.\");\n return { face: address.face, lod: address.lod, x: address.x, y: address.y, maxLOD: subtreeMaxLOD };\n });\n const tiles = text(source, \"tiles\");\n validateTileUrlTemplate(tiles);\n return {\n scheme,\n body: text(source, \"body\"),\n frame: text(source, \"frame\"),\n referenceRadii: [radii[0] as number, radii[1] as number, radii[2] as number],\n content,\n encoding: text(source, \"encoding\"),\n tileSize: tileSize as number,\n minLOD,\n maxLOD,\n subtrees,\n tiles,\n };\n}\n\n/** Options of {@link CelestialTileSource}. */\nexport interface ICelestialTileSourceOptions {\n /** Shared client, or options used to create a dedicated one. */\n client?: TileHttpClient | ITileHttpClientOptions;\n}\n\n/**\n * Tiles of a dataset of a tile service, over HTTP. It never requests a tile outside the declared availability, which\n * resolves as absent, so that a sparse pyramid costs no failed request.\n */\nexport class CelestialTileSource {\n public readonly dataset: ICelestialDataset;\n /** Surface of the tiles of the dataset, on its reference surface. */\n public readonly surface: CubeTileSurface;\n /** Deepest level available anywhere. */\n public readonly deepestLOD: number;\n public readonly client: TileHttpClient;\n /** Deepest level of the subtree rooted at each tile. */\n private readonly subtreeDepths = new Map<string, number>();\n\n /** @param dataset - The descriptor, or its JSON value, checked by {@link parseCelestialDataset}. */\n public constructor(dataset: ICelestialDataset | unknown, options: ICelestialTileSourceOptions = {}) {\n this.dataset = parseCelestialDataset(dataset);\n const [a, b, c] = this.dataset.referenceRadii;\n this.surface = new CubeTileSurface(new ReferenceSurface(a, b, c));\n this.deepestLOD = this.dataset.subtrees.reduce((deepest, subtree) => Math.max(deepest, subtree.maxLOD), this.dataset.maxLOD);\n this.client = options.client instanceof TileHttpClient ? options.client : new TileHttpClient(options.client);\n for (const { face, lod, x, y, maxLOD } of this.dataset.subtrees) {\n const root = `${face}/${lod}/${x}/${y}`;\n this.subtreeDepths.set(root, Math.max(maxLOD, this.subtreeDepths.get(root) ?? 0));\n }\n }\n\n /**\n * Deepest level of the dataset at the place of a tile, at most the level of the tile: the level of the tile itself\n * where the dataset declares it, of its deepest declared ancestor elsewhere.\n */\n public servingLevel(address: ITileAddress): number {\n const everywhere = Math.min(address.lod, this.dataset.maxLOD);\n if (address.lod <= this.dataset.maxLOD || this.subtreeDepths.size === 0) return everywhere;\n const face = address.face ?? 0;\n let best = everywhere;\n for (let lod = Math.min(address.lod, this.deepestLOD); lod >= 0; lod--) {\n const shift = address.lod - lod;\n const depth = this.subtreeDepths.get(`${face}/${lod}/${Math.floor(address.x / 2 ** shift)}/${Math.floor(address.y / 2 ** shift)}`);\n if (depth !== undefined) best = Math.max(best, Math.min(depth, address.lod));\n if (best === address.lod) break;\n }\n return best;\n }\n\n /** Whether the dataset declares a tile. */\n public isAvailable(address: ITileAddress): boolean {\n if (!isValidTileAddress(address)) return false;\n if (address.lod < this.dataset.minLOD) return false;\n return this.servingLevel(address) === address.lod;\n }\n\n /** Returns the URL of a tile, whether it is available or not. */\n public urlOf(address: ITileAddress): string {\n return expandTileUrlTemplate(this.dataset.tiles, address);\n }\n\n /**\n * Fetches a tile; a tile outside the declared availability resolves as absent, like a 404, without any request.\n *\n * @throws RangeError When the address is invalid.\n */\n public async fetchTile(address: ITileAddress, signal?: AbortSignal): Promise<TileFetchResult> {\n const url = this.urlOf(address);\n if (!this.isAvailable(address)) return { status: \"absent\", url, httpStatus: 404 };\n return this.client.fetchTile(url, signal);\n }\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import { CELESTIAL_CUBE_SCHEME, parseCelestialDataset, CelestialTileSource } from './chunk-QGTREKHS.js';
2
+ import { WEB_MERCATOR_SCHEME, parseWebMercatorDataset, WebMercatorDatasetSource } from './chunk-ESLGXWQR.js';
3
+
4
+ // src/datasets/tile-dataset.ts
5
+ var TILE_DATASET_SCHEMES = [CELESTIAL_CUBE_SCHEME, WEB_MERCATOR_SCHEME];
6
+ function parseTileDataset(value) {
7
+ const scheme = typeof value === "object" && value !== null ? value.scheme : void 0;
8
+ if (scheme === CELESTIAL_CUBE_SCHEME) return parseCelestialDataset(value);
9
+ if (scheme === WEB_MERCATOR_SCHEME) return parseWebMercatorDataset(value);
10
+ throw new RangeError(`Unknown dataset scheme ${String(scheme)}: expected one of ${TILE_DATASET_SCHEMES.join(", ")}.`);
11
+ }
12
+ function isWebMercatorDataset(dataset) {
13
+ return dataset.scheme === WEB_MERCATOR_SCHEME;
14
+ }
15
+ function createTileDatasetSource(dataset, options = {}) {
16
+ const parsed = parseTileDataset(dataset);
17
+ return isWebMercatorDataset(parsed) ? new WebMercatorDatasetSource(parsed, options) : new CelestialTileSource(parsed, options.client ? { client: options.client } : {});
18
+ }
19
+ function tileDatasetUsage(value) {
20
+ const usage = typeof value === "object" && value !== null ? value.usage : void 0;
21
+ if (usage === void 0 || usage === "public") return "public";
22
+ if (usage === "development") return usage;
23
+ throw new RangeError(`Unknown dataset usage ${String(usage)}: expected "public" or "development".`);
24
+ }
25
+ var DevelopmentDatasetError = class extends Error {
26
+ constructor(url) {
27
+ super(`${url} is for development only and is not used in production.`);
28
+ this.url = url;
29
+ this.name = "DevelopmentDatasetError";
30
+ }
31
+ url;
32
+ };
33
+ var ABSOLUTE = /^[a-z][a-z\d+.-]*:/i;
34
+ function resolveTileTemplate(template, descriptorUrl) {
35
+ if (ABSOLUTE.test(template)) return template;
36
+ return new URL(template, descriptorUrl).href.replace(/%7B/gi, "{").replace(/%7D/gi, "}");
37
+ }
38
+ async function loadTileDataset(url, options = {}) {
39
+ const fetcher = options.fetch ?? ((input, init) => fetch(input, init));
40
+ const href = new URL(url, typeof location === "undefined" ? void 0 : location.href).href;
41
+ if (/^[a-z][a-z\d+.-]*:\/\/[^/]*@/i.test(href)) throw new RangeError("A dataset URL must not carry credentials.");
42
+ const response = await fetcher(href, options.signal ? { signal: options.signal } : void 0);
43
+ if (options.optional && response.status === 404) return void 0;
44
+ if (!response.ok) throw new Error(`${href} answered ${response.status}.`);
45
+ const descriptor = await response.json();
46
+ if (tileDatasetUsage(descriptor) === "development" && options.production) throw new DevelopmentDatasetError(href);
47
+ if (typeof descriptor?.tiles === "string") descriptor.tiles = resolveTileTemplate(descriptor.tiles, href);
48
+ return parseTileDataset(descriptor);
49
+ }
50
+ function tileDatasetUrl(service, name) {
51
+ return new URL(`${name}.json`, `${service.replace(/\/+$/, "")}/`).href;
52
+ }
53
+
54
+ export { DevelopmentDatasetError, TILE_DATASET_SCHEMES, createTileDatasetSource, isWebMercatorDataset, loadTileDataset, parseTileDataset, resolveTileTemplate, tileDatasetUrl, tileDatasetUsage };
55
+ //# sourceMappingURL=chunk-SPDRAY37.js.map
56
+ //# sourceMappingURL=chunk-SPDRAY37.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/datasets/tile-dataset.ts"],"names":[],"mappings":";;;;AAiBO,IAAM,oBAAA,GAA0C,CAAC,qBAAA,EAAuB,mBAAmB;AAO3F,SAAS,iBAAiB,KAAA,EAA6B;AAC1D,EAAA,MAAM,SAAS,OAAO,KAAA,KAAU,YAAY,KAAA,KAAU,IAAA,GAAQ,MAAkC,MAAA,GAAS,MAAA;AACz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G,CAAA;AACxE,EAAA,MAAM,UAAA,GAAc,MAAM,QAAA,CAAS,IAAA,EAAK;AACxC,EAAA,IAAI,gBAAA,CAAiB,UAAU,CAAA,KAAM,aAAA,IAAiB,QAAQ,UAAA,EAAY,MAAM,IAAI,uBAAA,CAAwB,IAAI,CAAA;AAChH,EAAA,IAAI,OAAO,YAAY,KAAA,KAAU,QAAA,aAAqB,KAAA,GAAQ,mBAAA,CAAoB,UAAA,CAAW,KAAA,EAAO,IAAI,CAAA;AACxG,EAAA,OAAO,iBAAiB,UAAU,CAAA;AACtC;AAGO,SAAS,cAAA,CAAe,SAAiB,IAAA,EAAsB;AAClE,EAAA,OAAO,IAAI,GAAA,CAAI,CAAA,EAAG,IAAI,CAAA,KAAA,CAAA,EAAS,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAC,CAAA,CAAA,CAAG,CAAA,CAAE,IAAA;AACtE","file":"chunk-SPDRAY37.js","sourcesContent":["import { CELESTIAL_CUBE_SCHEME, CelestialTileSource, parseCelestialDataset, type ICelestialDataset } from \"../cube/celestial-dataset\";\nimport {\n WEB_MERCATOR_SCHEME,\n WebMercatorDatasetSource,\n parseWebMercatorDataset,\n type IWebMercatorDataset,\n type IWebMercatorDatasetSourceOptions,\n} from \"../mercator/web-mercator-dataset\";\nimport type { FetchFunction } from \"../sources/tile-http-client\";\n\n/** A dataset descriptor of a tile service, on any tiling scheme this package knows. */\nexport type TileDataset = ICelestialDataset | IWebMercatorDataset;\n\n/** The tile source of a dataset, on its own scheme. */\nexport type TileDatasetSource = CelestialTileSource | WebMercatorDatasetSource;\n\n/** Schemes {@link parseTileDataset} reads. */\nexport const TILE_DATASET_SCHEMES: readonly string[] = [CELESTIAL_CUBE_SCHEME, WEB_MERCATOR_SCHEME];\n\n/**\n * Checks the JSON value of a dataset descriptor and reads it on its scheme.\n *\n * @throws RangeError When the scheme is unknown, or a member is missing or invalid.\n */\nexport function parseTileDataset(value: unknown): TileDataset {\n const scheme = typeof value === \"object\" && value !== null ? (value as Record<string, unknown>).scheme : undefined;\n if (scheme === CELESTIAL_CUBE_SCHEME) return parseCelestialDataset(value);\n if (scheme === WEB_MERCATOR_SCHEME) return parseWebMercatorDataset(value);\n throw new RangeError(`Unknown dataset scheme ${String(scheme)}: expected one of ${TILE_DATASET_SCHEMES.join(\", \")}.`);\n}\n\n/** Whether a descriptor is on the Web Mercator scheme. */\nexport function isWebMercatorDataset(dataset: TileDataset): dataset is IWebMercatorDataset {\n return dataset.scheme === WEB_MERCATOR_SCHEME;\n}\n\n/** Options of {@link createTileDatasetSource}. */\nexport type ITileDatasetSourceOptions = IWebMercatorDatasetSourceOptions;\n\n/** The tile source of a dataset: a cube source or a Web Mercator one, as its scheme says. */\nexport function createTileDatasetSource(dataset: TileDataset | unknown, options: ITileDatasetSourceOptions = {}): TileDatasetSource {\n const parsed = parseTileDataset(dataset);\n return isWebMercatorDataset(parsed) ? new WebMercatorDatasetSource(parsed, options) : new CelestialTileSource(parsed, options.client ? { client: options.client } : {});\n}\n\n/**\n * What a descriptor may be used for, as its optional `usage` member says. `\"development\"` marks a source whose terms\n * cover development only, such as tiles read straight from a commercial map service: an application must never ship it.\n * Without the member, the descriptor is `\"public\"`.\n */\nexport type TileDatasetUsage = \"public\" | \"development\";\n\n/**\n * The usage a descriptor declares.\n *\n * @throws RangeError When `usage` is neither `\"public\"` nor `\"development\"`.\n */\nexport function tileDatasetUsage(value: unknown): TileDatasetUsage {\n const usage = typeof value === \"object\" && value !== null ? (value as Record<string, unknown>).usage : undefined;\n if (usage === undefined || usage === \"public\") return \"public\";\n if (usage === \"development\") return usage;\n throw new RangeError(`Unknown dataset usage ${String(usage)}: expected \"public\" or \"development\".`);\n}\n\n/** The error of a descriptor refused because it is for development only and the application runs in production. */\nexport class DevelopmentDatasetError extends Error {\n constructor(readonly url: string) {\n super(`${url} is for development only and is not used in production.`);\n this.name = \"DevelopmentDatasetError\";\n }\n}\n\n/** Options of {@link loadTileDataset}. */\nexport interface ILoadTileDatasetOptions {\n /** Whether the application runs in production: a descriptor for development only is then refused. */\n production?: boolean;\n /** The fetch of the host; the global one by default. */\n fetch?: FetchFunction;\n /** Whether a descriptor answered 404 reads as absent instead of failing. */\n optional?: boolean;\n signal?: AbortSignal;\n}\n\n/** Whether a template is already an absolute URL. */\nconst ABSOLUTE = /^[a-z][a-z\\d+.-]*:/i;\n\n/**\n * Resolves a relative template against the URL of its descriptor, as a relative URI of 3D Tiles resolves against its\n * tileset: a static bucket can serve `./{z}/{x}/{y}.png` next to its `imagery.json`. Braces stay unescaped.\n */\nexport function resolveTileTemplate(template: string, descriptorUrl: string): string {\n if (ABSOLUTE.test(template)) return template;\n return new URL(template, descriptorUrl).href.replace(/%7B/gi, \"{\").replace(/%7D/gi, \"}\");\n}\n\n/**\n * Reads a dataset descriptor from a URL: either the descriptor itself (`.../imagery.json`), or a service and the name\n * of its descriptor through {@link tileDatasetUrl}. The tiles template is resolved against the descriptor URL, then\n * the descriptor is checked on its scheme. This is the one loader the applications of SpaceXR share.\n *\n * @returns The descriptor, or `undefined` for a missing optional one.\n * @throws Error When the request fails, RangeError when the descriptor is invalid, {@link DevelopmentDatasetError}\n * when it is for development only and `production` is set.\n */\nexport async function loadTileDataset(url: string, options: ILoadTileDatasetOptions = {}): Promise<TileDataset | undefined> {\n const fetcher = options.fetch ?? ((input: string, init?: RequestInit) => fetch(input, init));\n const href = new URL(url, typeof location === \"undefined\" ? undefined : location.href).href;\n if (/^[a-z][a-z\\d+.-]*:\\/\\/[^/]*@/i.test(href)) throw new RangeError(\"A dataset URL must not carry credentials.\");\n const response = await fetcher(href, options.signal ? { signal: options.signal } : undefined);\n if (options.optional && response.status === 404) return undefined;\n if (!response.ok) throw new Error(`${href} answered ${response.status}.`);\n const descriptor = (await response.json()) as Record<string, unknown>;\n if (tileDatasetUsage(descriptor) === \"development\" && options.production) throw new DevelopmentDatasetError(href);\n if (typeof descriptor?.tiles === \"string\") descriptor.tiles = resolveTileTemplate(descriptor.tiles, href);\n return parseTileDataset(descriptor);\n}\n\n/** The URL of the descriptor `name.json` of a tile service, such as `elevation` or `imagery`. */\nexport function tileDatasetUrl(service: string, name: string): string {\n return new URL(`${name}.json`, `${service.replace(/\\/+$/, \"\")}/`).href;\n}\n"]}