@loaders.gl/tiles 4.5.3 → 5.0.0-alpha.10

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 (295) hide show
  1. package/LICENSE +14 -3
  2. package/README.md +136 -1
  3. package/dist/dist.dev.js +22570 -4947
  4. package/dist/dist.min.js +3 -1
  5. package/dist/image-set.d.ts +94 -0
  6. package/dist/image-set.d.ts.map +1 -0
  7. package/dist/image-set.js +243 -0
  8. package/dist/image-set.js.map +1 -0
  9. package/dist/index.cjs +10171 -2117
  10. package/dist/index.cjs.map +3 -4
  11. package/dist/index.d.ts +50 -9
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +28 -8
  14. package/dist/index.js.map +1 -1
  15. package/dist/point-cloud/point-cloud-tile.d.ts +47 -0
  16. package/dist/point-cloud/point-cloud-tile.d.ts.map +1 -0
  17. package/dist/point-cloud/point-cloud-tile.js +70 -0
  18. package/dist/point-cloud/point-cloud-tile.js.map +1 -0
  19. package/dist/point-cloud/point-cloud-tileset.d.ts +135 -0
  20. package/dist/point-cloud/point-cloud-tileset.d.ts.map +1 -0
  21. package/dist/point-cloud/point-cloud-tileset.js +549 -0
  22. package/dist/point-cloud/point-cloud-tileset.js.map +1 -0
  23. package/dist/point-cloud/types.d.ts +81 -0
  24. package/dist/point-cloud/types.d.ts.map +1 -0
  25. package/dist/point-cloud/types.js +5 -0
  26. package/dist/point-cloud/types.js.map +1 -0
  27. package/dist/raster-set.d.ts +124 -0
  28. package/dist/raster-set.d.ts.map +1 -0
  29. package/dist/raster-set.js +348 -0
  30. package/dist/raster-set.js.map +1 -0
  31. package/dist/spatial/format-spatial-reference.d.ts +68 -0
  32. package/dist/spatial/format-spatial-reference.d.ts.map +1 -0
  33. package/dist/spatial/format-spatial-reference.js +291 -0
  34. package/dist/spatial/format-spatial-reference.js.map +1 -0
  35. package/dist/spatial/get-spatial-coordinate-frame.d.ts +20 -0
  36. package/dist/spatial/get-spatial-coordinate-frame.d.ts.map +1 -0
  37. package/dist/spatial/get-spatial-coordinate-frame.js +139 -0
  38. package/dist/spatial/get-spatial-coordinate-frame.js.map +1 -0
  39. package/dist/spatial/i3s-elevation.d.ts +20 -0
  40. package/dist/spatial/i3s-elevation.d.ts.map +1 -0
  41. package/dist/spatial/i3s-elevation.js +90 -0
  42. package/dist/spatial/i3s-elevation.js.map +1 -0
  43. package/dist/spatial/i3s-spatial-transformer.d.ts +189 -0
  44. package/dist/spatial/i3s-spatial-transformer.d.ts.map +1 -0
  45. package/dist/spatial/i3s-spatial-transformer.js +686 -0
  46. package/dist/spatial/i3s-spatial-transformer.js.map +1 -0
  47. package/dist/spatial/normalize-crs-identifier.d.ts +15 -0
  48. package/dist/spatial/normalize-crs-identifier.d.ts.map +1 -0
  49. package/dist/spatial/normalize-crs-identifier.js +22 -0
  50. package/dist/spatial/normalize-crs-identifier.js.map +1 -0
  51. package/dist/spatial/spatial-coordinate-transformer.d.ts +52 -0
  52. package/dist/spatial/spatial-coordinate-transformer.d.ts.map +1 -0
  53. package/dist/spatial/spatial-coordinate-transformer.js +295 -0
  54. package/dist/spatial/spatial-coordinate-transformer.js.map +1 -0
  55. package/dist/spatial/spatial-resource-registry.d.ts +44 -0
  56. package/dist/spatial/spatial-resource-registry.d.ts.map +1 -0
  57. package/dist/spatial/spatial-resource-registry.js +67 -0
  58. package/dist/spatial/spatial-resource-registry.js.map +1 -0
  59. package/dist/spatial/spatial-types.d.ts +190 -0
  60. package/dist/spatial/spatial-types.d.ts.map +1 -0
  61. package/dist/spatial/spatial-types.js +192 -0
  62. package/dist/spatial/spatial-types.js.map +1 -0
  63. package/dist/spatial/tiles-3d-spatial-transformer.d.ts +32 -0
  64. package/dist/spatial/tiles-3d-spatial-transformer.d.ts.map +1 -0
  65. package/dist/spatial/tiles-3d-spatial-transformer.js +175 -0
  66. package/dist/spatial/tiles-3d-spatial-transformer.js.map +1 -0
  67. package/dist/tileset-2d/adapter.d.ts +37 -0
  68. package/dist/tileset-2d/adapter.d.ts.map +1 -0
  69. package/dist/tileset-2d/adapter.js +5 -0
  70. package/dist/tileset-2d/adapter.js.map +1 -0
  71. package/dist/tileset-2d/index.d.ts +7 -0
  72. package/dist/tileset-2d/index.d.ts.map +1 -0
  73. package/dist/tileset-2d/index.js +6 -0
  74. package/dist/tileset-2d/index.js.map +1 -0
  75. package/dist/tileset-2d/tile-2d-header.d.ts +68 -0
  76. package/dist/tileset-2d/tile-2d-header.d.ts.map +1 -0
  77. package/dist/tileset-2d/tile-2d-header.js +181 -0
  78. package/dist/tileset-2d/tile-2d-header.js.map +1 -0
  79. package/dist/tileset-2d/tileset-2d.d.ts +200 -0
  80. package/dist/tileset-2d/tileset-2d.d.ts.map +1 -0
  81. package/dist/tileset-2d/tileset-2d.js +532 -0
  82. package/dist/tileset-2d/tileset-2d.js.map +1 -0
  83. package/dist/tileset-2d/types.d.ts +44 -0
  84. package/dist/tileset-2d/types.d.ts.map +1 -0
  85. package/dist/tileset-2d/types.js +5 -0
  86. package/dist/tileset-2d/types.js.map +1 -0
  87. package/dist/tileset-2d.d.ts +2 -0
  88. package/dist/tileset-2d.d.ts.map +1 -0
  89. package/dist/tileset-2d.js +5 -0
  90. package/dist/tileset-2d.js.map +1 -0
  91. package/dist/tileset-3d/common/indexed-archive-tileset-source.d.ts +60 -0
  92. package/dist/tileset-3d/common/indexed-archive-tileset-source.d.ts.map +1 -0
  93. package/dist/tileset-3d/common/indexed-archive-tileset-source.js +130 -0
  94. package/dist/tileset-3d/common/indexed-archive-tileset-source.js.map +1 -0
  95. package/dist/tileset-3d/common/tile-3d-contracts.d.ts +63 -0
  96. package/dist/tileset-3d/common/tile-3d-contracts.d.ts.map +1 -0
  97. package/dist/tileset-3d/common/tile-3d-contracts.js +51 -0
  98. package/dist/tileset-3d/common/tile-3d-contracts.js.map +1 -0
  99. package/dist/tileset-3d/common/tile-3d.d.ts +410 -0
  100. package/dist/tileset-3d/common/tile-3d.d.ts.map +1 -0
  101. package/dist/tileset-3d/common/tile-3d.js +1056 -0
  102. package/dist/tileset-3d/common/tile-3d.js.map +1 -0
  103. package/dist/tileset-3d/common/tileset-3d.d.ts +360 -0
  104. package/dist/tileset-3d/common/tileset-3d.d.ts.map +1 -0
  105. package/dist/tileset-3d/common/tileset-3d.js +846 -0
  106. package/dist/tileset-3d/common/tileset-3d.js.map +1 -0
  107. package/dist/tileset-3d/common/tileset-cache.d.ts +29 -0
  108. package/dist/tileset-3d/common/tileset-cache.d.ts.map +1 -0
  109. package/dist/{tileset → tileset-3d/common}/tileset-cache.js +12 -4
  110. package/dist/tileset-3d/common/tileset-cache.js.map +1 -0
  111. package/dist/tileset-3d/common/tileset-content-traversal.d.ts +37 -0
  112. package/dist/tileset-3d/common/tileset-content-traversal.d.ts.map +1 -0
  113. package/dist/tileset-3d/common/tileset-content-traversal.js +80 -0
  114. package/dist/tileset-3d/common/tileset-content-traversal.js.map +1 -0
  115. package/dist/tileset-3d/common/tileset-observability.d.ts +60 -0
  116. package/dist/tileset-3d/common/tileset-observability.d.ts.map +1 -0
  117. package/dist/tileset-3d/common/tileset-observability.js +39 -0
  118. package/dist/tileset-3d/common/tileset-observability.js.map +1 -0
  119. package/dist/tileset-3d/common/tileset-source.d.ts +228 -0
  120. package/dist/tileset-3d/common/tileset-source.d.ts.map +1 -0
  121. package/dist/tileset-3d/common/tileset-source.js +17 -0
  122. package/dist/tileset-3d/common/tileset-source.js.map +1 -0
  123. package/dist/{tileset → tileset-3d/common}/tileset-traverser.d.ts +35 -3
  124. package/dist/tileset-3d/common/tileset-traverser.d.ts.map +1 -0
  125. package/dist/{tileset → tileset-3d/common}/tileset-traverser.js +61 -13
  126. package/dist/tileset-3d/common/tileset-traverser.js.map +1 -0
  127. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts +182 -0
  128. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.d.ts.map +1 -0
  129. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js +681 -0
  130. package/dist/tileset-3d/format-3d-tiles/implicit-tiling.js.map +1 -0
  131. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts +221 -0
  132. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.d.ts.map +1 -0
  133. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js +770 -0
  134. package/dist/tileset-3d/format-3d-tiles/tiles-3d-source.js.map +1 -0
  135. package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.d.ts +110 -0
  136. package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -0
  137. package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.js +331 -0
  138. package/dist/tileset-3d/format-3d-tiles/tileset-3d-traverser.js.map +1 -0
  139. package/dist/tileset-3d/format-i3s/i3s-pending-tiles-register.d.ts.map +1 -0
  140. package/dist/{tileset → tileset-3d}/format-i3s/i3s-pending-tiles-register.js +3 -0
  141. package/dist/tileset-3d/format-i3s/i3s-pending-tiles-register.js.map +1 -0
  142. package/dist/tileset-3d/format-i3s/i3s-source.d.ts +116 -0
  143. package/dist/tileset-3d/format-i3s/i3s-source.d.ts.map +1 -0
  144. package/dist/tileset-3d/format-i3s/i3s-source.js +450 -0
  145. package/dist/tileset-3d/format-i3s/i3s-source.js.map +1 -0
  146. package/dist/tileset-3d/format-i3s/i3s-tile-manager.d.ts.map +1 -0
  147. package/dist/{tileset → tileset-3d}/format-i3s/i3s-tile-manager.js +5 -2
  148. package/dist/tileset-3d/format-i3s/i3s-tile-manager.js.map +1 -0
  149. package/dist/{tileset → tileset-3d}/format-i3s/i3s-tileset-traverser.d.ts +2 -2
  150. package/dist/tileset-3d/format-i3s/i3s-tileset-traverser.d.ts.map +1 -0
  151. package/dist/{tileset → tileset-3d}/format-i3s/i3s-tileset-traverser.js +17 -23
  152. package/dist/tileset-3d/format-i3s/i3s-tileset-traverser.js.map +1 -0
  153. package/dist/{tileset → tileset-3d}/helpers/3d-tiles-options.d.ts +1 -1
  154. package/dist/tileset-3d/helpers/3d-tiles-options.d.ts.map +1 -0
  155. package/dist/{tileset → tileset-3d}/helpers/3d-tiles-options.js +3 -0
  156. package/dist/tileset-3d/helpers/3d-tiles-options.js.map +1 -0
  157. package/dist/{tileset → tileset-3d}/helpers/bounding-volume.d.ts +7 -3
  158. package/dist/tileset-3d/helpers/bounding-volume.d.ts.map +1 -0
  159. package/dist/{tileset → tileset-3d}/helpers/bounding-volume.js +20 -91
  160. package/dist/tileset-3d/helpers/bounding-volume.js.map +1 -0
  161. package/dist/tileset-3d/helpers/frame-state.d.ts +93 -0
  162. package/dist/tileset-3d/helpers/frame-state.d.ts.map +1 -0
  163. package/dist/{tileset → tileset-3d}/helpers/frame-state.js +92 -10
  164. package/dist/tileset-3d/helpers/frame-state.js.map +1 -0
  165. package/dist/{tileset → tileset-3d}/helpers/i3s-lod.d.ts +1 -1
  166. package/dist/tileset-3d/helpers/i3s-lod.d.ts.map +1 -0
  167. package/dist/{tileset → tileset-3d}/helpers/i3s-lod.js +21 -9
  168. package/dist/tileset-3d/helpers/i3s-lod.js.map +1 -0
  169. package/dist/tileset-3d/helpers/s2-bounding-volume.d.ts +17 -0
  170. package/dist/tileset-3d/helpers/s2-bounding-volume.d.ts.map +1 -0
  171. package/dist/tileset-3d/helpers/s2-bounding-volume.js +20 -0
  172. package/dist/tileset-3d/helpers/s2-bounding-volume.js.map +1 -0
  173. package/dist/tileset-3d/helpers/tiles-3d-lod.d.ts +72 -0
  174. package/dist/tileset-3d/helpers/tiles-3d-lod.d.ts.map +1 -0
  175. package/dist/tileset-3d/helpers/tiles-3d-lod.js +257 -0
  176. package/dist/tileset-3d/helpers/tiles-3d-lod.js.map +1 -0
  177. package/dist/tileset-3d/helpers/tiles-3d-request-priority.d.ts +134 -0
  178. package/dist/tileset-3d/helpers/tiles-3d-request-priority.d.ts.map +1 -0
  179. package/dist/tileset-3d/helpers/tiles-3d-request-priority.js +179 -0
  180. package/dist/tileset-3d/helpers/tiles-3d-request-priority.js.map +1 -0
  181. package/dist/{tileset → tileset-3d}/helpers/transform-utils.d.ts +1 -1
  182. package/dist/tileset-3d/helpers/transform-utils.d.ts.map +1 -0
  183. package/dist/tileset-3d/helpers/transform-utils.js.map +1 -0
  184. package/dist/tileset-3d/helpers/zoom.d.ts.map +1 -0
  185. package/dist/tileset-3d/helpers/zoom.js.map +1 -0
  186. package/dist/types.d.ts +14 -0
  187. package/dist/types.d.ts.map +1 -1
  188. package/dist/types.js +3 -0
  189. package/dist/types.js.map +1 -1
  190. package/dist/utils/doubly-linked-list.d.ts.map +1 -1
  191. package/dist/utils/doubly-linked-list.js +1 -0
  192. package/dist/utils/doubly-linked-list.js.map +1 -1
  193. package/dist/utils/managed-array.d.ts.map +1 -1
  194. package/dist/utils/managed-array.js +1 -0
  195. package/dist/utils/managed-array.js.map +1 -1
  196. package/package.json +12 -9
  197. package/src/image-set.ts +328 -0
  198. package/src/index.ts +157 -9
  199. package/src/point-cloud/point-cloud-tile.ts +80 -0
  200. package/src/point-cloud/point-cloud-tileset.ts +767 -0
  201. package/src/point-cloud/types.ts +99 -0
  202. package/src/raster-set.ts +504 -0
  203. package/src/spatial/format-spatial-reference.ts +385 -0
  204. package/src/spatial/get-spatial-coordinate-frame.ts +169 -0
  205. package/src/spatial/i3s-elevation.ts +96 -0
  206. package/src/spatial/i3s-spatial-transformer.ts +957 -0
  207. package/src/spatial/normalize-crs-identifier.ts +26 -0
  208. package/src/spatial/spatial-coordinate-transformer.ts +376 -0
  209. package/src/spatial/spatial-resource-registry.ts +79 -0
  210. package/src/spatial/spatial-types.ts +422 -0
  211. package/src/spatial/tiles-3d-spatial-transformer.ts +206 -0
  212. package/src/tileset-2d/adapter.ts +46 -0
  213. package/src/tileset-2d/index.ts +33 -0
  214. package/src/tileset-2d/tile-2d-header.ts +224 -0
  215. package/src/tileset-2d/tileset-2d.ts +715 -0
  216. package/src/tileset-2d/types.ts +39 -0
  217. package/src/tileset-2d.ts +5 -0
  218. package/src/tileset-3d/common/indexed-archive-tileset-source.ts +205 -0
  219. package/src/tileset-3d/common/tile-3d-contracts.ts +115 -0
  220. package/src/tileset-3d/common/tile-3d.ts +1310 -0
  221. package/src/tileset-3d/common/tileset-3d.ts +1166 -0
  222. package/src/{tileset → tileset-3d/common}/tileset-cache.ts +16 -8
  223. package/src/tileset-3d/common/tileset-content-traversal.ts +114 -0
  224. package/src/tileset-3d/common/tileset-observability.ts +100 -0
  225. package/src/tileset-3d/common/tileset-source.ts +284 -0
  226. package/src/{tileset → tileset-3d/common}/tileset-traverser.ts +74 -14
  227. package/src/tileset-3d/format-3d-tiles/implicit-tiling.ts +1059 -0
  228. package/src/tileset-3d/format-3d-tiles/tiles-3d-source.ts +1025 -0
  229. package/src/tileset-3d/format-3d-tiles/tileset-3d-traverser.ts +379 -0
  230. package/src/{tileset → tileset-3d}/format-i3s/i3s-pending-tiles-register.ts +4 -0
  231. package/src/tileset-3d/format-i3s/i3s-source.ts +557 -0
  232. package/src/{tileset → tileset-3d}/format-i3s/i3s-tile-manager.ts +6 -2
  233. package/src/{tileset → tileset-3d}/format-i3s/i3s-tileset-traverser.ts +20 -24
  234. package/src/{tileset → tileset-3d}/helpers/3d-tiles-options.ts +5 -1
  235. package/src/{tileset → tileset-3d}/helpers/bounding-volume.ts +31 -114
  236. package/src/tileset-3d/helpers/frame-state.ts +322 -0
  237. package/src/{tileset → tileset-3d}/helpers/i3s-lod.ts +24 -10
  238. package/src/tileset-3d/helpers/s2-bounding-volume.ts +35 -0
  239. package/src/tileset-3d/helpers/tiles-3d-lod.ts +370 -0
  240. package/src/tileset-3d/helpers/tiles-3d-request-priority.ts +301 -0
  241. package/src/{tileset → tileset-3d}/helpers/transform-utils.ts +1 -1
  242. package/src/types.ts +18 -0
  243. package/src/utils/doubly-linked-list.ts +2 -0
  244. package/src/utils/managed-array.ts +2 -0
  245. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts +0 -7
  246. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts.map +0 -1
  247. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -53
  248. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js.map +0 -1
  249. package/dist/tileset/format-i3s/i3s-pending-tiles-register.d.ts.map +0 -1
  250. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js.map +0 -1
  251. package/dist/tileset/format-i3s/i3s-tile-manager.d.ts.map +0 -1
  252. package/dist/tileset/format-i3s/i3s-tile-manager.js.map +0 -1
  253. package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts.map +0 -1
  254. package/dist/tileset/format-i3s/i3s-tileset-traverser.js.map +0 -1
  255. package/dist/tileset/helpers/3d-tiles-options.d.ts.map +0 -1
  256. package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
  257. package/dist/tileset/helpers/bounding-volume.d.ts.map +0 -1
  258. package/dist/tileset/helpers/bounding-volume.js.map +0 -1
  259. package/dist/tileset/helpers/frame-state.d.ts +0 -28
  260. package/dist/tileset/helpers/frame-state.d.ts.map +0 -1
  261. package/dist/tileset/helpers/frame-state.js.map +0 -1
  262. package/dist/tileset/helpers/i3s-lod.d.ts.map +0 -1
  263. package/dist/tileset/helpers/i3s-lod.js.map +0 -1
  264. package/dist/tileset/helpers/tiles-3d-lod.d.ts +0 -8
  265. package/dist/tileset/helpers/tiles-3d-lod.d.ts.map +0 -1
  266. package/dist/tileset/helpers/tiles-3d-lod.js +0 -113
  267. package/dist/tileset/helpers/tiles-3d-lod.js.map +0 -1
  268. package/dist/tileset/helpers/transform-utils.d.ts.map +0 -1
  269. package/dist/tileset/helpers/transform-utils.js.map +0 -1
  270. package/dist/tileset/helpers/zoom.d.ts.map +0 -1
  271. package/dist/tileset/helpers/zoom.js.map +0 -1
  272. package/dist/tileset/tile-3d.d.ts +0 -230
  273. package/dist/tileset/tile-3d.d.ts.map +0 -1
  274. package/dist/tileset/tile-3d.js +0 -631
  275. package/dist/tileset/tile-3d.js.map +0 -1
  276. package/dist/tileset/tileset-3d.d.ts +0 -284
  277. package/dist/tileset/tileset-3d.d.ts.map +0 -1
  278. package/dist/tileset/tileset-3d.js +0 -814
  279. package/dist/tileset/tileset-3d.js.map +0 -1
  280. package/dist/tileset/tileset-cache.d.ts +0 -19
  281. package/dist/tileset/tileset-cache.d.ts.map +0 -1
  282. package/dist/tileset/tileset-cache.js.map +0 -1
  283. package/dist/tileset/tileset-traverser.d.ts.map +0 -1
  284. package/dist/tileset/tileset-traverser.js.map +0 -1
  285. package/src/tileset/format-3d-tiles/tileset-3d-traverser.ts +0 -63
  286. package/src/tileset/helpers/frame-state.ts +0 -183
  287. package/src/tileset/helpers/tiles-3d-lod.ts +0 -149
  288. package/src/tileset/tile-3d.ts +0 -788
  289. package/src/tileset/tileset-3d.ts +0 -1037
  290. /package/dist/{tileset → tileset-3d}/format-i3s/i3s-pending-tiles-register.d.ts +0 -0
  291. /package/dist/{tileset → tileset-3d}/format-i3s/i3s-tile-manager.d.ts +0 -0
  292. /package/dist/{tileset → tileset-3d}/helpers/transform-utils.js +0 -0
  293. /package/dist/{tileset → tileset-3d}/helpers/zoom.d.ts +0 -0
  294. /package/dist/{tileset → tileset-3d}/helpers/zoom.js +0 -0
  295. /package/src/{tileset → tileset-3d}/helpers/zoom.ts +0 -0
