@loaders.gl/3d-tiles 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (327) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/cesium-ion-loader.d.ts.map +1 -1
  3. package/dist/cesium-ion-loader.js +37 -32
  4. package/dist/dist.min.js +5345 -2938
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/cesium-ion-loader.js +77 -0
  8. package/dist/es5/cesium-ion-loader.js.map +1 -0
  9. package/dist/es5/index.js +63 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js +114 -0
  12. package/dist/es5/lib/classes/helpers/tile-3d-accessor-utils.js.map +1 -0
  13. package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js +180 -0
  14. package/dist/es5/lib/classes/tile-3d-batch-table-hierarchy.js.map +1 -0
  15. package/dist/es5/lib/classes/tile-3d-batch-table.js +285 -0
  16. package/dist/es5/lib/classes/tile-3d-batch-table.js.map +1 -0
  17. package/dist/es5/lib/classes/tile-3d-feature-table.js +97 -0
  18. package/dist/es5/lib/classes/tile-3d-feature-table.js.map +1 -0
  19. package/dist/es5/lib/constants.js +32 -0
  20. package/dist/es5/lib/constants.js.map +1 -0
  21. package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js +49 -0
  22. package/dist/es5/lib/encoders/encode-3d-tile-batched-model.js.map +1 -0
  23. package/dist/es5/lib/encoders/encode-3d-tile-composite.js +30 -0
  24. package/dist/es5/lib/encoders/encode-3d-tile-composite.js.map +1 -0
  25. package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js +47 -0
  26. package/dist/es5/lib/encoders/encode-3d-tile-instanced-model.js.map +1 -0
  27. package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js +48 -0
  28. package/dist/es5/lib/encoders/encode-3d-tile-point-cloud.js.map +1 -0
  29. package/dist/es5/lib/encoders/encode-3d-tile.js +35 -0
  30. package/dist/es5/lib/encoders/encode-3d-tile.js.map +1 -0
  31. package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js +35 -0
  32. package/dist/es5/lib/encoders/helpers/encode-3d-tile-header.js.map +1 -0
  33. package/dist/es5/lib/ion/ion.js +170 -0
  34. package/dist/es5/lib/ion/ion.js.map +1 -0
  35. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js +64 -0
  36. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -0
  37. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js +32 -0
  38. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -0
  39. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js +32 -0
  40. package/dist/es5/lib/parsers/helpers/normalize-3d-tile-positions.js.map +1 -0
  41. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js +280 -0
  42. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -0
  43. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +98 -0
  44. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -0
  45. package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js +22 -0
  46. package/dist/es5/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -0
  47. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js +145 -0
  48. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -0
  49. package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js +85 -0
  50. package/dist/es5/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -0
  51. package/dist/es5/lib/parsers/helpers/parse-utils.js +28 -0
  52. package/dist/es5/lib/parsers/helpers/parse-utils.js.map +1 -0
  53. package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js +51 -0
  54. package/dist/es5/lib/parsers/parse-3d-tile-batched-model.js.map +1 -0
  55. package/dist/es5/lib/parsers/parse-3d-tile-composite.js +48 -0
  56. package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -0
  57. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +37 -0
  58. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -0
  59. package/dist/es5/lib/parsers/parse-3d-tile-header.js +271 -0
  60. package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -0
  61. package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js +172 -0
  62. package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -0
  63. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +271 -0
  64. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -0
  65. package/dist/es5/lib/parsers/parse-3d-tile.js +74 -0
  66. package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -0
  67. package/dist/es5/lib/utils/obb/s2-corners-to-obb.js +30 -0
  68. package/dist/es5/lib/utils/obb/s2-corners-to-obb.js.map +1 -0
  69. package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js +44 -0
  70. package/dist/es5/lib/utils/s2/converters/s2-to-boundary.js.map +1 -0
  71. package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js +30 -0
  72. package/dist/es5/lib/utils/s2/converters/s2-to-obb-points.js.map +1 -0
  73. package/dist/es5/lib/utils/s2/converters/s2-to-region.js +52 -0
  74. package/dist/es5/lib/utils/s2/converters/s2-to-region.js.map +1 -0
  75. package/dist/es5/lib/utils/s2/index.js +90 -0
  76. package/dist/es5/lib/utils/s2/index.js.map +1 -0
  77. package/dist/es5/lib/utils/s2/s2-geometry-functions.js +19 -0
  78. package/dist/es5/lib/utils/s2/s2-geometry-functions.js.map +1 -0
  79. package/dist/es5/lib/utils/s2/s2-token-functions.js +41 -0
  80. package/dist/es5/lib/utils/s2/s2-token-functions.js.map +1 -0
  81. package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js +22 -0
  82. package/dist/es5/lib/utils/s2/s2geometry/s2-cell-utils.js.map +1 -0
  83. package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js +207 -0
  84. package/dist/es5/lib/utils/s2/s2geometry/s2-geometry.js.map +1 -0
  85. package/dist/es5/lib/utils/version.js +9 -0
  86. package/dist/es5/lib/utils/version.js.map +1 -0
  87. package/dist/es5/tile-3d-subtree-loader.js +22 -0
  88. package/dist/es5/tile-3d-subtree-loader.js.map +1 -0
  89. package/dist/es5/tile-3d-writer.js +26 -0
  90. package/dist/es5/tile-3d-writer.js.map +1 -0
  91. package/dist/es5/tiles-3d-loader.js +138 -0
  92. package/dist/es5/tiles-3d-loader.js.map +1 -0
  93. package/dist/es5/types.js +2 -0
  94. package/dist/es5/types.js.map +1 -0
  95. package/dist/esm/bundle.js +4 -0
  96. package/dist/esm/bundle.js.map +1 -0
  97. package/dist/esm/cesium-ion-loader.js +36 -0
  98. package/dist/esm/cesium-ion-loader.js.map +1 -0
  99. package/dist/esm/index.js +9 -0
  100. package/dist/esm/index.js.map +1 -0
  101. package/dist/esm/lib/classes/helpers/tile-3d-accessor-utils.js +96 -0
  102. package/dist/esm/lib/classes/helpers/tile-3d-accessor-utils.js.map +1 -0
  103. package/dist/esm/lib/classes/tile-3d-batch-table-hierarchy.js +171 -0
  104. package/dist/esm/lib/classes/tile-3d-batch-table-hierarchy.js.map +1 -0
  105. package/dist/esm/lib/classes/tile-3d-batch-table.js +231 -0
  106. package/dist/esm/lib/classes/tile-3d-batch-table.js.map +1 -0
  107. package/dist/esm/lib/classes/tile-3d-feature-table.js +70 -0
  108. package/dist/esm/lib/classes/tile-3d-feature-table.js.map +1 -0
  109. package/dist/esm/lib/constants.js +22 -0
  110. package/dist/esm/lib/constants.js.map +1 -0
  111. package/dist/esm/lib/encoders/encode-3d-tile-batched-model.js +40 -0
  112. package/dist/esm/lib/encoders/encode-3d-tile-batched-model.js.map +1 -0
  113. package/dist/esm/lib/encoders/encode-3d-tile-composite.js +21 -0
  114. package/dist/esm/lib/encoders/encode-3d-tile-composite.js.map +1 -0
  115. package/dist/esm/lib/encoders/encode-3d-tile-instanced-model.js +36 -0
  116. package/dist/esm/lib/encoders/encode-3d-tile-instanced-model.js.map +1 -0
  117. package/dist/esm/lib/encoders/encode-3d-tile-point-cloud.js +39 -0
  118. package/dist/esm/lib/encoders/encode-3d-tile-point-cloud.js.map +1 -0
  119. package/dist/esm/lib/encoders/encode-3d-tile.js +29 -0
  120. package/dist/esm/lib/encoders/encode-3d-tile.js.map +1 -0
  121. package/dist/esm/lib/encoders/helpers/encode-3d-tile-header.js +28 -0
  122. package/dist/esm/lib/encoders/helpers/encode-3d-tile-header.js.map +1 -0
  123. package/dist/esm/lib/ion/ion.js +70 -0
  124. package/dist/esm/lib/ion/ion.js.map +1 -0
  125. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js +58 -0
  126. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-colors.js.map +1 -0
  127. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-normals.js +26 -0
  128. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-normals.js.map +1 -0
  129. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-positions.js +26 -0
  130. package/dist/esm/lib/parsers/helpers/normalize-3d-tile-positions.js.map +1 -0
  131. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js +241 -0
  132. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -0
  133. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +61 -0
  134. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -0
  135. package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js +16 -0
  136. package/dist/esm/lib/parsers/helpers/parse-3d-tile-header.js.map +1 -0
  137. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js +67 -0
  138. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -0
  139. package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js +80 -0
  140. package/dist/esm/lib/parsers/helpers/parse-3d-tile-tables.js.map +1 -0
  141. package/dist/esm/lib/parsers/helpers/parse-utils.js +20 -0
  142. package/dist/esm/lib/parsers/helpers/parse-utils.js.map +1 -0
  143. package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js +25 -0
  144. package/dist/esm/lib/parsers/parse-3d-tile-batched-model.js.map +1 -0
  145. package/dist/esm/lib/parsers/parse-3d-tile-composite.js +15 -0
  146. package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -0
  147. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +12 -0
  148. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -0
  149. package/dist/esm/lib/parsers/parse-3d-tile-header.js +164 -0
  150. package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -0
  151. package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js +147 -0
  152. package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -0
  153. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js +211 -0
  154. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -0
  155. package/dist/esm/lib/parsers/parse-3d-tile.js +30 -0
  156. package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -0
  157. package/dist/esm/lib/utils/obb/s2-corners-to-obb.js +23 -0
  158. package/dist/esm/lib/utils/obb/s2-corners-to-obb.js.map +1 -0
  159. package/dist/esm/lib/utils/s2/converters/s2-to-boundary.js +40 -0
  160. package/dist/esm/lib/utils/s2/converters/s2-to-boundary.js.map +1 -0
  161. package/dist/esm/lib/utils/s2/converters/s2-to-obb-points.js +24 -0
  162. package/dist/esm/lib/utils/s2/converters/s2-to-obb-points.js.map +1 -0
  163. package/dist/esm/lib/utils/s2/converters/s2-to-region.js +42 -0
  164. package/dist/esm/lib/utils/s2/converters/s2-to-region.js.map +1 -0
  165. package/dist/esm/lib/utils/s2/index.js +7 -0
  166. package/dist/esm/lib/utils/s2/index.js.map +1 -0
  167. package/dist/esm/lib/utils/s2/s2-geometry-functions.js +12 -0
  168. package/dist/esm/lib/utils/s2/s2-geometry-functions.js.map +1 -0
  169. package/dist/esm/lib/utils/s2/s2-token-functions.js +32 -0
  170. package/dist/esm/lib/utils/s2/s2-token-functions.js.map +1 -0
  171. package/dist/esm/lib/utils/s2/s2geometry/s2-cell-utils.js +15 -0
  172. package/dist/esm/lib/utils/s2/s2geometry/s2-cell-utils.js.map +1 -0
  173. package/dist/esm/lib/utils/s2/s2geometry/s2-geometry.js +186 -0
  174. package/dist/esm/lib/utils/s2/s2geometry/s2-geometry.js.map +1 -0
  175. package/dist/esm/lib/utils/version.js +2 -0
  176. package/dist/esm/lib/utils/version.js.map +1 -0
  177. package/dist/esm/tile-3d-subtree-loader.js +14 -0
  178. package/dist/esm/tile-3d-subtree-loader.js.map +1 -0
  179. package/dist/esm/tile-3d-writer.js +19 -0
  180. package/dist/esm/tile-3d-writer.js.map +1 -0
  181. package/dist/esm/tiles-3d-loader.js +62 -0
  182. package/dist/esm/tiles-3d-loader.js.map +1 -0
  183. package/dist/esm/types.js +2 -0
  184. package/dist/esm/types.js.map +1 -0
  185. package/dist/index.d.ts +1 -1
  186. package/dist/index.d.ts.map +1 -1
  187. package/dist/index.js +26 -9
  188. package/dist/lib/classes/helpers/tile-3d-accessor-utils.d.ts +1 -1
  189. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +106 -89
  190. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +184 -202
  191. package/dist/lib/classes/tile-3d-batch-table.d.ts +1 -1
  192. package/dist/lib/classes/tile-3d-batch-table.js +223 -282
  193. package/dist/lib/classes/tile-3d-feature-table.js +64 -86
  194. package/dist/lib/constants.js +23 -19
  195. package/dist/lib/encoders/encode-3d-tile-batched-model.js +45 -45
  196. package/dist/lib/encoders/encode-3d-tile-composite.js +23 -24
  197. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +37 -37
  198. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +36 -38
  199. package/dist/lib/encoders/encode-3d-tile.js +30 -32
  200. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +28 -29
  201. package/dist/lib/ion/ion.js +60 -69
  202. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +60 -62
  203. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +26 -26
  204. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +39 -28
  205. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +11 -0
  206. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  207. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +247 -203
  208. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  209. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +84 -63
  210. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +26 -15
  211. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +2 -1
  212. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  213. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +98 -58
  214. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +84 -80
  215. package/dist/lib/parsers/helpers/parse-utils.js +29 -16
  216. package/dist/lib/parsers/parse-3d-tile-batched-model.js +30 -26
  217. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +6 -1
  218. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  219. package/dist/lib/parsers/parse-3d-tile-composite.js +23 -16
  220. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +3 -1
  221. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  222. package/dist/lib/parsers/parse-3d-tile-gltf.js +19 -9
  223. package/dist/lib/parsers/parse-3d-tile-header.d.ts +6 -4
  224. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  225. package/dist/lib/parsers/parse-3d-tile-header.js +166 -138
  226. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +3 -1
  227. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  228. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +179 -170
  229. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +4 -2
  230. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  231. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +351 -184
  232. package/dist/lib/parsers/parse-3d-tile.js +36 -31
  233. package/dist/lib/utils/obb/s2-corners-to-obb.d.ts +15 -0
  234. package/dist/lib/utils/obb/s2-corners-to-obb.d.ts.map +1 -0
  235. package/dist/lib/utils/obb/s2-corners-to-obb.js +37 -0
  236. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +9 -0
  237. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -0
  238. package/dist/lib/utils/s2/converters/s2-to-boundary.js +61 -0
  239. package/dist/lib/utils/s2/converters/s2-to-obb-points.d.ts +15 -0
  240. package/dist/lib/utils/s2/converters/s2-to-obb-points.d.ts.map +1 -0
  241. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +36 -0
  242. package/dist/lib/utils/s2/converters/s2-to-region.d.ts +13 -0
  243. package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -0
  244. package/dist/lib/utils/s2/converters/s2-to-region.js +59 -0
  245. package/dist/lib/utils/s2/index.d.ts +8 -0
  246. package/dist/lib/utils/s2/index.d.ts.map +1 -0
  247. package/dist/lib/utils/s2/index.js +23 -0
  248. package/dist/lib/utils/s2/s2-geometry-functions.d.ts +14 -0
  249. package/dist/lib/utils/s2/s2-geometry-functions.d.ts.map +1 -0
  250. package/dist/lib/utils/s2/s2-geometry-functions.js +29 -0
  251. package/dist/lib/utils/s2/s2-token-functions.d.ts +23 -0
  252. package/dist/lib/utils/s2/s2-token-functions.d.ts.map +1 -0
  253. package/dist/lib/utils/s2/s2-token-functions.js +68 -0
  254. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +14 -0
  255. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -0
  256. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +32 -0
  257. package/dist/lib/utils/s2/s2geometry/s2-geometry.d.ts +52 -0
  258. package/dist/lib/utils/s2/s2geometry/s2-geometry.d.ts.map +1 -0
  259. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +260 -0
  260. package/dist/lib/utils/version.js +7 -2
  261. package/dist/tile-3d-subtree-loader.js +22 -13
  262. package/dist/tile-3d-writer.js +24 -17
  263. package/dist/tiles-3d-loader.d.ts +15 -1
  264. package/dist/tiles-3d-loader.d.ts.map +1 -1
  265. package/dist/tiles-3d-loader.js +67 -71
  266. package/dist/types.d.ts +28 -15
  267. package/dist/types.d.ts.map +1 -1
  268. package/dist/types.js +2 -2
  269. package/package.json +12 -11
  270. package/src/cesium-ion-loader.ts +1 -0
  271. package/src/index.ts +1 -1
  272. package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +104 -27
  273. package/src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts +4 -2
  274. package/src/lib/parsers/helpers/parse-3d-tile-subtree.ts +50 -7
  275. package/src/lib/parsers/parse-3d-tile-composite.ts +17 -6
  276. package/src/lib/parsers/parse-3d-tile-gltf.ts +25 -0
  277. package/src/lib/parsers/parse-3d-tile-header.ts +93 -24
  278. package/src/lib/parsers/parse-3d-tile-instanced-model.ts +17 -3
  279. package/src/lib/parsers/parse-3d-tile-point-cloud.ts +37 -10
  280. package/src/lib/utils/obb/s2-corners-to-obb.ts +51 -0
  281. package/src/lib/utils/s2/converters/s2-to-boundary.ts +67 -0
  282. package/src/lib/utils/s2/converters/s2-to-obb-points.ts +46 -0
  283. package/src/lib/utils/s2/converters/s2-to-region.ts +69 -0
  284. package/src/lib/utils/s2/index.ts +17 -0
  285. package/src/lib/utils/s2/s2-geometry-functions.ts +28 -0
  286. package/src/lib/utils/s2/s2-token-functions.ts +67 -0
  287. package/src/lib/utils/s2/s2geometry/s2-cell-utils.ts +33 -0
  288. package/src/lib/utils/s2/s2geometry/s2-geometry.ts +296 -0
  289. package/src/tiles-3d-loader.ts +64 -46
  290. package/src/types.ts +20 -5
  291. package/dist/bundle.js.map +0 -1
  292. package/dist/cesium-ion-loader.js.map +0 -1
  293. package/dist/index.js.map +0 -1
  294. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
  295. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
  296. package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
  297. package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
  298. package/dist/lib/constants.js.map +0 -1
  299. package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
  300. package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
  301. package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
  302. package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
  303. package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
  304. package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
  305. package/dist/lib/ion/ion.js.map +0 -1
  306. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
  307. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
  308. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
  309. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
  310. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
  311. package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
  312. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
  313. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
  314. package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
  315. package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
  316. package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
  317. package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
  318. package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
  319. package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
  320. package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
  321. package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
  322. package/dist/lib/utils/version.js.map +0 -1
  323. package/dist/tile-3d-subtree-loader.js.map +0 -1
  324. package/dist/tile-3d-writer.js.map +0 -1
  325. package/dist/tiles-3d-loader.js.map +0 -1
  326. package/dist/types.js.map +0 -1
  327. package/src/lib/parsers/parse-3d-tile-gltf.js +0 -16