@@ -0,0 +1,1166 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ // This file is derived from the Cesium code base under Apache 2 license
5
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
6
+
7
+ import {Matrix4, Vector3} from '@math.gl/core';
8
+ import {Ellipsoid} from '@math.gl/geospatial';
9
+ import {Stats} from '@probe.gl/stats';
10
+ import {RequestScheduler, Loader, LoaderOptions} from '@loaders.gl/loader-utils';
11
+ import {TilesetCache} from './tileset-cache';
12
+ import {calculateTransformProps} from '../helpers/transform-utils';
13
+ import {getFrameState, limitSelectedTiles, updateCameraMotionState} from '../helpers/frame-state';
14
+ import type {CameraMotionState, FrameState} from '../helpers/frame-state';
15
+ import {
16
+ calculateDynamicScreenSpaceErrorDensity,
17
+ updateRootTransformForDynamicScreenSpaceError
18
+ } from '../helpers/tiles-3d-lod';
19
+ import {interpolateLinearly} from '../helpers/tiles-3d-request-priority';
20
+ import type {FoveatedInterpolationCallback} from '../helpers/tiles-3d-request-priority';
21
+
22
+ import type {GeospatialViewport, Viewport} from '../../types';
23
+ import {Tile3D} from './tile-3d';
24
+ import {TILESET_TYPE} from '../../constants';
25
+ import type {TilesetSpatialOptions, TilesetSpatialReference} from '../../spatial/spatial-types';
26
+ import {
27
+ applyTilesetSpatialOptions,
28
+ createTilesetSpatialReference
29
+ } from '../../spatial/spatial-types';
30
+
31
+ import {TilesetTraverser} from './tileset-traverser';
32
+ import {
33
+ isTileset3DSource,
34
+ TileContentLoadResult,
35
+ TilesetContentFormats,
36
+ TilesetJSON,
37
+ Tileset3DSource,
38
+ TilesetSourceMetadata
39
+ } from './tileset-source';
40
+
41
+ export type {TilesetJSON} from './tileset-source';
42
+
43
+ export type Tileset3DProps = {
44
+ throttleRequests?: boolean;
45
+ maxRequests?: number;
46
+ loadOptions?: LoaderOptions;
47
+ loadTiles?: boolean;
48
+ basePath?: string;
49
+ /**
50
+ * Soft target, in bytes, for cached tile content that is not required by the current frame.
51
+ * The listed default applies to 3D Tiles; I3S retains its existing 32 MiB default.
52
+ * @default 536870912
53
+ */
54
+ cacheBytes?: number;
55
+ /**
56
+ * Additional bytes that the current-frame working set may use before memory-adjusted SSE rises.
57
+ * The listed default applies to 3D Tiles; I3S retains its existing 1 MiB default.
58
+ * @default 536870912
59
+ */
60
+ maximumCacheOverflowBytes?: number;
61
+ maximumTilesSelected?: number;
62
+ debounceTime?: number;
63
+
64
+ description?: string;
65
+ attributions?: string[];
66
+
67
+ ellipsoid?: object;
68
+ modelMatrix?: Matrix4;
69
+ /** Automatic CRS output options and expert source-metadata recovery overrides. */
70
+ spatial?: TilesetSpatialOptions;
71
+
72
+ maximumScreenSpaceError?: number;
73
+ /**
74
+ * Enables replacement traversal that may skip hierarchy levels while retaining ready ancestors
75
+ * as coverage. This trades temporary overdraw for faster refinement on deep trees.
76
+ * @default false
77
+ */
78
+ skipLevelOfDetail?: boolean;
79
+ /**
80
+ * SSE above which tiles remain part of the non-skipping base traversal.
81
+ * @default 1024
82
+ */
83
+ baseScreenSpaceError?: number;
84
+ /**
85
+ * Required SSE reduction from the nearest requested or loaded ancestor before loading a tile.
86
+ * @default 16
87
+ */
88
+ skipScreenSpaceErrorFactor?: number;
89
+ /**
90
+ * Minimum hierarchy levels between requested tiles during skip-LOD traversal.
91
+ * @default 1
92
+ */
93
+ skipLevels?: number;
94
+ /**
95
+ * Requests only final tiles that meet the active SSE target when skip-LOD is enabled.
96
+ * @default false
97
+ */
98
+ immediatelyLoadDesiredLevelOfDetail?: boolean;
99
+ /** Enables perspective dynamic SSE to reduce distant, horizon-facing refinement. */
100
+ dynamicScreenSpaceError?: boolean;
101
+ /** Base dynamic SSE fog density in inverse meters. */
102
+ dynamicScreenSpaceErrorDensity?: number;
103
+ /** Maximum dynamic SSE reduction in logical/CSS pixels. */
104
+ dynamicScreenSpaceErrorFactor?: number;
105
+ /** Fraction of tileset height at which dynamic SSE begins to fade, clamped to `[0, 1]`. */
106
+ dynamicScreenSpaceErrorHeightFalloff?: number;
107
+ /**
108
+ * Enables adaptive LOD reduction when estimated tile memory exceeds the overflow ceiling.
109
+ * Defaults to `true` for 3D Tiles and retains the existing `false` default for I3S.
110
+ */
111
+ memoryAdjustedScreenSpaceError?: boolean;
112
+ viewportTraversersMap?: any;
113
+ updateTransforms?: boolean;
114
+ viewDistanceScale?: number;
115
+ /** Reduced viewport-height fraction used to prioritize coarse initial coverage; `0` disables it. */
116
+ progressiveResolutionHeightFraction?: number;
117
+ /** Whether requests nearer the center of a perspective viewport receive higher priority. */
118
+ foveatedScreenSpaceError?: boolean;
119
+ /** Fraction of the perspective field of view that receives no foveated SSE relaxation. */
120
+ foveatedConeSize?: number;
121
+ /** Minimum logical-pixel SSE relaxation immediately outside the foveated cone. */
122
+ foveatedMinimumScreenSpaceErrorRelaxation?: number;
123
+ /** Function that increases SSE relaxation from the foveated cone toward the viewport edge. */
124
+ foveatedInterpolationCallback?: FoveatedInterpolationCallback;
125
+ /** Seconds peripheral requests may wait after the camera moves. */
126
+ foveatedTimeDelay?: number;
127
+
128
+ onTileLoad?: (tile: Tile3D) => any;
129
+ onTileUnload?: (tile: Tile3D) => any;
130
+ onTileError?: (tile: Tile3D, message: string, url: string) => any;
131
+ /** Called when a format-specific source operation fails. */
132
+ onSourceError?: (error: Error, source: Tileset3DSource, tile?: Tile3D | null) => any;
133
+ /** Called when tileset initialization fails before traversal can begin. */
134
+ onTilesetError?: (error: Error, tileset: Tileset3D) => any;
135
+ contentLoader?: (tile: Tile3D) => Promise<void>;
136
+ onTraversalComplete?: (selectedTiles: Tile3D[]) => Tile3D[];
137
+ onUpdate?: () => void;
138
+ };
139
+
140
+ type Props = {
141
+ description: string;
142
+ ellipsoid: object;
143
+ modelMatrix: Matrix4;
144
+ throttleRequests: boolean;
145
+ maxRequests: number;
146
+ /** Soft target, in bytes, for evictable cached tile content. */
147
+ cacheBytes: number;
148
+ /** Current-frame headroom, in bytes, before memory-adjusted SSE rises. */
149
+ maximumCacheOverflowBytes: number;
150
+ maximumTilesSelected: number;
151
+ debounceTime: number;
152
+ onTileLoad: (tile: Tile3D) => void;
153
+ onTileUnload: (tile: Tile3D) => void;
154
+ onTileError: (tile: Tile3D, message: string, url: string) => void;
155
+ onSourceError: (error: Error, source: Tileset3DSource, tile?: Tile3D | null) => void;
156
+ onTilesetError: (error: Error, tileset: Tileset3D) => void;
157
+ onTraversalComplete: (selectedTiles: Tile3D[]) => Tile3D[];
158
+ onUpdate: () => void;
159
+ maximumScreenSpaceError: number;
160
+ /** Whether replacement traversal may skip levels while retaining ancestor coverage. */
161
+ skipLevelOfDetail: boolean;
162
+ /** SSE above which tiles remain part of the non-skipping base traversal. */
163
+ baseScreenSpaceError: number;
164
+ /** Required SSE reduction between requested skip-LOD tiles. */
165
+ skipScreenSpaceErrorFactor: number;
166
+ /** Minimum hierarchy levels between requested skip-LOD tiles. */
167
+ skipLevels: number;
168
+ /** Whether skip-LOD requests only the final desired tiles. */
169
+ immediatelyLoadDesiredLevelOfDetail: boolean;
170
+ /** Whether perspective dynamic SSE is enabled. */
171
+ dynamicScreenSpaceError: boolean;
172
+ /** Base dynamic SSE fog density in inverse meters. */
173
+ dynamicScreenSpaceErrorDensity: number;
174
+ /** Maximum dynamic SSE reduction in logical/CSS pixels. */
175
+ dynamicScreenSpaceErrorFactor: number;
176
+ /** Fraction of tileset height at which dynamic SSE begins to fade. */
177
+ dynamicScreenSpaceErrorHeightFalloff: number;
178
+ /** Whether cache pressure may adapt the active SSE threshold. */
179
+ memoryAdjustedScreenSpaceError: boolean;
180
+ viewportTraversersMap: Record<string, any> | null;
181
+ attributions: string[];
182
+ loadTiles: boolean;
183
+ loadOptions: LoaderOptions;
184
+ updateTransforms: boolean;
185
+ viewDistanceScale: number;
186
+ /** Reduced viewport-height fraction used to prioritize coarse initial coverage. */
187
+ progressiveResolutionHeightFraction: number;
188
+ /** Whether perspective requests are prioritized around the viewport center. */
189
+ foveatedScreenSpaceError: boolean;
190
+ /** Fraction of the perspective field of view with no foveated SSE relaxation. */
191
+ foveatedConeSize: number;
192
+ /** Minimum logical-pixel SSE relaxation outside the foveated cone. */
193
+ foveatedMinimumScreenSpaceErrorRelaxation: number;
194
+ /** Function used to interpolate foveated SSE relaxation. */
195
+ foveatedInterpolationCallback: FoveatedInterpolationCallback;
196
+ /** Seconds eligible peripheral requests wait after camera movement. */
197
+ foveatedTimeDelay: number;
198
+ basePath: string;
199
+ contentLoader?: (tile: Tile3D) => Promise<void>;
200
+ i3s: Record<string, any>;
201
+ /** Automatic CRS output options and expert source-metadata recovery overrides. */
202
+ spatial: TilesetSpatialOptions;
203
+ };
204
+
205
+ const BYTES_PER_MEBIBYTE = 1024 * 1024;
206
+ const DEFAULT_CACHE_BYTES = 512 * BYTES_PER_MEBIBYTE;
207
+ const DEFAULT_MAXIMUM_CACHE_OVERFLOW_BYTES = 512 * BYTES_PER_MEBIBYTE;
208
+ const DEFAULT_I3S_CACHE_BYTES = 32 * BYTES_PER_MEBIBYTE;
209
+ const DEFAULT_I3S_MAXIMUM_CACHE_OVERFLOW_BYTES = BYTES_PER_MEBIBYTE;
210
+
211
+ /**
212
+ * Validates a byte-based tile-cache budget.
213
+ *
214
+ * Fractions are accepted because JavaScript memory estimates are numbers, but negative, infinite,
215
+ * and `NaN` values cannot define a stable cache threshold.
216
+ *
217
+ * @param value - Proposed cache budget in bytes.
218
+ * @param optionName - Public option name used in an actionable error message.
219
+ * @returns The validated byte budget.
220
+ */
221
+ function validateCacheByteLength(value: number, optionName: string): number {
222
+ if (!Number.isFinite(value) || value < 0) {
223
+ throw new Error(`${optionName} must be a finite number greater than or equal to 0`);
224
+ }
225
+ return value;
226
+ }
227
+
228
+ /**
229
+ * Resolves the base cache target from the byte-native option or its fallback.
230
+ *
231
+ * @param options - Options that may contain a byte-native cache value.
232
+ * @param fallbackCacheBytes - Existing or default cache target in bytes.
233
+ * @returns The resolved and validated cache target in bytes.
234
+ */
235
+ function resolveCacheBytes(options: Tileset3DProps, fallbackCacheBytes: number): number {
236
+ const cacheBytes = options.cacheBytes ?? fallbackCacheBytes;
237
+ return validateCacheByteLength(cacheBytes, 'cacheBytes');
238
+ }
239
+
240
+ /**
241
+ * Resolves cache overflow headroom from the byte-native option or its fallback.
242
+ *
243
+ * @param options - Options that may contain a byte-native overflow value.
244
+ * @param fallbackOverflowBytes - Existing or default overflow headroom in bytes.
245
+ * @returns The resolved and validated overflow headroom in bytes.
246
+ */
247
+ function resolveMaximumCacheOverflowBytes(
248
+ options: Tileset3DProps,
249
+ fallbackOverflowBytes: number
250
+ ): number {
251
+ const maximumCacheOverflowBytes = options.maximumCacheOverflowBytes ?? fallbackOverflowBytes;
252
+ return validateCacheByteLength(maximumCacheOverflowBytes, 'maximumCacheOverflowBytes');
253
+ }
254
+
255
+ const DEFAULT_PROPS: Props = {
256
+ description: '',
257
+ ellipsoid: Ellipsoid.WGS84,
258
+ modelMatrix: new Matrix4(),
259
+ throttleRequests: true,
260
+ maxRequests: 64,
261
+ cacheBytes: DEFAULT_CACHE_BYTES,
262
+ maximumCacheOverflowBytes: DEFAULT_MAXIMUM_CACHE_OVERFLOW_BYTES,
263
+ maximumTilesSelected: 0,
264
+ debounceTime: 0,
265
+ onTileLoad: () => {},
266
+ onTileUnload: () => {},
267
+ onTileError: () => {},
268
+ onSourceError: () => {},
269
+ onTilesetError: () => {},
270
+ onTraversalComplete: (selectedTiles: Tile3D[]) => selectedTiles,
271
+ onUpdate: () => {},
272
+ contentLoader: undefined,
273
+ viewDistanceScale: 1.0,
274
+ progressiveResolutionHeightFraction: 0.3,
275
+ foveatedScreenSpaceError: true,
276
+ foveatedConeSize: 0.1,
277
+ foveatedMinimumScreenSpaceErrorRelaxation: 0,
278
+ foveatedInterpolationCallback: interpolateLinearly,
279
+ foveatedTimeDelay: 0.2,
280
+ maximumScreenSpaceError: 8,
281
+ skipLevelOfDetail: false,
282
+ baseScreenSpaceError: 1024,
283
+ skipScreenSpaceErrorFactor: 16,
284
+ skipLevels: 1,
285
+ immediatelyLoadDesiredLevelOfDetail: false,
286
+ dynamicScreenSpaceError: true,
287
+ dynamicScreenSpaceErrorDensity: 2.0e-4,
288
+ dynamicScreenSpaceErrorFactor: 24,
289
+ dynamicScreenSpaceErrorHeightFalloff: 0.25,
290
+ memoryAdjustedScreenSpaceError: true,
291
+ loadTiles: true,
292
+ updateTransforms: true,
293
+ viewportTraversersMap: null,
294
+ loadOptions: {fetch: {}},
295
+ attributions: [],
296
+ basePath: '',
297
+ i3s: {},
298
+ spatial: {}
299
+ };
300
+
301
+ const TILES_TOTAL = 'Tiles In Tileset(s)';
302
+ const TILES_IN_MEMORY = 'Tiles In Memory';
303
+ const TILES_IN_VIEW = 'Tiles In View';
304
+ const TILES_RENDERABLE = 'Tiles To Render';
305
+ const TILES_LOADED = 'Tiles Loaded';
306
+ const TILES_LOADING = 'Tiles Loading';
307
+ const TILES_UNLOADED = 'Tiles Unloaded';
308
+ const TILES_LOAD_FAILED = 'Failed Tile Loads';
309
+ const POINTS_COUNT = 'Points/Vertices';
310
+ const TILES_GPU_MEMORY = 'Tile Memory Use';
311
+ const MAXIMUM_SSE = 'Maximum Screen Space Error';
312
+
313
+ /**
314
+ * Shared runtime for tile traversal, selection, cache management, and request scheduling.
315
+ *
316
+ * Format-specific loading behavior is delegated to a {@link Tileset3DSource} implementation.
317
+ */
318
+ export class Tileset3D {
319
+ options: Props;
320
+ loadOptions: LoaderOptions;
321
+ /** Source implementation responsible for format-specific initialization and loading. */
322
+ source: Tileset3DSource;
323
+
324
+ type: TILESET_TYPE;
325
+ tileset: TilesetJSON | null;
326
+ loader: Loader;
327
+ url: string;
328
+ basePath: string;
329
+ modelMatrix: Matrix4;
330
+ ellipsoid: any;
331
+ lodMetricType: string;
332
+ lodMetricValue: number;
333
+ refine: string;
334
+ root: Tile3D | null = null;
335
+ roots: Record<string, Tile3D> = {};
336
+ asset: Record<string, any> = {};
337
+ /** Inline metadata schema declared by the source tileset, when present. */
338
+ schema: Record<string, any> | null = null;
339
+ /** External metadata schema URI declared by the source tileset, when present. */
340
+ schemaUri: string | null = null;
341
+ /** Metadata groups declared by the source tileset, in source order. */
342
+ groups: Array<Record<string, any>> = [];
343
+ /** Tileset-wide metadata entity, preserved without property-table decoding. */
344
+ metadata: Record<string, any> | null = null;
345
+ /** Tileset statistics metadata, preserved for application-level inspection. */
346
+ statistics: unknown = null;
347
+ /** Normalized source and target coordinate reference system metadata. */
348
+ spatialReference: TilesetSpatialReference = createTilesetSpatialReference({});
349
+
350
+ description = '';
351
+ properties: any;
352
+ extras: any = null;
353
+ attributions: any = {};
354
+ credits: any = {};
355
+
356
+ stats: Stats;
357
+ contentFormats: TilesetContentFormats;
358
+
359
+ cartographicCenter: Vector3 | null = null;
360
+ cartesianCenter: Vector3 | null = null;
361
+ zoom = 1;
362
+ boundingVolume: any = null;
363
+
364
+ /** Effective dynamic SSE density calculated for the most recently traversed viewport. */
365
+ dynamicScreenSpaceErrorComputedDensity = 0;
366
+
367
+ /** Estimated bytes currently retained by loaded tile content. */
368
+ gpuMemoryUsageInBytes = 0;
369
+ /** Active SSE threshold after optional cache-pressure adjustment, in logical/CSS pixels. */
370
+ memoryAdjustedScreenSpaceError = 0.0;
371
+
372
+ private _cacheBytes = DEFAULT_CACHE_BYTES;
373
+ private _maximumCacheOverflowBytes = DEFAULT_MAXIMUM_CACHE_OVERFLOW_BYTES;
374
+
375
+ _frameNumber = 0;
376
+ private _tiles: Record<string, Tile3D> = {};
377
+ private _pendingCount = 0;
378
+
379
+ selectedTiles: Tile3D[] = [];
380
+
381
+ traverseCounter = 0;
382
+ geometricError = 0;
383
+ private lastUpdatedVieports: Viewport[] | Viewport | null = null;
384
+ private _requestedTiles: Tile3D[] = [];
385
+ private _emptyTiles: Tile3D[] = [];
386
+ private frameStateData: any = {};
387
+ /** Last camera pose retained independently for each viewport. */
388
+ private _cameraMotionStates: Record<string, CameraMotionState> = {};
389
+ /** Pending traversal that releases requests after camera motion settles. */
390
+ private _deferredTraversalTimeout: ReturnType<typeof setTimeout> | null = null;
391
+
392
+ _traverser: TilesetTraverser;
393
+ _cache = new TilesetCache();
394
+ _requestScheduler: RequestScheduler;
395
+
396
+ private _heldTiles: Set<string> = new Set();
397
+ private updatePromise: Promise<number> | null = null;
398
+ tilesetInitializationPromise: Promise<void>;
399
+
400
+ /**
401
+ * Creates a tileset runtime from an explicit source implementation.
402
+ * @param source Source-backed tileset implementation.
403
+ * @param options Traversal and runtime options.
404
+ */
405
+ constructor(source: Tileset3DSource, options?: Tileset3DProps) {
406
+ if (!isTileset3DSource(source)) {
407
+ throw new Error('Tileset3D requires a Tileset3DSource instance');
408
+ }
409
+
410
+ const suppliedOptions = options || {};
411
+ const usesTiles3DCacheDefaults = source.type === TILESET_TYPE.TILES3D;
412
+ const defaultCacheBytes = usesTiles3DCacheDefaults
413
+ ? DEFAULT_PROPS.cacheBytes
414
+ : DEFAULT_I3S_CACHE_BYTES;
415
+ const defaultMaximumCacheOverflowBytes = usesTiles3DCacheDefaults
416
+ ? DEFAULT_PROPS.maximumCacheOverflowBytes
417
+ : DEFAULT_I3S_MAXIMUM_CACHE_OVERFLOW_BYTES;
418
+ const cacheBytes = resolveCacheBytes(suppliedOptions, defaultCacheBytes);
419
+ const maximumCacheOverflowBytes = resolveMaximumCacheOverflowBytes(
420
+ suppliedOptions,
421
+ defaultMaximumCacheOverflowBytes
422
+ );
423
+ this.options = {
424
+ ...DEFAULT_PROPS,
425
+ ...suppliedOptions,
426
+ cacheBytes,
427
+ maximumCacheOverflowBytes,
428
+ memoryAdjustedScreenSpaceError:
429
+ suppliedOptions.memoryAdjustedScreenSpaceError ?? usesTiles3DCacheDefaults
430
+ };
431
+ this.loadOptions = this.options.loadOptions || {};
432
+ this.source = source;
433
+
434
+ this.tileset = null;
435
+ this.loader = this.source.loader;
436
+ this.type = this.source.type;
437
+ this.url = this.source.url;
438
+ this.basePath = this.source.basePath;
439
+ this.modelMatrix = this.options.modelMatrix;
440
+ this.ellipsoid = this.options.ellipsoid;
441
+ this.lodMetricType = '';
442
+ this.lodMetricValue = 0;
443
+ this.refine = '';
444
+ this.contentFormats = this.source.contentFormats;
445
+
446
+ this._traverser = this._initializeTraverser();
447
+ this._requestScheduler = new RequestScheduler({
448
+ throttleRequests: this.options.throttleRequests,
449
+ maxRequests: this.options.maxRequests
450
+ });
451
+
452
+ this.memoryAdjustedScreenSpaceError = this.options.maximumScreenSpaceError;
453
+ this._cacheBytes = cacheBytes;
454
+ this._maximumCacheOverflowBytes = maximumCacheOverflowBytes;
455
+ const metadata = this._getSourceMetadata();
456
+ if (metadata) {
457
+ this.spatialReference = applyTilesetSpatialOptions(
458
+ metadata.spatialReference,
459
+ this.options.spatial
460
+ );
461
+ }
462
+
463
+ this.stats = new Stats({id: this.url});
464
+ this._initializeStats();
465
+
466
+ this.tilesetInitializationPromise = this._initializeTileSet();
467
+ }
468
+
469
+ destroy(): void {
470
+ this._clearDeferredTraversal();
471
+ this.source.destroy?.();
472
+ this._destroy();
473
+ }
474
+
475
+ isLoaded(): boolean {
476
+ return this._pendingCount === 0 && this._frameNumber !== 0 && this._requestedTiles.length === 0;
477
+ }
478
+
479
+ get tiles(): object[] {
480
+ return Object.values(this._tiles);
481
+ }
482
+
483
+ get frameNumber(): number {
484
+ return this._frameNumber;
485
+ }
486
+
487
+ /**
488
+ * Returns the tiles requested during the most recent completed traversal.
489
+ *
490
+ * A defensive copy makes request ordering deterministic for diagnostics and prevents callers
491
+ * from mutating the scheduler's working set.
492
+ */
493
+ get requestedTiles(): readonly Tile3D[] {
494
+ return this._requestedTiles.slice();
495
+ }
496
+
497
+ /**
498
+ * Returns empty tiles considered during the most recent completed traversal.
499
+ *
500
+ * Empty tiles can still be useful hierarchy placeholders, but their IDs are included in
501
+ * observability snapshots so applications can distinguish traversal work from render content.
502
+ */
503
+ get emptyTiles(): readonly Tile3D[] {
504
+ return this._emptyTiles.slice();
505
+ }
506
+
507
+ /**
508
+ * Gets or sets the soft target, in bytes, for cached tile content not needed this frame.
509
+ *
510
+ * Current-frame tiles remain protected even when their estimated memory exceeds this target.
511
+ * Reducing the value makes unused least-recently-used tiles eligible for eviction on the next
512
+ * traversal.
513
+ * @default 536870912 for 3D Tiles; 33554432 for I3S
514
+ */
515
+ get cacheBytes(): number {
516
+ return this._cacheBytes;
517
+ }
518
+
519
+ set cacheBytes(value: number) {
520
+ this._cacheBytes = validateCacheByteLength(value, 'cacheBytes');
521
+ this.options.cacheBytes = this._cacheBytes;
522
+ }
523
+
524
+ /**
525
+ * Gets or sets the additional current-frame headroom, in bytes, before memory-adjusted SSE rises.
526
+ *
527
+ * The pressure ceiling is `cacheBytes + maximumCacheOverflowBytes`. This value does not change
528
+ * the base target used to evict tiles that were not touched in the current frame.
529
+ * @default 536870912 for 3D Tiles; 1048576 for I3S
530
+ */
531
+ get maximumCacheOverflowBytes(): number {
532
+ return this._maximumCacheOverflowBytes;
533
+ }
534
+
535
+ set maximumCacheOverflowBytes(value: number) {
536
+ this._maximumCacheOverflowBytes = validateCacheByteLength(value, 'maximumCacheOverflowBytes');
537
+ this.options.maximumCacheOverflowBytes = this._maximumCacheOverflowBytes;
538
+ }
539
+
540
+ get queryParams(): string {
541
+ const rootUrl = this.source.getTileUrl(this.url);
542
+ const queryIndex = rootUrl.indexOf('?');
543
+ return queryIndex >= 0 ? rootUrl.slice(queryIndex + 1) : '';
544
+ }
545
+
546
+ /**
547
+ * Updates traversal and runtime options while retaining unspecified byte budgets.
548
+ *
549
+ * @param props - Partial runtime options to apply.
550
+ */
551
+ setProps(props: Tileset3DProps): void {
552
+ const cacheBytes = resolveCacheBytes(props, this.cacheBytes);
553
+ const maximumCacheOverflowBytes = resolveMaximumCacheOverflowBytes(
554
+ props,
555
+ this.maximumCacheOverflowBytes
556
+ );
557
+ this.options = {
558
+ ...this.options,
559
+ ...props,
560
+ cacheBytes,
561
+ maximumCacheOverflowBytes
562
+ };
563
+ this._cacheBytes = cacheBytes;
564
+ this._maximumCacheOverflowBytes = maximumCacheOverflowBytes;
565
+ }
566
+
567
+ getTileUrl(tilePath: string): string {
568
+ return this.source.getTileUrl(tilePath);
569
+ }
570
+
571
+ hasExtension(extensionName: string): boolean {
572
+ return Boolean(this.source.hasExtension?.(extensionName));
573
+ }
574
+
575
+ update(viewports: Viewport[] | Viewport | null = null): void {
576
+ this.tilesetInitializationPromise.then(() => {
577
+ if (!viewports && this.lastUpdatedVieports) {
578
+ viewports = this.lastUpdatedVieports;
579
+ } else {
580
+ this.lastUpdatedVieports = viewports;
581
+ }
582
+ if (viewports) {
583
+ this.doUpdate(viewports);
584
+ }
585
+ });
586
+ }
587
+
588
+ async selectTiles(viewports: Viewport[] | Viewport | null = null): Promise<number> {
589
+ await this.tilesetInitializationPromise;
590
+ if (viewports) {
591
+ this.lastUpdatedVieports = viewports;
592
+ }
593
+ if (!this.updatePromise) {
594
+ this.updatePromise = new Promise<number>(resolve => {
595
+ setTimeout(() => {
596
+ if (this.lastUpdatedVieports) {
597
+ this.doUpdate(this.lastUpdatedVieports);
598
+ }
599
+ resolve(this._frameNumber);
600
+ this.updatePromise = null;
601
+ }, this.options.debounceTime);
602
+ });
603
+ }
604
+ return this.updatePromise;
605
+ }
606
+
607
+ /**
608
+ * Moves the active LOD threshold toward the configured SSE or away from cache pressure.
609
+ *
610
+ * Usage below {@link Tileset3D.cacheBytes} restores quality in two-percent steps. Usage above
611
+ * `cacheBytes + maximumCacheOverflowBytes` reduces refinement in two-percent steps. Values in
612
+ * the overflow window leave the threshold unchanged, preventing rapid load/evict oscillation.
613
+ */
614
+ adjustScreenSpaceError(): void {
615
+ if (this.gpuMemoryUsageInBytes < this.cacheBytes) {
616
+ this.memoryAdjustedScreenSpaceError = Math.max(
617
+ this.memoryAdjustedScreenSpaceError / 1.02,
618
+ this.options.maximumScreenSpaceError
619
+ );
620
+ } else if (this.gpuMemoryUsageInBytes > this.cacheBytes + this.maximumCacheOverflowBytes) {
621
+ this.memoryAdjustedScreenSpaceError *= 1.02;
622
+ }
623
+ }
624
+
625
+ private doUpdate(viewports: Viewport[] | Viewport): void {
626
+ if ('loadTiles' in this.options && !this.options.loadTiles) {
627
+ return;
628
+ }
629
+ if (this.traverseCounter > 0) {
630
+ return;
631
+ }
632
+ const preparedViewports = viewports instanceof Array ? viewports : [viewports];
633
+ const activeViewportIds = new Set(preparedViewports.map(viewport => viewport.id));
634
+ // A viewport may be removed between frames. Discard its completed state before aggregating
635
+ // requested and selected tiles so observability reflects only the current traversal inputs.
636
+ for (const frameStateId of Object.keys(this.frameStateData)) {
637
+ if (!activeViewportIds.has(frameStateId)) {
638
+ delete this.frameStateData[frameStateId];
639
+ }
640
+ }
641
+
642
+ this._cache.reset();
643
+ this._frameNumber++;
644
+ this.traverseCounter = preparedViewports.length;
645
+ const currentTime = Date.now();
646
+ let minimumDeferredTraversalDelay = Number.POSITIVE_INFINITY;
647
+ const viewportsToTraverse: string[] = [];
648
+ for (const viewport of preparedViewports) {
649
+ const id = viewport.id;
650
+ if (this._needTraverse(id)) {
651
+ viewportsToTraverse.push(id);
652
+ } else {
653
+ this.traverseCounter--;
654
+ }
655
+ }
656
+
657
+ for (const viewport of preparedViewports) {
658
+ const id = viewport.id;
659
+ if (!this.roots[id]) {
660
+ this.roots[id] = this._initializeTileHeaders(this.tileset, null);
661
+ }
662
+
663
+ if (!viewportsToTraverse.includes(id)) {
664
+ continue;
665
+ }
666
+ const frameState = getFrameState(viewport as GeospatialViewport, this._frameNumber);
667
+ const root = this.roots[id];
668
+ const cameraMotionUpdate = updateCameraMotionState(
669
+ this._cameraMotionStates[id],
670
+ frameState.camera.position,
671
+ frameState.camera.direction,
672
+ currentTime
673
+ );
674
+ this._cameraMotionStates[id] = cameraMotionUpdate.state;
675
+ frameState.camera.timeSinceMovement = cameraMotionUpdate.timeSinceMovement;
676
+ // Dynamic SSE reads the root's inverse computed transform before traversal updates tile
677
+ // visibility. Refresh it from the current tileset model matrix here so animated local
678
+ // box/sphere tilesets never calculate their height falloff one transform behind the frame.
679
+ updateRootTransformForDynamicScreenSpaceError(root, this.modelMatrix);
680
+ frameState.dynamicScreenSpaceErrorDensity =
681
+ this.type === TILESET_TYPE.TILES3D &&
682
+ this.options.dynamicScreenSpaceError &&
683
+ !frameState.viewport.orthographic
684
+ ? calculateDynamicScreenSpaceErrorDensity(root, frameState, this.options)
685
+ : 0;
686
+ // Keep the legacy diagnostic field, but traversal reads the per-viewport frame value above.
687
+ this.dynamicScreenSpaceErrorComputedDensity = frameState.dynamicScreenSpaceErrorDensity;
688
+ this._traverser.traverse(root, frameState, this.options);
689
+ if (Object.keys(this._traverser.deferredTiles).length > 0) {
690
+ minimumDeferredTraversalDelay = Math.min(
691
+ minimumDeferredTraversalDelay,
692
+ Math.max(this.options.foveatedTimeDelay - cameraMotionUpdate.timeSinceMovement, 0)
693
+ );
694
+ }
695
+ }
696
+
697
+ if (Number.isFinite(minimumDeferredTraversalDelay)) {
698
+ this._scheduleDeferredTraversal(minimumDeferredTraversalDelay);
699
+ } else {
700
+ this._clearDeferredTraversal();
701
+ }
702
+ }
703
+
704
+ /**
705
+ * Schedules one follow-up traversal when the moving-camera deferral window expires.
706
+ *
707
+ * Replacing an existing timer ensures continuing camera movement pushes the retry window forward
708
+ * instead of creating a queue of redundant traversals.
709
+ *
710
+ * @param delayInSeconds - Remaining stationary delay before deferred requests become eligible.
711
+ */
712
+ private _scheduleDeferredTraversal(delayInSeconds: number): void {
713
+ this._clearDeferredTraversal();
714
+ this._deferredTraversalTimeout = setTimeout(
715
+ () => {
716
+ this._deferredTraversalTimeout = null;
717
+ this.selectTiles().catch((error: unknown) => {
718
+ const traversalError = error instanceof Error ? error : new Error(String(error));
719
+ this._onTilesetError(traversalError);
720
+ });
721
+ },
722
+ Math.max(delayInSeconds * 1000, 0)
723
+ );
724
+ }
725
+
726
+ /** Clears a pending moving-camera follow-up traversal. */
727
+ private _clearDeferredTraversal(): void {
728
+ if (this._deferredTraversalTimeout !== null) {
729
+ clearTimeout(this._deferredTraversalTimeout);
730
+ this._deferredTraversalTimeout = null;
731
+ }
732
+ }
733
+
734
+ _needTraverse(viewportId: string): boolean {
735
+ let traverserId = viewportId;
736
+ if (this.options.viewportTraversersMap) {
737
+ traverserId = this.options.viewportTraversersMap[viewportId];
738
+ }
739
+ return traverserId === viewportId;
740
+ }
741
+
742
+ _onTraversalEnd(frameState: FrameState): void {
743
+ const id = frameState.viewport.id;
744
+ if (!this.frameStateData[id]) {
745
+ this.frameStateData[id] = {selectedTiles: [], _requestedTiles: [], _emptyTiles: []};
746
+ }
747
+ const currentFrameStateData = this.frameStateData[id];
748
+ const selectedTiles = Object.values(this._traverser.selectedTiles);
749
+ const [filteredSelectedTiles, unselectedTiles] = limitSelectedTiles(
750
+ selectedTiles,
751
+ frameState,
752
+ this.options.maximumTilesSelected
753
+ );
754
+ currentFrameStateData.selectedTiles = filteredSelectedTiles;
755
+ for (const tile of unselectedTiles) {
756
+ tile.unselect();
757
+ }
758
+
759
+ currentFrameStateData._requestedTiles = Object.values(this._traverser.requestedTiles);
760
+ currentFrameStateData._emptyTiles = Object.values(this._traverser.emptyTiles);
761
+
762
+ this.traverseCounter--;
763
+ if (this.traverseCounter > 0) {
764
+ return;
765
+ }
766
+
767
+ this._updateTiles();
768
+ }
769
+
770
+ _updateTiles(): void {
771
+ const previousSelectedTiles = this.selectedTiles;
772
+ this.selectedTiles = [];
773
+ this._requestedTiles = [];
774
+ this._emptyTiles = [];
775
+
776
+ for (const frameStateKey in this.frameStateData) {
777
+ const frameStateDataValue = this.frameStateData[frameStateKey];
778
+ this.selectedTiles = this.selectedTiles.concat(frameStateDataValue.selectedTiles);
779
+ this._requestedTiles = this._requestedTiles.concat(frameStateDataValue._requestedTiles);
780
+ this._emptyTiles = this._emptyTiles.concat(frameStateDataValue._emptyTiles);
781
+ }
782
+
783
+ this.selectedTiles = this.options.onTraversalComplete(this.selectedTiles);
784
+
785
+ const selectedIds = new Set(this.selectedTiles.map(tile => tile.id));
786
+ const hasUndrawnTiles = this.selectedTiles.some(tile => !tile.tileDrawn);
787
+
788
+ let heldBackCount = 0;
789
+ if (hasUndrawnTiles) {
790
+ for (const tileId of selectedIds) {
791
+ this._heldTiles.add(tileId);
792
+ }
793
+ for (const tileId of this._heldTiles) {
794
+ if (selectedIds.has(tileId)) continue;
795
+
796
+ const tile = this._tiles[tileId];
797
+ if (tile && tile.contentAvailable) {
798
+ tile._selectedFrame = this._frameNumber;
799
+ this.selectedTiles.push(tile);
800
+ heldBackCount++;
801
+ } else {
802
+ this._heldTiles.delete(tileId);
803
+ }
804
+ }
805
+ } else {
806
+ this._heldTiles = selectedIds;
807
+ }
808
+
809
+ if (heldBackCount > 0) {
810
+ setTimeout(() => {
811
+ this.selectTiles();
812
+ }, 0);
813
+ }
814
+
815
+ for (const tile of this.selectedTiles) {
816
+ this._tiles[tile.id] = tile;
817
+ }
818
+
819
+ this._loadTiles();
820
+ this._unloadTiles();
821
+ this._updateStats();
822
+
823
+ if (this._tilesChanged(previousSelectedTiles, this.selectedTiles)) {
824
+ this.options.onUpdate();
825
+ }
826
+ }
827
+
828
+ _tilesChanged(oldSelectedTiles: Tile3D[], selectedTiles: Tile3D[]): boolean {
829
+ if (oldSelectedTiles.length !== selectedTiles.length) {
830
+ return true;
831
+ }
832
+ const oldSet = new Set(oldSelectedTiles.map(tile => tile.id));
833
+ const newSet = new Set(selectedTiles.map(tile => tile.id));
834
+ let changed = oldSelectedTiles.some(tile => !newSet.has(tile.id));
835
+ changed = changed || selectedTiles.some(tile => !oldSet.has(tile.id));
836
+ return changed;
837
+ }
838
+
839
+ _loadTiles(): void {
840
+ this._requestedTiles.sort((tileA, tileB) => tileA._priority - tileB._priority);
841
+ for (const tile of this._requestedTiles) {
842
+ if (tile.contentUnloaded) {
843
+ this._loadTile(tile);
844
+ }
845
+ }
846
+ }
847
+
848
+ _unloadTiles(): void {
849
+ this._cache.unloadTiles(this, (tileset, tile) => tileset._unloadTile(tile));
850
+ if (this.options.memoryAdjustedScreenSpaceError) {
851
+ this.adjustScreenSpaceError();
852
+ }
853
+ }
854
+
855
+ _updateStats(): void {
856
+ let tilesRenderable = 0;
857
+ let pointsRenderable = 0;
858
+ for (const tile of this.selectedTiles) {
859
+ if (tile.contentAvailable && tile.content) {
860
+ tilesRenderable++;
861
+ const contents = tile.contents.length ? tile.contents : [tile.content];
862
+ for (const content of contents) {
863
+ if (content.pointCount) {
864
+ pointsRenderable += content.pointCount;
865
+ } else {
866
+ pointsRenderable += content.vertexCount || 0;
867
+ }
868
+ }
869
+ }
870
+ }
871
+
872
+ this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length;
873
+ this.stats.get(TILES_RENDERABLE).count = tilesRenderable;
874
+ this.stats.get(POINTS_COUNT).count = pointsRenderable;
875
+ this.stats.get(MAXIMUM_SSE).count = this.memoryAdjustedScreenSpaceError;
876
+ }
877
+
878
+ async _initializeTileSet(): Promise<void> {
879
+ try {
880
+ const initializePromise = this.source.initialize();
881
+ const initialMetadata = this._getSourceMetadata();
882
+ if (initialMetadata) {
883
+ this._syncSourceState(initialMetadata);
884
+ }
885
+ if (
886
+ initialMetadata?.tileset?.root &&
887
+ typeof initialMetadata.tileset.root.then !== 'function' &&
888
+ (!this.source.prepareTileset || this.spatialReference?.status === 'native')
889
+ ) {
890
+ this.root = this._initializeTileHeaders(initialMetadata.tileset, null);
891
+ this._applyViewState();
892
+ }
893
+
894
+ await initializePromise;
895
+ const metadata = this.source.getMetadata();
896
+ this._syncSourceState(metadata);
897
+ await this.source.prepareTileset?.(this);
898
+ if (!this.root) {
899
+ this.root = this._initializeTileHeaders(metadata.tileset, null);
900
+ }
901
+ this._applyViewState();
902
+ } catch (error: unknown) {
903
+ const sourceError = error instanceof Error ? error : new Error(String(error));
904
+ this._onSourceError(sourceError, this.root);
905
+ this._onTilesetError(sourceError);
906
+ throw sourceError;
907
+ }
908
+ }
909
+
910
+ _initializeStats(): void {
911
+ this.stats.get(TILES_TOTAL);
912
+ this.stats.get(TILES_LOADING);
913
+ this.stats.get(TILES_IN_MEMORY);
914
+ this.stats.get(TILES_IN_VIEW);
915
+ this.stats.get(TILES_RENDERABLE);
916
+ this.stats.get(TILES_LOADED);
917
+ this.stats.get(TILES_UNLOADED);
918
+ this.stats.get(TILES_LOAD_FAILED);
919
+ this.stats.get(POINTS_COUNT);
920
+ this.stats.get(TILES_GPU_MEMORY, 'memory');
921
+ this.stats.get(MAXIMUM_SSE);
922
+ }
923
+
924
+ _initializeTileHeaders(tilesetJson: TilesetJSON, parentTileHeader?: Tile3D | null): Tile3D {
925
+ return this.source.initializeTileHeaders(this, tilesetJson, parentTileHeader);
926
+ }
927
+
928
+ _initializeTraverser(): TilesetTraverser {
929
+ return this.source.createTraverser({
930
+ basePath: this.basePath,
931
+ onTraversalEnd: this._onTraversalEnd.bind(this)
932
+ });
933
+ }
934
+
935
+ _destroyTileHeaders(parentTile: Tile3D): void {
936
+ this._destroySubtree(parentTile);
937
+ }
938
+
939
+ async _loadTile(tile: Tile3D): Promise<void> {
940
+ let loadResult: TileContentLoadResult | null = null;
941
+ try {
942
+ this._onStartTileLoading();
943
+ loadResult = await tile.loadContent();
944
+ } catch (error: unknown) {
945
+ const tileError = error instanceof Error ? error : new Error('load failed');
946
+ this._onSourceError(tileError, tile);
947
+ this._onTileLoadError(tile, tileError);
948
+ } finally {
949
+ this._onEndTileLoading();
950
+ this._onTileLoad(tile, loadResult);
951
+ }
952
+ }
953
+
954
+ /**
955
+ * Loads a source-managed lazy child-header group and reports failures through tile callbacks.
956
+ *
957
+ * Subtree metadata shares the normal loading counters but is not reported as render content and
958
+ * is not added to the GPU cache. Traversal is notified separately after the promise settles.
959
+ *
960
+ * @param tile - Runtime tile that owns the lazy subtree reference.
961
+ * @param frameState - View state that made the subtree eligible for refinement.
962
+ */
963
+ async _loadTileChildren(tile: Tile3D, frameState: FrameState): Promise<void> {
964
+ try {
965
+ this._onStartTileLoading();
966
+ await tile.loadChildren(frameState);
967
+ } catch (error: unknown) {
968
+ const tileError = error instanceof Error ? error : new Error('subtree load failed');
969
+ this._onSourceError(tileError, tile);
970
+ this._onTileLoadError(tile, tileError);
971
+ } finally {
972
+ this._onEndTileLoading();
973
+ }
974
+ }
975
+
976
+ _onTileLoadError(tile: Tile3D, error: Error): void {
977
+ this.stats.get(TILES_LOAD_FAILED).incrementCount();
978
+
979
+ const message = error.message || error.toString();
980
+ const url = tile.url;
981
+ console.error(`A 3D tile failed to load: ${tile.url} ${message}`);
982
+ this.options.onTileError(tile, message, url);
983
+ }
984
+
985
+ _onSourceError(error: Error, tile: Tile3D | null = null): void {
986
+ this.options.onSourceError(error, this.source, tile);
987
+ }
988
+
989
+ _onTilesetError(error: Error): void {
990
+ this.options.onTilesetError(error, this);
991
+ }
992
+
993
+ _onTileLoad(tile: Tile3D, loadResult: TileContentLoadResult | null): void {
994
+ if (!loadResult?.loaded) {
995
+ return;
996
+ }
997
+
998
+ if (tile.content) {
999
+ calculateTransformProps(tile, tile.content);
1000
+ }
1001
+
1002
+ this.source.onTileLoaded?.(this, tile, loadResult);
1003
+ this._syncSourceState(this.source.getMetadata());
1004
+
1005
+ const totalTiles = this.source.getTilesTotalCount?.();
1006
+ if (totalTiles) {
1007
+ this.stats.get(TILES_TOTAL).reset();
1008
+ this.stats.get(TILES_TOTAL).addCount(totalTiles);
1009
+ }
1010
+
1011
+ this._addTileToCache(tile);
1012
+ this.options.onTileLoad(tile);
1013
+ }
1014
+
1015
+ _onStartTileLoading(): void {
1016
+ this._pendingCount++;
1017
+ this.stats.get(TILES_LOADING).incrementCount();
1018
+ }
1019
+
1020
+ _onEndTileLoading(): void {
1021
+ this._pendingCount--;
1022
+ this.stats.get(TILES_LOADING).decrementCount();
1023
+ }
1024
+
1025
+ _addTileToCache(tile: Tile3D): void {
1026
+ this._cache.add(this, tile, tileset => tileset._updateCacheStats(tile));
1027
+ }
1028
+
1029
+ _updateCacheStats(tile: Tile3D): void {
1030
+ this.stats.get(TILES_LOADED).incrementCount();
1031
+ this.stats.get(TILES_IN_MEMORY).incrementCount();
1032
+
1033
+ this.gpuMemoryUsageInBytes += tile.gpuMemoryUsageInBytes || 0;
1034
+ this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
1035
+
1036
+ if (this.options.memoryAdjustedScreenSpaceError) {
1037
+ this.adjustScreenSpaceError();
1038
+ }
1039
+ }
1040
+
1041
+ _unloadTile(tile: Tile3D): void {
1042
+ this.gpuMemoryUsageInBytes -= tile.gpuMemoryUsageInBytes || 0;
1043
+
1044
+ this.stats.get(TILES_IN_MEMORY).decrementCount();
1045
+ this.stats.get(TILES_UNLOADED).incrementCount();
1046
+ this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
1047
+
1048
+ this.options.onTileUnload(tile);
1049
+ tile.unloadContent();
1050
+ }
1051
+
1052
+ _destroy(): void {
1053
+ const stack: Tile3D[] = [];
1054
+
1055
+ if (this.root) {
1056
+ stack.push(this.root);
1057
+ }
1058
+
1059
+ while (stack.length > 0) {
1060
+ const tile = stack.pop() as Tile3D;
1061
+
1062
+ for (const child of tile.children) {
1063
+ stack.push(child);
1064
+ }
1065
+
1066
+ this._destroyTile(tile);
1067
+ }
1068
+ this.root = null;
1069
+ }
1070
+
1071
+ _destroySubtree(tile: Tile3D): void {
1072
+ const rootTile = tile;
1073
+ const stack: Tile3D[] = [rootTile];
1074
+ while (stack.length > 0) {
1075
+ tile = stack.pop() as Tile3D;
1076
+ for (const child of tile.children) {
1077
+ stack.push(child);
1078
+ }
1079
+ if (tile !== rootTile) {
1080
+ this._destroyTile(tile);
1081
+ }
1082
+ }
1083
+ rootTile.children = [];
1084
+ }
1085
+
1086
+ _destroyTile(tile: Tile3D): void {
1087
+ this._cache.unloadTile(this, tile);
1088
+ this._unloadTile(tile);
1089
+ tile.destroy();
1090
+ }
1091
+
1092
+ private _syncSourceState(metadata: TilesetSourceMetadata): void {
1093
+ this.tileset = metadata.tileset;
1094
+ this.loader = metadata.loader;
1095
+ this.type = metadata.type;
1096
+ this.url = metadata.url;
1097
+ this.basePath = metadata.basePath;
1098
+ this.lodMetricType = metadata.lodMetricType;
1099
+ this.lodMetricValue = metadata.lodMetricValue;
1100
+ this.refine = metadata.refine;
1101
+ this.contentFormats = this.source.contentFormats;
1102
+ this.asset = this.source.asset || this.asset;
1103
+ const tileset = metadata.tileset as Record<string, any>;
1104
+ this.schema = tileset.schema || null;
1105
+ this.schemaUri = tileset.schemaUri || null;
1106
+ this.groups = tileset.groups || [];
1107
+ this.metadata = tileset.metadata || null;
1108
+ this.statistics = tileset.statistics ?? null;
1109
+ const spatialReference = applyTilesetSpatialOptions(
1110
+ metadata.spatialReference,
1111
+ this.options.spatial
1112
+ );
1113
+ this.spatialReference = preserveTransformedSpatialReference(
1114
+ this.spatialReference,
1115
+ spatialReference
1116
+ );
1117
+ this.properties = this.source.properties ?? this.properties;
1118
+ this.extras = this.source.extras ?? this.extras;
1119
+ if (this.options.attributions?.length) {
1120
+ this.credits = {attributions: this.options.attributions};
1121
+ } else {
1122
+ this.credits = this.source.credits || this.credits;
1123
+ }
1124
+ }
1125
+
1126
+ private _applyViewState(): void {
1127
+ const viewState = this.source.getViewState(this.root);
1128
+ this.asset = viewState.asset || this.source.asset || {};
1129
+ this.properties = viewState.properties ?? this.source.properties;
1130
+ this.extras = viewState.extras ?? this.source.extras ?? null;
1131
+ this.credits = viewState.credits ||
1132
+ this.source.credits ||
1133
+ this.credits || {attributions: this.options.attributions || []};
1134
+ this.description = viewState.description || this.options.description || '';
1135
+ this.boundingVolume = viewState.boundingVolume || this.root?.boundingVolume || null;
1136
+ this.cartographicCenter = viewState.cartographicCenter || new Vector3();
1137
+ this.cartesianCenter = viewState.cartesianCenter || null;
1138
+ this.zoom = viewState.zoom || 1;
1139
+ this.geometricError = this.tileset?.geometricError || 0;
1140
+ }
1141
+
1142
+ /**
1143
+ * Returns normalized source metadata when initialization has already populated it.
1144
+ */
1145
+ private _getSourceMetadata(): TilesetSourceMetadata | null {
1146
+ try {
1147
+ return this.source.getMetadata();
1148
+ } catch {
1149
+ return null;
1150
+ }
1151
+ }
1152
+ }
1153
+
1154
+ /** Preserve a completed runtime operation when asynchronous source metadata describes the same request. */
1155
+ function preserveTransformedSpatialReference(
1156
+ current: TilesetSpatialReference,
1157
+ next: TilesetSpatialReference
1158
+ ): TilesetSpatialReference {
1159
+ return current?.status === 'transformed' &&
1160
+ current.sourceCrs === next.sourceCrs &&
1161
+ current.targetCrs === next.targetCrs &&
1162
+ current.targetHeightReference === next.targetHeightReference &&
1163
+ current.outputCoordinates === next.outputCoordinates
1164
+ ? current
1165
+ : next;
1166
+ }