@@ -10,14 +10,28 @@ import Tile3DBatchTable from '../classes/tile-3d-batch-table';
10
10
  import {parse3DTileHeaderSync} from './helpers/parse-3d-tile-header';
11
11
  import {parse3DTileTablesHeaderSync, parse3DTileTablesSync} from './helpers/parse-3d-tile-tables';
12
12
  import {parse3DTileGLTFViewSync, extractGLTF} from './helpers/parse-3d-tile-gltf-view';
13
-
14
- export async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
13
+ import {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
14
+ import {LoaderContext} from '@loaders.gl/loader-utils';
15
+
16
+ export async function parseInstancedModel3DTile(
17
+ tile,
18
+ arrayBuffer: ArrayBuffer,
19
+ byteOffset: number,
20
+ options: Tiles3DLoaderOptions,
21
+ context: LoaderContext
22
+ ): Promise<number> {
15
23
  byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options, context);
16
24
  await extractGLTF(tile, tile.gltfFormat, options, context);
17
25
  return byteOffset;
18
26
  }
19
27
 
20
- function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
28
+ function parseInstancedModel(
29
+ tile,
30
+ arrayBuffer: ArrayBuffer,
31
+ byteOffset: number,
32
+ options: Tiles3DLoaderOptions,
33
+ context: LoaderContext
34
+ ): number {
21
35
  byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
22
36
  if (tile.version !== 1) {
23
37
  throw new Error(`Instanced 3D Model version ${tile.version} is not supported`);
@@ -12,8 +12,16 @@ import {parse3DTileTablesHeaderSync, parse3DTileTablesSync} from './helpers/pars
12
12
  import {normalize3DTileColorAttribute} from './helpers/normalize-3d-tile-colors';
13
13
  import {normalize3DTileNormalAttribute} from './helpers/normalize-3d-tile-normals';
14
14
  import {normalize3DTilePositionAttribute} from './helpers/normalize-3d-tile-positions';
15
-
16
- export async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context) {
15
+ import {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
16
+ import {LoaderContext} from '@loaders.gl/loader-utils';
17
+
18
+ export async function parsePointCloud3DTile(
19
+ tile,
20
+ arrayBuffer: ArrayBuffer,
21
+ byteOffset: number,
22
+ options: Tiles3DLoaderOptions,
23
+ context: LoaderContext
24
+ ): Promise<number> {
17
25
  byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
18
26
  byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
19
27
  byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
@@ -24,13 +32,14 @@ export async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, optio
24
32
  await parseDraco(tile, featureTable, batchTable, options, context);
25
33
 
26
34
  parsePositions(tile, featureTable, options);
35
+ // @ts-expect-error TODO - do we need to assert on the batch table?
27
36
  parseColors(tile, featureTable, batchTable);
28
37
  parseNormals(tile, featureTable);
29
38
 
30
39
  return byteOffset;
31
40
  }
32
41
 
33
- function initializeTile(tile) {
42
+ function initializeTile(tile): void {
34
43
  // Initialize point cloud tile defaults
35
44
  tile.attributes = {
36
45
  positions: null,
@@ -44,7 +53,10 @@ function initializeTile(tile) {
44
53
  tile.isOctEncoded16P = false;
45
54
  }
46
55
 
47
- function parsePointCloudTables(tile) {
56
+ function parsePointCloudTables(tile): {
57
+ featureTable: Tile3DFeatureTable;
58
+ batchTable: Tile3DBatchTable | null;
59
+ } {
48
60
  const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
49
61
 
50
62
  const pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH');
@@ -64,7 +76,11 @@ function parsePointCloudTables(tile) {
64
76
  return {featureTable, batchTable};
65
77
  }
66
78
 
67
- function parsePositions(tile, featureTable, options) {
79
+ function parsePositions(
80
+ tile,
81
+ featureTable: Tile3DFeatureTable,
82
+ options: Tiles3DLoaderOptions
83
+ ): void {
68
84
  if (!tile.attributes.positions) {
69
85
  if (featureTable.hasProperty('POSITION')) {
70
86
  tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL.FLOAT, 3);
@@ -101,7 +117,7 @@ function parsePositions(tile, featureTable, options) {
101
117
  }
102
118
  }
103
119
 
104
- function parseColors(tile, featureTable, batchTable) {
120
+ function parseColors(tile, featureTable: Tile3DFeatureTable, batchTable: Tile3DBatchTable): void {
105
121
  if (!tile.attributes.colors) {
106
122
  let colors = null;
107
123
  if (featureTable.hasProperty('RGBA')) {
@@ -122,7 +138,7 @@ function parseColors(tile, featureTable, batchTable) {
122
138
  }
123
139
  }
124
140
 
125
- function parseNormals(tile, featureTable) {
141
+ function parseNormals(tile, featureTable: Tile3DFeatureTable): void {
126
142
  if (!tile.attributes.normals) {
127
143
  let normals = null;
128
144
  if (featureTable.hasProperty('NORMAL')) {
@@ -136,7 +152,7 @@ function parseNormals(tile, featureTable) {
136
152
  }
137
153
  }
138
154
 
139
- function parseBatchIds(tile, featureTable) {
155
+ function parseBatchIds(tile, featureTable: Tile3DFeatureTable): Tile3DBatchTable | null {
140
156
  let batchTable: Tile3DBatchTable | null = null;
141
157
  if (!tile.batchIds && featureTable.hasProperty('BATCH_ID')) {
142
158
  tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL.UNSIGNED_SHORT, 1);
@@ -154,7 +170,13 @@ function parseBatchIds(tile, featureTable) {
154
170
  }
155
171
 
156
172
  // eslint-disable-next-line complexity
157
- async function parseDraco(tile, featureTable, batchTable, options, context) {
173
+ async function parseDraco(
174
+ tile,
175
+ featureTable: Tile3DFeatureTable,
176
+ batchTable,
177
+ options: Tiles3DLoaderOptions,
178
+ context: LoaderContext
179
+ ) {
158
180
  let dracoBuffer;
159
181
  let dracoFeatureTableProperties;
160
182
  let dracoBatchTableProperties;
@@ -202,7 +224,12 @@ async function parseDraco(tile, featureTable, batchTable, options, context) {
202
224
  }
203
225
 
204
226
  // eslint-disable-next-line complexity, max-statements
205
- export async function loadDraco(tile, dracoData, options, context) {
227
+ export async function loadDraco(
228
+ tile,
229
+ dracoData,
230
+ options: Tiles3DLoaderOptions,
231
+ context: LoaderContext
232
+ ) {
206
233
  const {parse} = context;
207
234
  const dracoOptions = {
208
235
  ...options,
@@ -0,0 +1,51 @@
1
+ import {Vector3} from '@math.gl/core';
2
+ import {OrientedBoundingBox, makeOrientedBoundingBoxFromPoints} from '@math.gl/culling';
3
+
4
+ import type {S2HeightInfo} from '../../utils/s2/index';
5
+ import {getS2OrientedBoundingBoxCornerPoints} from '../../utils/s2/index';
6
+
7
+ import {getS2LngLat} from '../../utils/s2/index';
8
+ import {Ellipsoid} from '@math.gl/geospatial';
9
+
10
+ export type S2VolumeInfo = {
11
+ /** S2 key or token */
12
+ token: string;
13
+ /** minimum height in meters */
14
+ minimumHeight: number;
15
+ /** maximum height in meters */
16
+ maximumHeight: number;
17
+ };
18
+
19
+ /**
20
+ * Converts S2VolumeInfo to OrientedBoundingBox
21
+ * @param {S2VolumeInfo} s2VolumeInfo - s2 volume to convert
22
+ * @returns Oriented Bounding Box of type Box
23
+ */
24
+ export function convertS2BoundingVolumetoOBB(s2VolumeInfo: S2VolumeInfo): number[] {
25
+ const token: string = s2VolumeInfo.token;
26
+ const heightInfo: S2HeightInfo = {
27
+ minimumHeight: s2VolumeInfo.minimumHeight,
28
+ maximumHeight: s2VolumeInfo.maximumHeight
29
+ };
30
+
31
+ const corners: Vector3[] = getS2OrientedBoundingBoxCornerPoints(token, heightInfo);
32
+
33
+ // Add a point that doesn't allow the box dive under the Earth
34
+
35
+ const center = getS2LngLat(token);
36
+ const centerLng: number = center[0];
37
+ const centerLat: number = center[1];
38
+ const point = Ellipsoid.WGS84.cartographicToCartesian([
39
+ centerLng,
40
+ centerLat,
41
+ heightInfo.maximumHeight
42
+ ]);
43
+ const centerPointAdditional = new Vector3(point[0], point[1], point[2]);
44
+ corners.push(centerPointAdditional);
45
+
46
+ // corners should be an array of Vector3 (XYZ)
47
+ const obb: OrientedBoundingBox = makeOrientedBoundingBoxFromPoints(corners);
48
+ const box: number[] = [...obb.center, ...obb.halfAxes];
49
+
50
+ return box;
51
+ }
@@ -0,0 +1,67 @@
1
+ import type {S2Cell} from '../s2geometry/s2-geometry';
2
+ import {IJToST, STToUV, FaceUVToXYZ, XYZToLngLat} from '../s2geometry/s2-geometry';
3
+
4
+ const MAX_RESOLUTION = 100;
5
+
6
+ /**
7
+ * Get a polygon with corner coordinates for an S2 cell
8
+ * @param s2cell {S2Cell} S2 cell
9
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
10
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
11
+ */
12
+ // eslint-disable-next-line max-statements
13
+ export function getS2BoundaryFlatFromS2Cell(s2cell: S2Cell): Float64Array {
14
+ const {face, ij, level} = s2cell;
15
+ const offsets = [
16
+ [0, 0],
17
+ [0, 1],
18
+ [1, 1],
19
+ [1, 0],
20
+ [0, 0]
21
+ ];
22
+
23
+ // The S2 cell edge is curved: http://s2geometry.io/
24
+ // This is more prominent at lower levels
25
+ // resolution is the number of segments to generate per edge.
26
+ // We exponentially reduce resolution as level increases so it doesn't affect perf
27
+ // when there are a large number of cells
28
+ const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
29
+ const result = new Float64Array(4 * resolution * 2 + 2);
30
+ let ptIndex = 0;
31
+ let prevLng = 0;
32
+
33
+ for (let i = 0; i < 4; i++) {
34
+ const offset = offsets[i].slice(0) as [number, number];
35
+ const nextOffset = offsets[i + 1];
36
+ const stepI = (nextOffset[0] - offset[0]) / resolution;
37
+ const stepJ = (nextOffset[1] - offset[1]) / resolution;
38
+
39
+ for (let j = 0; j < resolution; j++) {
40
+ offset[0] += stepI;
41
+ offset[1] += stepJ;
42
+ // Cell can be represented by coordinates IJ, ST, UV, XYZ
43
+ // http://s2geometry.io/devguide/s2cell_hierarchy#coordinate-systems
44
+ const st = IJToST(ij, level, offset);
45
+ const uv = STToUV(st);
46
+ const xyz = FaceUVToXYZ(face, uv);
47
+ const lngLat = XYZToLngLat(xyz);
48
+
49
+ // Adjust longitude for Web Mercator projection
50
+
51
+ if (Math.abs(lngLat[1]) > 89.999) {
52
+ lngLat[0] = prevLng;
53
+ }
54
+
55
+ const deltaLng = lngLat[0] - prevLng;
56
+ lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
57
+
58
+ result[ptIndex++] = lngLat[0];
59
+ result[ptIndex++] = lngLat[1];
60
+ prevLng = lngLat[0];
61
+ }
62
+ }
63
+ // close the loop
64
+ result[ptIndex++] = result[0];
65
+ result[ptIndex++] = result[1];
66
+ return result;
67
+ }
@@ -0,0 +1,46 @@
1
+ import {getS2Cell} from '../s2geometry/s2-cell-utils';
2
+ import {getS2Region} from './s2-to-region';
3
+ import {Vector3} from '@math.gl/core';
4
+
5
+ export type S2HeightInfo = {
6
+ minimumHeight: number;
7
+ maximumHeight: number;
8
+ };
9
+
10
+ /**
11
+ * Converts S2HeightInfo to corner points of an oriented bounding box
12
+ * Can be used to constuct an OrientedBoundingBox instance
13
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
14
+ * @param heightInfo {S2HeightInfo} min and max height of the box
15
+ * @returns corner points of the oriented bounding box
16
+ */
17
+ export function getS2OrientedBoundingBoxCornerPoints(
18
+ tokenOrKey: string, // This can be an S2 key or token
19
+ heightInfo?: S2HeightInfo
20
+ ): Vector3[] {
21
+ const min: number = heightInfo?.minimumHeight || 0;
22
+ const max: number = heightInfo?.maximumHeight || 0;
23
+
24
+ const s2cell = getS2Cell(tokenOrKey);
25
+ const region = getS2Region(s2cell);
26
+
27
+ // region lng/lat are in degrees
28
+ const W = region.west;
29
+ const S = region.south;
30
+ const E = region.east;
31
+ const N = region.north;
32
+
33
+ const points: Vector3[] = [];
34
+
35
+ points.push(new Vector3(W, N, min));
36
+ points.push(new Vector3(E, N, min));
37
+ points.push(new Vector3(E, S, min));
38
+ points.push(new Vector3(W, S, min));
39
+
40
+ points.push(new Vector3(W, N, max));
41
+ points.push(new Vector3(E, N, max));
42
+ points.push(new Vector3(E, S, max));
43
+ points.push(new Vector3(W, S, max));
44
+
45
+ return points;
46
+ }
@@ -0,0 +1,69 @@
1
+ import type {S2Cell} from '../s2geometry/s2-geometry';
2
+ import {getS2BoundaryFlatFromS2Cell} from './s2-to-boundary';
3
+ import {getS2Cell} from '../s2geometry/s2-cell-utils';
4
+
5
+ /**
6
+ * Converts S2 cell to the 2D region
7
+ * @param s2cell {S2Cell} S2 cell to convert to 2D region
8
+ * @returns 2D region as an object containing: west, north, east, south in degrees
9
+ */
10
+ export function getS2Region(s2cell: S2Cell): {
11
+ west: number;
12
+ east: number;
13
+ north: number;
14
+ south: number;
15
+ } {
16
+ let region;
17
+ if (s2cell.face === 2 || s2cell.face === 5) {
18
+ // let corners: Float64Array;
19
+ let corners: any = null;
20
+ let len = 0;
21
+ for (let i = 0; i < 4; i++) {
22
+ const key = `${s2cell.face}/${i}`;
23
+ const cell = getS2Cell(key);
24
+ const corns: Float64Array = getS2BoundaryFlatFromS2Cell(cell);
25
+ if (typeof corners === 'undefined' || corners === null)
26
+ corners = new Float64Array(4 * corns.length);
27
+ corners.set(corns, len);
28
+ len += corns.length;
29
+ }
30
+ region = get2DRegionFromS2Corners(corners);
31
+ } else {
32
+ const corners: Float64Array = getS2BoundaryFlatFromS2Cell(s2cell);
33
+ region = get2DRegionFromS2Corners(corners);
34
+ }
35
+ return region;
36
+ }
37
+
38
+ /**
39
+ * Converts the S2 cell defined by its corners to the 2D region
40
+ * @param corners {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
41
+ * @returns 2D region as an object containing: west, north, east, south in degrees
42
+ */
43
+ function get2DRegionFromS2Corners(corners: Float64Array): {
44
+ west: number;
45
+ east: number;
46
+ north: number;
47
+ south: number;
48
+ } {
49
+ if (corners.length % 2 !== 0) {
50
+ throw new Error('Invalid corners');
51
+ }
52
+ const longitudes: number[] = [];
53
+ const latitudes: number[] = [];
54
+ for (let i = 0; i < corners.length; i += 2) {
55
+ longitudes.push(corners[i]);
56
+ latitudes.push(corners[i + 1]);
57
+ }
58
+
59
+ longitudes.sort((a, b) => a - b);
60
+ latitudes.sort((a, b) => a - b);
61
+
62
+ // Return the region in degrees
63
+ return {
64
+ west: longitudes[0],
65
+ east: longitudes[longitudes.length - 1],
66
+ north: latitudes[latitudes.length - 1],
67
+ south: latitudes[0]
68
+ };
69
+ }
@@ -0,0 +1,17 @@
1
+ // math.gl MIT license
2
+
3
+ export {getS2CellIdFromToken, getS2TokenFromCellId, getS2ChildCellId} from './s2-token-functions';
4
+ export {getS2BoundaryFlat, getS2LngLat} from './s2-geometry-functions';
5
+
6
+ export {getS2Cell, getS2QuadKey} from './s2geometry/s2-cell-utils';
7
+ export {
8
+ getS2QuadkeyFromCellId,
9
+ getS2CellFromQuadKey,
10
+ getS2CellIdFromQuadkey,
11
+ getS2LngLatFromS2Cell
12
+ } from './s2geometry/s2-geometry';
13
+
14
+ export {getS2Region} from './converters/s2-to-region';
15
+
16
+ export type {S2HeightInfo} from './converters/s2-to-obb-points';
17
+ export {getS2OrientedBoundingBoxCornerPoints} from './converters/s2-to-obb-points';
@@ -0,0 +1,28 @@
1
+ // math.gl, MIT license
2
+
3
+ import {getS2BoundaryFlatFromS2Cell} from './converters/s2-to-boundary';
4
+ import {getS2LngLatFromS2Cell} from './s2geometry/s2-geometry';
5
+ import {getS2Cell} from './s2geometry/s2-cell-utils';
6
+
7
+ // GEOMETRY
8
+
9
+ /**
10
+ * Retrieve S2 geometry center
11
+ * @param s2Token {string} A string that is the cell's hex token
12
+ * @returns {[number, number]} Longitude and Latitude coordinates of the S2 cell's center
13
+ */
14
+ export function getS2LngLat(s2Token: string): [number, number] {
15
+ const s2cell = getS2Cell(s2Token);
16
+ return getS2LngLatFromS2Cell(s2cell);
17
+ }
18
+
19
+ /**
20
+ * Get a polygon with corner coordinates for an s2 cell
21
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
22
+ * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
23
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
24
+ */
25
+ export function getS2BoundaryFlat(tokenOrKey: string): Float64Array {
26
+ const s2cell = getS2Cell(tokenOrKey);
27
+ return getS2BoundaryFlatFromS2Cell(s2cell);
28
+ }
@@ -0,0 +1,67 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import Long from 'long';
4
+
5
+ const MAXIMUM_TOKEN_LENGTH = 16;
6
+
7
+ /**
8
+ * Convert the S2 token to the S2 cell ID
9
+ * @param token {string} A string that is the cell's hex token. Zero cell ID is represented as 'X'.
10
+ * @returns {Long} Cell id that is a 64-bit encoding of a face and a Hilbert curve parameter on that face.
11
+ * See {@link https://github.com/google/s2-geometry-library-java/blob/c04b68bf3197a9c34082327eeb3aec7ab7c85da1/src/com/google/common/geometry/S2CellId.java#L439} for more information
12
+ */
13
+ export function getS2CellIdFromToken(token: string): Long {
14
+ if (token === 'X') {
15
+ token = '';
16
+ }
17
+ // pad token with zeros to make the length 16 that is defined in MAXIMUM_TOKEN_LENGTH
18
+ const paddedToken = token.padEnd(MAXIMUM_TOKEN_LENGTH, '0');
19
+ return Long.fromString(paddedToken, true, 16); // Hex base
20
+ }
21
+
22
+ /**
23
+ * Convert the S2 cell ID to the S2 token
24
+ * @param cellId {Long} A 64-bit encoding of a face and a Hilbert curve parameter on that face.
25
+ * @returns {string} A string that is the cell's hex token. Zero cell ID is represented as 'X'.
26
+ */
27
+ export function getS2TokenFromCellId(cellId: Long): string {
28
+ if (cellId.isZero()) {
29
+ return 'X';
30
+ }
31
+ let numZeroDigits = cellId.countTrailingZeros();
32
+
33
+ const remainder = numZeroDigits % 4;
34
+ numZeroDigits = (numZeroDigits - remainder) / 4;
35
+ const trailingZeroHexChars = numZeroDigits;
36
+ numZeroDigits *= 4;
37
+
38
+ const x = cellId.shiftRightUnsigned(numZeroDigits);
39
+ const hexString = x.toString(16).replace(/0+$/, '');
40
+ const zeroString = Array(17 - trailingZeroHexChars - hexString.length).join('0');
41
+ return zeroString + hexString;
42
+ }
43
+
44
+ /**
45
+ * Get one of four S2 cell's children.
46
+ * @param cellId {Long} A 64-bit encoding of a face and a Hilbert curve parameter on that face.
47
+ * The cell must NOT be a leaf one. So, the cell's level is in the range [0-29].
48
+ * @param index {number} Child index defines one of four S2 cell's children. Must be in the range [0-3].
49
+ * @returns The ID of the cell's child.
50
+ */
51
+ export function getS2ChildCellId(cellId: Long, index: number): Long {
52
+ // Shift sentinel bit 2 positions to the right.
53
+ const newLsb = lsb(cellId).shiftRightUnsigned(2);
54
+ // Insert child index before the sentinel bit.
55
+ const childCellId: Long = cellId.add(Long.fromNumber(2 * index + 1 - 4).multiply(newLsb));
56
+ return childCellId;
57
+ }
58
+
59
+ /**
60
+ * Return the lowest-numbered bit that is on for this cell id.
61
+ * @private
62
+ * @param cellId {Long} Cell id.
63
+ * @returns {Long} The lowest-numbered bit that is on for this cell id.
64
+ */
65
+ function lsb(cellId: Long): Long {
66
+ return cellId.and(cellId.not().add(1)); // eslint-disable-line
67
+ }
@@ -0,0 +1,33 @@
1
+ // math.gl, MIT license
2
+
3
+ import type {S2Cell} from './s2-geometry';
4
+ import {getS2CellFromQuadKey, getS2QuadkeyFromCellId} from './s2-geometry';
5
+ import {getS2CellIdFromToken} from '../s2-token-functions';
6
+
7
+ import Long from 'long';
8
+
9
+ /**
10
+ * Return the S2Cell from the cell's hex token or the Hilbert quad key
11
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
12
+ * @returns {@link S2Cell}
13
+ */
14
+ export function getS2Cell(tokenOrKey: string): S2Cell {
15
+ const key = getS2QuadKey(tokenOrKey);
16
+ const s2cell = getS2CellFromQuadKey(key);
17
+ return s2cell;
18
+ }
19
+
20
+ /**
21
+ * Get the underlying Hilbert quad key
22
+ * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
23
+ * @returns Hilbert quad key
24
+ */
25
+ export function getS2QuadKey(tokenOrKey: string): string {
26
+ if (tokenOrKey.indexOf('/') > 0) {
27
+ // is Hilbert quad key
28
+ return tokenOrKey;
29
+ }
30
+ // is S2 cell's hex token
31
+ const id: Long = getS2CellIdFromToken(tokenOrKey);
32
+ return getS2QuadkeyFromCellId(id);
33
+ }