@hztxi/cesium-engine 25.0.7 → 26.2.2

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 (471) hide show
  1. package/Build/Workers/chunk-2FNKHQL3.js +754 -0
  2. package/Build/Workers/chunk-2NCNUVAT.js +56 -0
  3. package/Build/Workers/chunk-2ZYRUVVU.js +301 -0
  4. package/Build/Workers/chunk-36IU7N4V.js +1284 -0
  5. package/Build/Workers/chunk-3BDLET5S.js +198 -0
  6. package/Build/Workers/chunk-3JZXI44G.js +3822 -0
  7. package/Build/Workers/chunk-3N2UNLWJ.js +101 -0
  8. package/Build/Workers/chunk-3NCG2YYR.js +58 -0
  9. package/Build/Workers/chunk-3PRHI4KX.js +241 -0
  10. package/Build/Workers/chunk-3R6E2SH4.js +672 -0
  11. package/Build/Workers/chunk-3ZKKXEXL.js +415 -0
  12. package/Build/Workers/chunk-47KVKPTO.js +415 -0
  13. package/Build/Workers/chunk-4FFIJ7ZV.js +56 -0
  14. package/Build/Workers/chunk-4N227IPR.js +973 -0
  15. package/Build/Workers/chunk-4P6OAPBM.js +97 -0
  16. package/Build/Workers/chunk-4XR3K4GD.js +280 -0
  17. package/Build/Workers/chunk-4Z2JINRS.js +519 -0
  18. package/Build/Workers/chunk-4ZOLEPZK.js +519 -0
  19. package/Build/Workers/chunk-5EF3WWQG.js +352 -0
  20. package/Build/Workers/chunk-5I76476T.js +288 -0
  21. package/Build/Workers/chunk-5PBZKBAP.js +511 -0
  22. package/Build/Workers/chunk-5RVAAW26.js +82 -0
  23. package/Build/Workers/chunk-5VWK76PO.js +511 -0
  24. package/Build/Workers/chunk-6SEICASZ.js +241 -0
  25. package/Build/Workers/chunk-77DBX23X.js +455 -0
  26. package/Build/Workers/chunk-7C2D3DTI.js +959 -0
  27. package/Build/Workers/chunk-7GQOWCSN.js +959 -0
  28. package/Build/Workers/chunk-7J2ONMKC.js +198 -0
  29. package/Build/Workers/chunk-7MHUHXZZ.js +219 -0
  30. package/Build/Workers/chunk-7MQPHOAS.js +455 -0
  31. package/Build/Workers/chunk-7NJ5O7TP.js +387 -0
  32. package/Build/Workers/chunk-7T4MW2W4.js +368 -0
  33. package/Build/Workers/chunk-7UXZUGUZ.js +82 -0
  34. package/Build/Workers/chunk-7Y642MCO.js +352 -0
  35. package/Build/Workers/chunk-7ZFKBLUE.js +1054 -0
  36. package/Build/Workers/chunk-A2UHPWPL.js +38 -0
  37. package/Build/Workers/chunk-A7LGY5XS.js +140 -0
  38. package/Build/Workers/chunk-AN2NVYL6.js +1483 -0
  39. package/Build/Workers/chunk-AS2QC7H2.js +219 -0
  40. package/Build/Workers/chunk-AVOLMIGJ.js +57 -0
  41. package/Build/Workers/chunk-B7PT2VL5.js +630 -0
  42. package/Build/Workers/chunk-BHRHMUDM.js +147 -0
  43. package/Build/Workers/chunk-BUWAHRK5.js +672 -0
  44. package/Build/Workers/chunk-C5ET5HON.js +198 -0
  45. package/Build/Workers/chunk-C6XQGBPV.js +476 -0
  46. package/Build/Workers/chunk-C7B672RR.js +73 -0
  47. package/Build/Workers/chunk-CAEC5DA2.js +57 -0
  48. package/Build/Workers/chunk-CBCOHH5O.js +837 -0
  49. package/Build/Workers/chunk-CEMXKBQO.js +1800 -0
  50. package/Build/Workers/chunk-CKW3STKA.js +1067 -0
  51. package/Build/Workers/chunk-CV5RICKT.js +1992 -0
  52. package/Build/Workers/chunk-DBWSISJT.js +56 -0
  53. package/Build/Workers/chunk-DCMOBPLG.js +352 -0
  54. package/Build/Workers/chunk-DSBSPPPJ.js +1344 -0
  55. package/Build/Workers/chunk-DSGLDRTI.js +278 -0
  56. package/Build/Workers/chunk-DXD7OPSP.js +1992 -0
  57. package/Build/Workers/chunk-DXECZBSA.js +368 -0
  58. package/Build/Workers/chunk-DZIRO6ZK.js +682 -0
  59. package/Build/Workers/chunk-E4CRPGX5.js +140 -0
  60. package/Build/Workers/chunk-E4IVMEBH.js +52 -0
  61. package/Build/Workers/chunk-E6IPM6HP.js +56 -0
  62. package/Build/Workers/chunk-EB2HAHRY.js +1054 -0
  63. package/Build/Workers/chunk-ECDCQXCO.js +1992 -0
  64. package/Build/Workers/chunk-ECN3VUMA.js +73 -0
  65. package/Build/Workers/chunk-ECSKVHUB.js +476 -0
  66. package/Build/Workers/chunk-EIENGLA5.js +278 -0
  67. package/Build/Workers/chunk-EK5CWDW2.js +476 -0
  68. package/Build/Workers/chunk-EL4B5CSQ.js +162 -0
  69. package/Build/Workers/chunk-EUCUBIEZ.js +97 -0
  70. package/Build/Workers/chunk-FAYBQGKO.js +219 -0
  71. package/Build/Workers/chunk-FGCXPEZM.js +3201 -0
  72. package/Build/Workers/chunk-FHCRXPA6.js +44 -0
  73. package/Build/Workers/chunk-FM6EQUFX.js +1800 -0
  74. package/Build/Workers/chunk-FPFGGQ4X.js +301 -0
  75. package/Build/Workers/chunk-FQ42MT7M.js +58 -0
  76. package/Build/Workers/chunk-FQDYQG4P.js +1284 -0
  77. package/Build/Workers/chunk-FQTV6W3I.js +973 -0
  78. package/Build/Workers/chunk-FTCBY5HH.js +138 -0
  79. package/Build/Workers/chunk-GI5RWJAY.js +101 -0
  80. package/Build/Workers/chunk-GNLMSDRO.js +945 -0
  81. package/Build/Workers/chunk-GTA727KQ.js +140 -0
  82. package/Build/Workers/chunk-GVUJ6O3R.js +73 -0
  83. package/Build/Workers/chunk-GXTM7AG3.js +1483 -0
  84. package/Build/Workers/chunk-HAXQB2FS.js +2719 -0
  85. package/Build/Workers/chunk-HCGU7OCG.js +97 -0
  86. package/Build/Workers/chunk-HRIPVWSC.js +58 -0
  87. package/Build/Workers/chunk-IC3BR6SC.js +102 -0
  88. package/Build/Workers/chunk-IEPPOHF3.js +44 -0
  89. package/Build/Workers/chunk-IU3YAYPT.js +1344 -0
  90. package/Build/Workers/chunk-J3AXZ4WC.js +124 -0
  91. package/Build/Workers/chunk-J7MZR7B2.js +1483 -0
  92. package/Build/Workers/chunk-KBNW776Q.js +305 -0
  93. package/Build/Workers/chunk-KBSWXVSY.js +837 -0
  94. package/Build/Workers/chunk-KEYTLNVK.js +1067 -0
  95. package/Build/Workers/chunk-KN3RQWUA.js +3201 -0
  96. package/Build/Workers/chunk-KSIEJYNL.js +3822 -0
  97. package/Build/Workers/chunk-KT3GG7AW.js +754 -0
  98. package/Build/Workers/chunk-KYCEM22I.js +1800 -0
  99. package/Build/Workers/chunk-L2TFZKN6.js +455 -0
  100. package/Build/Workers/chunk-LHKE2VUR.js +945 -0
  101. package/Build/Workers/chunk-LJTQW46H.js +57 -0
  102. package/Build/Workers/chunk-LMQGYJME.js +672 -0
  103. package/Build/Workers/chunk-LOBYJQA4.js +76 -0
  104. package/Build/Workers/chunk-LOF32O7F.js +163 -0
  105. package/Build/Workers/chunk-LOTIJA7D.js +124 -0
  106. package/Build/Workers/chunk-M7Z3MPAX.js +973 -0
  107. package/Build/Workers/chunk-MHNLTQHO.js +3201 -0
  108. package/Build/Workers/chunk-MICPAD7R.js +398 -0
  109. package/Build/Workers/chunk-ML7OMD72.js +2342 -0
  110. package/Build/Workers/chunk-MPJ73WMH.js +138 -0
  111. package/Build/Workers/chunk-MUTHG7T7.js +171 -0
  112. package/Build/Workers/chunk-NBTGXEMT.js +945 -0
  113. package/Build/Workers/chunk-NQZC37F7.js +38 -0
  114. package/Build/Workers/chunk-O3X3D2Z3.js +352 -0
  115. package/Build/Workers/chunk-OBUIHPKF.js +352 -0
  116. package/Build/Workers/chunk-PAEWNYIV.js +138 -0
  117. package/Build/Workers/chunk-PANJ7YH6.js +102 -0
  118. package/Build/Workers/chunk-PCL3Y7H5.js +82 -0
  119. package/Build/Workers/chunk-PHUELDXQ.js +76 -0
  120. package/Build/Workers/chunk-PIIUGRQD.js +387 -0
  121. package/Build/Workers/chunk-POKD22OT.js +2719 -0
  122. package/Build/Workers/chunk-PQMA7MFS.js +9237 -0
  123. package/Build/Workers/chunk-PQZW2QZG.js +163 -0
  124. package/Build/Workers/chunk-PURIPUSY.js +682 -0
  125. package/Build/Workers/chunk-QQZPPXY4.js +3822 -0
  126. package/Build/Workers/chunk-QXLQLGL2.js +1067 -0
  127. package/Build/Workers/chunk-R2JQAAU7.js +630 -0
  128. package/Build/Workers/chunk-RC4YC3VU.js +278 -0
  129. package/Build/Workers/chunk-RGNNWVR6.js +171 -0
  130. package/Build/Workers/chunk-RUOETBWP.js +288 -0
  131. package/Build/Workers/chunk-RV4EPLBO.js +2342 -0
  132. package/Build/Workers/chunk-SBBIEHYT.js +44 -0
  133. package/Build/Workers/chunk-SBEQLEO5.js +352 -0
  134. package/Build/Workers/chunk-SGC2GT3Y.js +1284 -0
  135. package/Build/Workers/chunk-SKLK4CBL.js +162 -0
  136. package/Build/Workers/chunk-SWVZTU6X.js +305 -0
  137. package/Build/Workers/chunk-T3EUPM5A.js +454 -0
  138. package/Build/Workers/chunk-TA6IU2XL.js +171 -0
  139. package/Build/Workers/chunk-TLSGD5TR.js +280 -0
  140. package/Build/Workers/chunk-TNDQT5AB.js +682 -0
  141. package/Build/Workers/chunk-TOXDLWKZ.js +368 -0
  142. package/Build/Workers/chunk-TZBM6TAB.js +124 -0
  143. package/Build/Workers/chunk-U2OY6MX6.js +398 -0
  144. package/Build/Workers/chunk-UCY4B5EV.js +288 -0
  145. package/Build/Workers/chunk-V52FEPCV.js +754 -0
  146. package/Build/Workers/chunk-VBEXZBG5.js +147 -0
  147. package/Build/Workers/chunk-VC76B6GM.js +959 -0
  148. package/Build/Workers/chunk-VCUOYHWC.js +519 -0
  149. package/Build/Workers/chunk-VDBQVKTF.js +387 -0
  150. package/Build/Workers/chunk-VJIL5H6K.js +2719 -0
  151. package/Build/Workers/chunk-VJLDRHKN.js +511 -0
  152. package/Build/Workers/chunk-VMF7KOGY.js +162 -0
  153. package/Build/Workers/chunk-W3X2ZAEJ.js +52 -0
  154. package/Build/Workers/chunk-W5OCKMPJ.js +101 -0
  155. package/Build/Workers/chunk-X4VZ33YL.js +454 -0
  156. package/Build/Workers/chunk-XDM5A6C4.js +102 -0
  157. package/Build/Workers/chunk-XHT5SVP4.js +52 -0
  158. package/Build/Workers/chunk-XITBARMZ.js +2342 -0
  159. package/Build/Workers/chunk-XLQZNQ4Z.js +163 -0
  160. package/Build/Workers/chunk-XZ6HDXKM.js +76 -0
  161. package/Build/Workers/chunk-Y6AQK4FY.js +1344 -0
  162. package/Build/Workers/chunk-Y7NDFEQ3.js +398 -0
  163. package/Build/Workers/chunk-YBBQDYX2.js +301 -0
  164. package/Build/Workers/chunk-YHPYPVAB.js +837 -0
  165. package/Build/Workers/chunk-YJBPRW4A.js +415 -0
  166. package/Build/Workers/chunk-YNKK6BXY.js +454 -0
  167. package/Build/Workers/chunk-YRAJ74HR.js +305 -0
  168. package/Build/Workers/chunk-YULTZK5O.js +147 -0
  169. package/Build/Workers/chunk-YUNQYP3Z.js +9237 -0
  170. package/Build/Workers/chunk-YX2FOQMF.js +9237 -0
  171. package/Build/Workers/chunk-Z7BONRW2.js +241 -0
  172. package/Build/Workers/chunk-ZK2R3DEJ.js +1054 -0
  173. package/Build/Workers/combineGeometry.js +24 -24
  174. package/Build/Workers/createBoxGeometry.js +18 -18
  175. package/Build/Workers/createBoxOutlineGeometry.js +18 -18
  176. package/Build/Workers/createCircleGeometry.js +26 -26
  177. package/Build/Workers/createCircleOutlineGeometry.js +19 -19
  178. package/Build/Workers/createCoplanarPolygonGeometry.js +39 -39
  179. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +33 -33
  180. package/Build/Workers/createCorridorGeometry.js +36 -37
  181. package/Build/Workers/createCorridorOutlineGeometry.js +34 -35
  182. package/Build/Workers/createCylinderGeometry.js +20 -20
  183. package/Build/Workers/createCylinderOutlineGeometry.js +20 -20
  184. package/Build/Workers/createEllipseGeometry.js +26 -26
  185. package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
  186. package/Build/Workers/createEllipsoidGeometry.js +19 -19
  187. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
  188. package/Build/Workers/createFrustumGeometry.js +18 -18
  189. package/Build/Workers/createFrustumOutlineGeometry.js +20 -20
  190. package/Build/Workers/createGeometry.js +25 -24
  191. package/Build/Workers/createGroundPolylineGeometry.js +26 -26
  192. package/Build/Workers/createMvtTile.js +111 -19
  193. package/Build/Workers/createPlaneGeometry.js +18 -18
  194. package/Build/Workers/createPlaneOutlineGeometry.js +17 -17
  195. package/Build/Workers/createPolygonGeometry.js +36 -36
  196. package/Build/Workers/createPolygonOutlineGeometry.js +33 -33
  197. package/Build/Workers/createPolylineGeometry.js +28 -28
  198. package/Build/Workers/createPolylineVolumeGeometry.js +38 -36
  199. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +32 -31
  200. package/Build/Workers/createRectangleGeometry.js +29 -29
  201. package/Build/Workers/createRectangleOutlineGeometry.js +23 -23
  202. package/Build/Workers/createSimplePolylineGeometry.js +26 -26
  203. package/Build/Workers/createSphereGeometry.js +19 -19
  204. package/Build/Workers/createSphereOutlineGeometry.js +18 -18
  205. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  206. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  207. package/Build/Workers/createVectorTileGeometries.js +24 -24
  208. package/Build/Workers/createVectorTilePoints.js +13 -13
  209. package/Build/Workers/createVectorTilePolygons.js +22 -22
  210. package/Build/Workers/createVectorTilePolylines.js +14 -14
  211. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +26 -26
  212. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +23 -23
  213. package/Build/Workers/createVerticesFromHeightmap.js +23 -23
  214. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +21 -21
  215. package/Build/Workers/createWallGeometry.js +26 -26
  216. package/Build/Workers/createWallOutlineGeometry.js +26 -26
  217. package/Build/Workers/decodeDraco.js +10 -10
  218. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +993 -2334
  219. package/Build/Workers/decodeI3S.js +10 -10
  220. package/Build/Workers/gaussianSplatSorter.js +4 -4
  221. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  222. package/Build/Workers/incrementallyBuildTerrainPicker.js +10 -10
  223. package/Build/Workers/transcodeKTX2.js +6 -6
  224. package/Build/Workers/transferTypedArrayTest.js +1 -1
  225. package/Build/Workers/upsampleQuantizedTerrainMesh.js +23 -23
  226. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +26 -26
  227. package/Source/Core/ArcGISTiledElevationTerrainProvider.js +1 -5
  228. package/Source/Core/BoundingRectangle.js +6 -8
  229. package/Source/Core/BoundingSphere.js +0 -3
  230. package/Source/Core/Cartesian2.js +1 -1
  231. package/Source/Core/Cartesian3.js +1 -1
  232. package/Source/Core/Cartesian4.js +1 -1
  233. package/Source/Core/Cesium3DTilesTerrainGeometryProcessor.js +3 -4
  234. package/Source/Core/Color.js +1 -0
  235. package/Source/Core/ComponentDatatype.js +35 -0
  236. package/Source/Core/CoplanarPolygonGeometry.js +2 -2
  237. package/Source/Core/CorridorGeometry.js +2 -4
  238. package/Source/Core/CorridorOutlineGeometry.js +1 -3
  239. package/Source/Core/EarthOrientationParameters.js +2 -2
  240. package/Source/Core/EllipseGeometryLibrary.js +2 -2
  241. package/Source/Core/EllipsoidGeodesic.js +3 -3
  242. package/Source/Core/EllipsoidRhumbLine.js +1 -1
  243. package/Source/Core/Heap.js +1 -1
  244. package/Source/Core/HermitePolynomialApproximation.js +215 -179
  245. package/Source/Core/InterpolationAlgorithm.js +58 -50
  246. package/Source/Core/Ion.js +1 -1
  247. package/Source/Core/JulianDate.js +1 -1
  248. package/Source/Core/LagrangePolynomialApproximation.js +55 -52
  249. package/Source/Core/LinearApproximation.js +69 -66
  250. package/Source/Core/MapProjection.js +1 -0
  251. package/Source/Core/Math.js +59 -0
  252. package/Source/Core/Matrix2.js +3 -3
  253. package/Source/Core/Matrix3.js +3 -3
  254. package/Source/Core/Matrix4.js +1 -1
  255. package/Source/Core/OrthographicFrustum.js +1 -1
  256. package/Source/Core/PerspectiveFrustum.js +1 -1
  257. package/Source/Core/PolygonGeometry.js +2 -2
  258. package/Source/Core/PolygonGeometryLibrary.js +1 -1
  259. package/Source/Core/PolygonOutlineGeometry.js +1 -1
  260. package/Source/Core/PolylineGeometry.js +1 -1
  261. package/Source/Core/PolylineVolumeGeometryLibrary.js +1 -1
  262. package/Source/Core/Rectangle.js +7 -1
  263. package/Source/Core/RectangleOutlineGeometry.js +1 -1
  264. package/Source/Core/Resource.js +1 -1
  265. package/Source/Core/ScreenSpaceEventHandler.js +51 -41
  266. package/Source/Core/SimplePolylineGeometry.js +1 -1
  267. package/Source/Core/TerrainEncoding.js +2 -2
  268. package/Source/Core/TerrainMesh.js +3 -3
  269. package/Source/Core/TerrainPicker.js +180 -168
  270. package/Source/Core/TimeIntervalCollection.js +1 -3
  271. package/Source/Core/Tipsify.js +1 -1
  272. package/Source/Core/Transforms.js +5 -1
  273. package/Source/Core/VectorPipeline.js +1117 -0
  274. package/Source/Core/VectorProvider.js +429 -0
  275. package/Source/Core/WallOutlineGeometry.js +1 -1
  276. package/Source/Core/createColorRamp.js +37 -0
  277. package/Source/Core/getTimestamp.js +4 -2
  278. package/Source/Core/globalTypes.js +25 -0
  279. package/Source/Core/writeTextToCanvas.js +1 -0
  280. package/Source/DataSources/CompositeEntityCollection.js +0 -1
  281. package/Source/DataSources/CzmlDataSource.js +14 -0
  282. package/Source/DataSources/DataSourceDisplay.js +1 -1
  283. package/Source/DataSources/GeoJsonDataSource.js +0 -1
  284. package/Source/DataSources/GeometryVisualizer.js +1 -1
  285. package/Source/DataSources/KmlDataSource.js +529 -557
  286. package/Source/DataSources/PathGraphics.js +8 -1
  287. package/Source/DataSources/PathMode.js +27 -0
  288. package/Source/DataSources/PathVisualizer.js +298 -1
  289. package/Source/DataSources/PolylineVisualizer.js +1 -1
  290. package/Source/DataSources/StaticOutlineGeometryBatch.js +1 -1
  291. package/Source/Renderer/AutomaticUniforms.js +23 -0
  292. package/Source/Renderer/Context.js +9 -3
  293. package/Source/Renderer/DrawCommand.js +22 -0
  294. package/Source/Renderer/Framebuffer.js +4 -0
  295. package/Source/Renderer/Pass.js +11 -9
  296. package/Source/Renderer/Texture.js +12 -1
  297. package/Source/Renderer/UniformState.js +7 -0
  298. package/Source/Renderer/VertexArray.js +1 -1
  299. package/Source/Renderer/createUniform.js +346 -239
  300. package/Source/Renderer/createUniformArray.js +494 -381
  301. package/Source/Scene/ArcGisMapServerImageryProvider.js +0 -5
  302. package/Source/Scene/ArcGisMapService.js +1 -1
  303. package/Source/Scene/Billboard.js +2 -1
  304. package/Source/Scene/BillboardCollection.js +15 -5
  305. package/Source/Scene/BillboardTexture.js +5 -3
  306. package/Source/Scene/BufferPointCollection.js +11 -1
  307. package/Source/Scene/BufferPolygonCollection.js +26 -0
  308. package/Source/Scene/BufferPolylineCollection.js +2 -0
  309. package/Source/Scene/BufferPrimitiveCollection.js +105 -32
  310. package/Source/Scene/Camera.js +85 -9
  311. package/Source/Scene/CameraEventAggregator.js +30 -18
  312. package/Source/Scene/CameraFlightPath.js +7 -4
  313. package/Source/Scene/Cesium3DTile.js +102 -4
  314. package/Source/Scene/Cesium3DTileContent.js +195 -254
  315. package/Source/Scene/Cesium3DTileContentFactory.js +10 -2
  316. package/Source/Scene/Cesium3DTileOptimizations.js +4 -6
  317. package/Source/Scene/Cesium3DTileStyle.js +40 -0
  318. package/Source/Scene/Cesium3DTileset.js +213 -8
  319. package/Source/Scene/Cesium3DTilesetTraversal.js +14 -0
  320. package/Source/Scene/ClippingPlaneCollection.js +4 -4
  321. package/Source/Scene/ClippingPolygon.js +2 -0
  322. package/Source/Scene/ClippingPolygonCollection.js +2 -2
  323. package/Source/Scene/Composite3DTileContent.js +254 -292
  324. package/Source/Scene/Controllers/Controller.js +63 -0
  325. package/Source/Scene/Controllers/ControllerHost.js +78 -0
  326. package/Source/Scene/Controllers/HybridScreenSpacePanCameraController.js +106 -0
  327. package/Source/Scene/Controllers/MouseButton.js +32 -0
  328. package/Source/Scene/Controllers/ScreenSpaceElevatorCameraController.js +295 -0
  329. package/Source/Scene/Controllers/ScreenSpaceInputBindings.js +154 -0
  330. package/Source/Scene/Controllers/ScreenSpaceMapCameraController.js +310 -0
  331. package/Source/Scene/Controllers/ScreenSpaceTiltOrbitCameraController.js +642 -0
  332. package/Source/Scene/Controllers/ScreenSpaceZoomCameraController.js +431 -0
  333. package/Source/Scene/Controllers/defaultPickWorldPosition.js +84 -0
  334. package/Source/Scene/DerivedCommand.js +98 -0
  335. package/Source/Scene/EdgeDisplayMode.js +50 -0
  336. package/Source/Scene/EdgeFramebuffer.js +1 -5
  337. package/Source/Scene/Empty3DTileContent.js +100 -132
  338. package/Source/Scene/Expression.js +6 -8
  339. package/Source/Scene/FrameState.js +17 -0
  340. package/Source/Scene/GaussianSplat3DTileContent.js +436 -478
  341. package/Source/Scene/GeoJsonPrimitive.js +874 -0
  342. package/Source/Scene/Geometry3DTileContent.js +151 -185
  343. package/Source/Scene/Globe.js +22 -1
  344. package/Source/Scene/GlobeDepth.js +27 -1
  345. package/Source/Scene/GlobeSurfaceShaderSet.js +637 -540
  346. package/Source/Scene/GlobeSurfaceTile.js +575 -398
  347. package/Source/Scene/GlobeSurfaceTileProvider.js +1412 -1184
  348. package/Source/Scene/GltfBufferViewLoader.js +3 -3
  349. package/Source/Scene/GltfLoader.js +146 -3
  350. package/Source/Scene/GltfLoaderUtil.js +20 -4
  351. package/Source/Scene/GltfPipeline/forEachTextureInMaterial.js +10 -0
  352. package/Source/Scene/GltfPipeline/removeUnusedElements.js +21 -11
  353. package/Source/Scene/GltfSpzLoader.js +1 -1
  354. package/Source/Scene/GltfVertexBufferLoader.js +6 -3
  355. package/Source/Scene/I3SDataProvider.js +1 -1
  356. package/Source/Scene/I3SLayer.js +1 -1
  357. package/Source/Scene/I3SNode.js +2 -2
  358. package/Source/Scene/ImageryLayer.js +2 -2
  359. package/Source/Scene/ImageryLayerCollection.js +190 -6
  360. package/Source/Scene/Implicit3DTileContent.js +192 -216
  361. package/Source/Scene/ImplicitTileCoordinates.js +17 -0
  362. package/Source/Scene/IonImageryProvider.js +1 -5
  363. package/Source/Scene/Label.js +4 -4
  364. package/Source/Scene/LabelCollection.js +4 -1
  365. package/Source/Scene/MVTDataProvider.js +555 -0
  366. package/Source/Scene/Material.js +1 -0
  367. package/Source/Scene/Model/B3dmLoader.js +1 -2
  368. package/Source/Scene/Model/EdgeVisibilityPipelineStage.js +82 -312
  369. package/Source/Scene/Model/Extensions/Gpm/GltfGpmLoader.js +4 -0
  370. package/Source/Scene/Model/I3dmLoader.js +1 -1
  371. package/Source/Scene/Model/InstancingPipelineStage.js +4 -7
  372. package/Source/Scene/Model/MaterialPipelineStage.js +124 -1
  373. package/Source/Scene/Model/Model.js +45 -10
  374. package/Source/Scene/Model/Model3DTileContent.js +424 -458
  375. package/Source/Scene/Model/ModelClippingPlanesPipelineStage.js +28 -1
  376. package/Source/Scene/Model/ModelDrawCommand.js +180 -8
  377. package/Source/Scene/Model/ModelDrawCommands.js +4 -0
  378. package/Source/Scene/Model/ModelSceneGraph.js +21 -0
  379. package/Source/Scene/Model/ModelUtility.js +5 -0
  380. package/Source/Scene/Model/PickingPipelineStage.js +29 -0
  381. package/Source/Scene/Model/PrimitiveRenderResources.js +24 -0
  382. package/Source/Scene/Model/createVectorTileBuffersFromModelComponents.js +645 -153
  383. package/Source/Scene/ModelComponents.js +112 -0
  384. package/Source/Scene/Multiple3DTileContent.js +291 -334
  385. package/Source/Scene/MvtLabelCandidates.js +295 -0
  386. package/Source/Scene/MvtLabelManager.js +1069 -0
  387. package/Source/Scene/Picking.js +19 -3
  388. package/Source/Scene/PlanarFillIdFramebuffer.js +172 -0
  389. package/Source/Scene/PntsParser.js +1 -1
  390. package/Source/Scene/PolylineCollection.js +5 -3
  391. package/Source/Scene/PostProcessStage.js +4 -2
  392. package/Source/Scene/QuadtreePrimitive.js +3 -2
  393. package/Source/Scene/ResourceCache.js +7 -4
  394. package/Source/Scene/ResourceCacheKey.js +21 -18
  395. package/Source/Scene/Scene.js +237 -11
  396. package/Source/Scene/SceneTransforms.js +6 -5
  397. package/Source/Scene/ShadowMap.js +9 -3
  398. package/Source/Scene/ShadowMapShader.js +50 -2
  399. package/Source/Scene/SnapFramebuffer.js +121 -0
  400. package/Source/Scene/Snapping.js +184 -0
  401. package/Source/Scene/TerrainFillMesh.js +3 -2
  402. package/Source/Scene/Tileset3DTileContent.js +113 -146
  403. package/Source/Scene/UrlTemplate3DTilesDataProvider.js +543 -0
  404. package/Source/Scene/Vector3DTileContent.js +207 -237
  405. package/Source/Scene/VectorGltf3DTileContent.js +185 -45
  406. package/Source/Scene/View.js +10 -8
  407. package/Source/Scene/VoxelPrimitive.js +159 -175
  408. package/Source/Scene/VoxelProvider.js +64 -91
  409. package/Source/Scene/VoxelTraversal.js +1 -1
  410. package/Source/Scene/buildVectorGltfFromMVT.js +1208 -0
  411. package/Source/Scene/buildVoxelCustomShader.js +199 -0
  412. package/Source/Scene/createElevationBandMaterial.js +1 -1
  413. package/Source/Scene/decodeMVT.js +877 -0
  414. package/Source/Scene/findMeshoptExtension.js +23 -0
  415. package/Source/Scene/renderBufferPointCollection.js +114 -64
  416. package/Source/Scene/renderBufferPolygonCollection.js +245 -53
  417. package/Source/Scene/renderBufferPolylineCollection.js +271 -145
  418. package/Source/Shaders/BillboardCollectionVS.glsl +23 -25
  419. package/Source/Shaders/BillboardCollectionVS.js +23 -25
  420. package/Source/Shaders/BufferPointMaterialFS.glsl +1 -0
  421. package/Source/Shaders/BufferPointMaterialFS.js +1 -0
  422. package/Source/Shaders/BufferPointMaterialVS.glsl +19 -9
  423. package/Source/Shaders/BufferPointMaterialVS.js +20 -10
  424. package/Source/Shaders/BufferPolygonMaterialFS.glsl +13 -0
  425. package/Source/Shaders/BufferPolygonMaterialFS.js +13 -0
  426. package/Source/Shaders/BufferPolygonMaterialVS.glsl +22 -4
  427. package/Source/Shaders/BufferPolygonMaterialVS.js +23 -5
  428. package/Source/Shaders/BufferPolylineMaterialVS.glsl +16 -2
  429. package/Source/Shaders/BufferPolylineMaterialVS.js +17 -3
  430. package/Source/Shaders/Builtin/Constants/passCesium3DTile.glsl +1 -1
  431. package/Source/Shaders/Builtin/Constants/passCesium3DTile.js +1 -1
  432. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.glsl +1 -1
  433. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.js +1 -1
  434. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.glsl +1 -1
  435. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.js +1 -1
  436. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdgesDirect.glsl +9 -0
  437. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdgesDirect.js +11 -0
  438. package/Source/Shaders/Builtin/Constants/passCesium3DTilePlanarFillId.glsl +9 -0
  439. package/Source/Shaders/Builtin/Constants/passCesium3DTilePlanarFillId.js +11 -0
  440. package/Source/Shaders/Builtin/Constants/passClassification.glsl +1 -1
  441. package/Source/Shaders/Builtin/Constants/passClassification.js +1 -1
  442. package/Source/Shaders/Builtin/Constants/passGaussianSplats.glsl +1 -1
  443. package/Source/Shaders/Builtin/Constants/passGaussianSplats.js +1 -1
  444. package/Source/Shaders/Builtin/Constants/passOpaque.glsl +1 -1
  445. package/Source/Shaders/Builtin/Constants/passOpaque.js +1 -1
  446. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  447. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  448. package/Source/Shaders/Builtin/Constants/passTranslucent.glsl +1 -1
  449. package/Source/Shaders/Builtin/Constants/passTranslucent.js +1 -1
  450. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +1 -1
  451. package/Source/Shaders/Builtin/Constants/passVoxels.js +1 -1
  452. package/Source/Shaders/Builtin/CzmBuiltins.js +4 -0
  453. package/Source/Shaders/GlobeFS.glsl +10 -6
  454. package/Source/Shaders/GlobeFS.js +10 -6
  455. package/Source/Shaders/Materials/PolylineGlowMaterial.glsl +1 -1
  456. package/Source/Shaders/Materials/PolylineGlowMaterial.js +1 -1
  457. package/Source/Shaders/Model/EdgeVisibilityStageVS.glsl +0 -1
  458. package/Source/Shaders/Model/EdgeVisibilityStageVS.js +0 -1
  459. package/Source/Shaders/Model/MaterialStageFS.glsl +8 -2
  460. package/Source/Shaders/Model/MaterialStageFS.js +8 -2
  461. package/Source/Shaders/Model/ModelFS.glsl +105 -0
  462. package/Source/Shaders/Model/ModelFS.js +105 -0
  463. package/Source/Shaders/VectorCommon.glsl +178 -0
  464. package/Source/Shaders/VectorCommon.js +180 -0
  465. package/Source/ThirdParty/zip-module.wasm +0 -0
  466. package/Source/Widget/CesiumWidget.js +30 -0
  467. package/Source/Workers/createMvtTile.js +39 -0
  468. package/Source/Workers/decodeGoogleEarthEnterprisePacket.js +2 -2
  469. package/Source/Workers/incrementallyBuildTerrainPicker.js +2 -0
  470. package/index.js +214 -184
  471. package/package.json +13 -13
@@ -0,0 +1,1069 @@
1
+ // @ts-check
2
+
3
+ import Cartesian2 from "../Core/Cartesian2.js";
4
+ import Cartesian3 from "../Core/Cartesian3.js";
5
+ import Color from "../Core/Color.js";
6
+ import getTimestamp from "../Core/getTimestamp.js";
7
+ import Matrix4 from "../Core/Matrix4.js";
8
+ import Rectangle from "../Core/Rectangle.js";
9
+ import WebMercatorProjection from "../Core/WebMercatorProjection.js";
10
+ import WebMercatorTilingScheme from "../Core/WebMercatorTilingScheme.js";
11
+ import defined from "../Core/defined.js";
12
+ import destroyObject from "../Core/destroyObject.js";
13
+ import EllipsoidalOccluder from "../Core/EllipsoidalOccluder.js";
14
+ import oneTimeWarning from "../Core/oneTimeWarning.js";
15
+ // @ts-expect-error rbush does not ship declarations in this workspace.
16
+ import RBush from "rbush";
17
+ import HorizontalOrigin from "./HorizontalOrigin.js";
18
+ import HeightReference from "./HeightReference.js";
19
+ import LabelCollection from "./LabelCollection.js";
20
+ import LabelStyle from "./LabelStyle.js";
21
+ import SceneMode from "./SceneMode.js";
22
+ import SceneTransforms from "./SceneTransforms.js";
23
+ import VerticalOrigin from "./VerticalOrigin.js";
24
+ import BillboardLoadState from "./BillboardLoadState.js";
25
+
26
+ const tilingScheme = new WebMercatorTilingScheme();
27
+ const earthCircumference = 2.0 * Math.PI * 6378137.0;
28
+ const webMercatorTileSize = 256.0;
29
+ const levelSwitchThreshold = 0.65;
30
+ const duplicateTextDistance = 64.0;
31
+ const scratchPosition = new Cartesian3();
32
+ const scratchWorldPosition = new Cartesian3();
33
+ const scratchWindowPosition = new Cartesian2();
34
+ const scratchTileRectangle = new Rectangle();
35
+ const scratchCollisionRectangle = {
36
+ minX: 0,
37
+ minY: 0,
38
+ maxX: 0,
39
+ maxY: 0,
40
+ };
41
+ const scratchFillColor = new Color();
42
+ const scratchOutlineColor = new Color();
43
+
44
+ /**
45
+ * @typedef {object} MvtLabelManagerOptions
46
+ * @property {*} scene
47
+ * @property {Array<*>} styles
48
+ * @property {HeightReference} [heightReference]
49
+ * @property {number} [transitionDuration]
50
+ * @property {number} [transitionSteps]
51
+ * @property {number} [maximumRetiringLabels]
52
+ * @property {number} [maximumCachedGlyphs]
53
+ * @property {number} [minimumRebuildInterval]
54
+ * @property {number} [glyphReclaimMargin]
55
+ * @property {number} [maximumVisibleLabels]
56
+ * @property {number} [threePointDepthTestDistance] Distance within which labels are depth-tested at three key points.
57
+ */
58
+
59
+ /**
60
+ * Coordinates MVT text symbols across the visible tile set. Candidates remain
61
+ * tile-local until traversal determines which tiles render in the current frame.
62
+ * @private
63
+ */
64
+ class MvtLabelManager {
65
+ /**
66
+ * @param {MvtLabelManagerOptions} options
67
+ */
68
+ constructor(options) {
69
+ this._scene = options.scene;
70
+ this._styles = normalizeStyles(options.styles);
71
+ this._heightReference =
72
+ options.heightReference ?? HeightReference.CLAMP_TO_GROUND;
73
+ this._transitionDuration = Math.max(0, options.transitionDuration ?? 0.2);
74
+ this._transitionSteps = Math.max(
75
+ 1,
76
+ Math.floor(options.transitionSteps ?? 4),
77
+ );
78
+ this._maximumRetiringLabels = Math.max(
79
+ 0,
80
+ Math.floor(options.maximumRetiringLabels ?? 512),
81
+ );
82
+ this._maximumCachedGlyphs = Math.max(
83
+ 0,
84
+ Math.floor(options.maximumCachedGlyphs ?? 2048),
85
+ );
86
+ this._minimumRebuildInterval = Math.max(
87
+ 0,
88
+ options.minimumRebuildInterval ?? 10,
89
+ );
90
+ this._glyphReclaimMargin = Math.max(
91
+ 0,
92
+ Math.floor(
93
+ options.glyphReclaimMargin ?? Math.floor(this._maximumCachedGlyphs / 4),
94
+ ),
95
+ );
96
+ this._maximumVisibleLabels = Math.max(
97
+ 0,
98
+ Math.floor(options.maximumVisibleLabels ?? 1000),
99
+ );
100
+ this._threePointDepthTestDistance = Math.max(
101
+ 0,
102
+ options.threePointDepthTestDistance ??
103
+ getMaximumThreePointDepthTestDistance(this._styles),
104
+ );
105
+ this._visible = true;
106
+ this._getTimestamp = getTimestamp;
107
+ this._labelCollection = new LabelCollection({
108
+ scene: this._scene,
109
+ threePointDepthTestDistance: this._threePointDepthTestDistance,
110
+ alwaysThreePointDepthTest: true,
111
+ });
112
+ /** @type {Set<*>} */
113
+ this._tiles = new Set();
114
+ /** @type {Array<*>} */
115
+ this._frameCandidates = [];
116
+ /** @type {Array<*>} */
117
+ this._visibleCandidates = [];
118
+ /** @type {Array<*>} */
119
+ this._nextVisibleCandidates = [];
120
+ /** @type {Set<*>} */
121
+ this._nextVisibleSet = new Set();
122
+ /** @type {Set<*>} */
123
+ this._retainedCandidates = new Set();
124
+ /** @type {Set<string>} */
125
+ this._acceptedIds = new Set();
126
+ /** @type {Map<string, Array<Cartesian2>>} */
127
+ this._textPositions = new Map();
128
+ /** @type {Array<*>} */
129
+ this._retiringCandidates = [];
130
+ this._collisionTree = new RBush();
131
+ this._frameNumber = -1;
132
+ this._frameTime = undefined;
133
+ this._displayZoom = undefined;
134
+ this._frameTileZoom = undefined;
135
+ this._labelCollectionRebuilds = 0;
136
+ this._lastRebuildTime = undefined;
137
+ }
138
+
139
+ get enabled() {
140
+ return this._styles.length > 0;
141
+ }
142
+
143
+ /** @returns {boolean} */
144
+ get visible() {
145
+ return this._visible;
146
+ }
147
+
148
+ /**
149
+ * Controls whether labels participate in the current frame. Hiding also
150
+ * removes live labels immediately so the change is reflected without waiting
151
+ * for candidates to retire through collision updates.
152
+ * @param {boolean} visible
153
+ */
154
+ setVisible(visible) {
155
+ if (this._visible === visible) {
156
+ return;
157
+ }
158
+ this._visible = visible;
159
+ if (!visible) {
160
+ const candidates = [
161
+ ...this._visibleCandidates,
162
+ ...this._retiringCandidates,
163
+ ];
164
+ this._visibleCandidates.length = 0;
165
+ this._nextVisibleCandidates.length = 0;
166
+ this._retiringCandidates.length = 0;
167
+ this._nextVisibleSet.clear();
168
+ this._retainedCandidates.clear();
169
+ this._frameCandidates.length = 0;
170
+ this._acceptedIds.clear();
171
+ this._textPositions.clear();
172
+ this._collisionTree.clear();
173
+ for (const candidate of candidates) {
174
+ if (defined(candidate.label)) {
175
+ this._labelCollection.remove(candidate.label);
176
+ }
177
+ // Recreating labels on the next visible frame starts from show=false,
178
+ // so clear the cached opacity transition state as well. Otherwise the
179
+ // opacity fast path would skip applying show=true to the new label.
180
+ resetCandidateLabel(candidate);
181
+ }
182
+ }
183
+ this._scene?.requestRender?.();
184
+ }
185
+
186
+ /** @param {*} frameState */
187
+ beginFrame(frameState) {
188
+ if (this._frameNumber === frameState.frameNumber) {
189
+ return;
190
+ }
191
+ this._frameNumber = frameState.frameNumber;
192
+ this._frameTime = this._getTimestamp();
193
+ if (!this._visible) {
194
+ return;
195
+ }
196
+ this._rebuildLabelCollectionIfNeeded();
197
+ this._updateDisplayZoom(frameState);
198
+ this._frameCandidates.length = 0;
199
+ this._collisionTree.clear();
200
+ }
201
+
202
+ /** @param {*} tile @param {{tileX:number,tileY:number,tileZ:number}} tileCoordinates @param {Array<*>} candidates */
203
+ addTile(tile, tileCoordinates, candidates) {
204
+ const entry = { tile, tileCoordinates, candidates };
205
+ this._tiles.add(entry);
206
+ return entry;
207
+ }
208
+
209
+ /** @param {*} entry */
210
+ removeTile(entry) {
211
+ if (!defined(entry) || !this._tiles.delete(entry)) {
212
+ return;
213
+ }
214
+ removeCandidates(this._frameCandidates, entry.candidates);
215
+ removeCandidates(this._visibleCandidates, entry.candidates);
216
+ for (const candidate of entry.candidates) {
217
+ this._removeCandidate(candidate);
218
+ }
219
+ }
220
+
221
+ /** @param {*} entry @param {*} transform */
222
+ submitTile(entry, transform) {
223
+ if (!this.enabled || !this._visible || !this._tiles.has(entry)) {
224
+ return;
225
+ }
226
+ for (const candidate of entry.candidates) {
227
+ candidate.transform = transform;
228
+ this._frameCandidates.push(candidate);
229
+ }
230
+ }
231
+
232
+ /** @param {*} frameState */
233
+ submitSelectedTiles(frameState) {
234
+ if (!this.enabled || !this._visible) {
235
+ this._frameTileZoom = undefined;
236
+ return;
237
+ }
238
+ let maximumSelectedZoom = -1;
239
+ for (const entry of this._tiles) {
240
+ const tileZoom = entry.tileCoordinates.tileZ;
241
+ if (entry.tile._selectedFrame !== frameState.frameNumber) {
242
+ continue;
243
+ }
244
+ maximumSelectedZoom = Math.max(maximumSelectedZoom, tileZoom);
245
+ this.submitTile(entry, entry.tile.computedTransform);
246
+ }
247
+ this._frameTileZoom =
248
+ maximumSelectedZoom >= 0 ? maximumSelectedZoom : undefined;
249
+ }
250
+
251
+ /** @param {*} frameState */
252
+ endFrame(frameState) {
253
+ if (
254
+ !this.enabled ||
255
+ !this._visible ||
256
+ this._frameNumber !== frameState.frameNumber
257
+ ) {
258
+ return;
259
+ }
260
+
261
+ const scene = this._scene;
262
+ const ellipsoidOccluder = createEllipsoidOccluder(scene, frameState);
263
+ const heightReference = getHeightReference(
264
+ frameState.mode,
265
+ this._heightReference,
266
+ );
267
+ const previousVisibleCandidates = this._visibleCandidates;
268
+ const nextVisibleCandidates = this._nextVisibleCandidates;
269
+ const acceptedIds = this._acceptedIds;
270
+ const textPositions = this._textPositions;
271
+ const nextVisibleSet = this._nextVisibleSet;
272
+ const retainedCandidates = this._retainedCandidates;
273
+ nextVisibleCandidates.length = 0;
274
+ acceptedIds.clear();
275
+ textPositions.clear();
276
+ nextVisibleSet.clear();
277
+ retainedCandidates.clear();
278
+ this._frameCandidates.sort(compareCandidates);
279
+ const currentCandidates = new Set(this._frameCandidates);
280
+ const currentCandidatesByDedupeKey = new Map();
281
+ for (const candidate of this._frameCandidates) {
282
+ const dedupeKey = getCandidateDedupeKey(candidate);
283
+ if (defined(dedupeKey) && !currentCandidatesByDedupeKey.has(dedupeKey)) {
284
+ currentCandidatesByDedupeKey.set(dedupeKey, candidate);
285
+ }
286
+ }
287
+ // Rebuilding the collision layout from scratch makes the winning symbol
288
+ // alternate while tiles stream in and out. Keep labels that remain valid
289
+ // for another frame, then fill only unoccupied space with new candidates.
290
+ for (const candidate of previousVisibleCandidates) {
291
+ const dedupeKey = getCandidateDedupeKey(candidate);
292
+ const currentCandidate = currentCandidates.has(candidate)
293
+ ? candidate
294
+ : currentCandidatesByDedupeKey.get(dedupeKey);
295
+ if (!defined(currentCandidate)) {
296
+ continue;
297
+ }
298
+ const style = this._styles[currentCandidate.styleIndex];
299
+ const styleZoom = this._displayZoom ?? currentCandidate.tileZ;
300
+ if (
301
+ styleZoom < style.minZoom ||
302
+ styleZoom > style.maxZoom ||
303
+ (defined(dedupeKey) && acceptedIds.has(dedupeKey))
304
+ ) {
305
+ continue;
306
+ }
307
+
308
+ getWorldPosition(currentCandidate, scratchWorldPosition);
309
+ if (
310
+ defined(ellipsoidOccluder) &&
311
+ !ellipsoidOccluder.isPointVisible(scratchWorldPosition)
312
+ ) {
313
+ continue;
314
+ }
315
+ if (defined(scene)) {
316
+ const windowPosition = SceneTransforms.worldToWindowCoordinates(
317
+ scene,
318
+ scratchWorldPosition,
319
+ scratchWindowPosition,
320
+ );
321
+ if (!isInsideViewport(scene, windowPosition)) {
322
+ continue;
323
+ }
324
+ const rectangle = makeCollisionRectangle(
325
+ currentCandidate,
326
+ style,
327
+ windowPosition,
328
+ scratchCollisionRectangle,
329
+ );
330
+ if (this._collisionTree.collides(rectangle)) {
331
+ continue;
332
+ }
333
+ if (
334
+ isDuplicateText(textPositions, currentCandidate.text, windowPosition)
335
+ ) {
336
+ continue;
337
+ }
338
+ this._collisionTree.insert({ ...rectangle });
339
+ }
340
+
341
+ this._reuseMatchingLabel(currentCandidate);
342
+ getOrCreateLabel(
343
+ this._labelCollection,
344
+ currentCandidate,
345
+ style,
346
+ scratchWorldPosition,
347
+ heightReference,
348
+ );
349
+ this._activateCandidate(currentCandidate, style, this._frameTime);
350
+ nextVisibleCandidates.push(currentCandidate);
351
+ nextVisibleSet.add(currentCandidate);
352
+ retainedCandidates.add(currentCandidate);
353
+ if (defined(dedupeKey)) {
354
+ acceptedIds.add(dedupeKey);
355
+ }
356
+ }
357
+
358
+ for (const candidate of this._frameCandidates) {
359
+ if (retainedCandidates.has(candidate)) {
360
+ continue;
361
+ }
362
+ // Candidates are priority-sorted, so the cap drops the least important
363
+ // labels. It also keeps the live glyph set inside the atlas budget.
364
+ if (nextVisibleCandidates.length >= this._maximumVisibleLabels) {
365
+ break;
366
+ }
367
+ const style = this._styles[candidate.styleIndex];
368
+ const styleZoom = this._displayZoom ?? candidate.tileZ;
369
+ const dedupeKey = getCandidateDedupeKey(candidate);
370
+ if (
371
+ styleZoom < style.minZoom ||
372
+ styleZoom > style.maxZoom ||
373
+ (defined(dedupeKey) && acceptedIds.has(dedupeKey))
374
+ ) {
375
+ continue;
376
+ }
377
+
378
+ getWorldPosition(candidate, scratchWorldPosition);
379
+ if (
380
+ defined(ellipsoidOccluder) &&
381
+ !ellipsoidOccluder.isPointVisible(scratchWorldPosition)
382
+ ) {
383
+ continue;
384
+ }
385
+ if (defined(scene)) {
386
+ const windowPosition = SceneTransforms.worldToWindowCoordinates(
387
+ scene,
388
+ scratchWorldPosition,
389
+ scratchWindowPosition,
390
+ );
391
+ if (!isInsideViewport(scene, windowPosition)) {
392
+ continue;
393
+ }
394
+ const rectangle = makeCollisionRectangle(
395
+ candidate,
396
+ style,
397
+ windowPosition,
398
+ scratchCollisionRectangle,
399
+ );
400
+ if (this._collisionTree.collides(rectangle)) {
401
+ continue;
402
+ }
403
+ if (isDuplicateText(textPositions, candidate.text, windowPosition)) {
404
+ continue;
405
+ }
406
+ // The tree retains what it is given, so the scratch cannot be inserted.
407
+ this._collisionTree.insert({ ...rectangle });
408
+ }
409
+
410
+ this._reuseMatchingLabel(candidate);
411
+ getOrCreateLabel(
412
+ this._labelCollection,
413
+ candidate,
414
+ style,
415
+ scratchWorldPosition,
416
+ heightReference,
417
+ );
418
+ this._activateCandidate(candidate, style, this._frameTime);
419
+ nextVisibleCandidates.push(candidate);
420
+ nextVisibleSet.add(candidate);
421
+ if (defined(dedupeKey)) {
422
+ acceptedIds.add(dedupeKey);
423
+ }
424
+ }
425
+
426
+ // Swap before retiring so the retire path splices the new array, matching
427
+ // the previous behavior where mutations to the old array were discarded.
428
+ this._visibleCandidates = nextVisibleCandidates;
429
+ for (const candidate of previousVisibleCandidates) {
430
+ if (!nextVisibleSet.has(candidate)) {
431
+ this._retireCandidate(candidate, this._frameTime);
432
+ }
433
+ }
434
+ previousVisibleCandidates.length = 0;
435
+ this._nextVisibleCandidates = previousVisibleCandidates;
436
+ this._updateTransitions(this._frameTime);
437
+
438
+ // update is an internal primitive method, but it is the same lifecycle
439
+ // used by Vector3DTilePoints for batched labels.
440
+ /** @type {*} */ (this._labelCollection).update(frameState);
441
+ if (hasPendingGlyphLoads(this._labelCollection)) {
442
+ if (defined(frameState.afterRender)) {
443
+ frameState.afterRender.push(requestRenderAfterFrame);
444
+ } else {
445
+ scene?.requestRender();
446
+ }
447
+ }
448
+ }
449
+
450
+ /** @param {*} candidate @param {*} style @param {*} time */
451
+ _activateCandidate(candidate, style, time) {
452
+ const isNewTransition = candidate.transitionTargetOpacity !== 1;
453
+ const previousOpacity =
454
+ candidate.opacity ??
455
+ (isNewTransition && defined(this._scene) ? 1 / this._transitionSteps : 1);
456
+ if (isNewTransition) {
457
+ candidate.transitionStart = time;
458
+ candidate.transitionStartOpacity = previousOpacity;
459
+ candidate.transitionTargetOpacity = 1;
460
+ }
461
+ removeCandidates(this._retiringCandidates, [candidate]);
462
+ this._applyCandidateOpacity(candidate, style, previousOpacity);
463
+ }
464
+
465
+ /** @param {*} candidate @param {*} time */
466
+ _retireCandidate(candidate, time) {
467
+ removeCandidates(this._visibleCandidates, [candidate]);
468
+ if (!defined(candidate.label)) {
469
+ return;
470
+ }
471
+ if (
472
+ this._transitionDuration === 0 ||
473
+ this._maximumRetiringLabels === 0 ||
474
+ !defined(this._scene)
475
+ ) {
476
+ this._removeCandidate(candidate);
477
+ return;
478
+ }
479
+
480
+ candidate.transitionStart = time;
481
+ candidate.transitionStartOpacity = candidate.opacity ?? 1;
482
+ candidate.transitionTargetOpacity = 0;
483
+ this._retiringCandidates.push(candidate);
484
+
485
+ while (this._retiringCandidates.length > this._maximumRetiringLabels) {
486
+ this._removeCandidate(this._retiringCandidates[0]);
487
+ }
488
+ }
489
+
490
+ /** @param {*} candidate */
491
+ _reuseMatchingLabel(candidate) {
492
+ const dedupeKey = getCandidateDedupeKey(candidate);
493
+ if (defined(candidate.label) || !defined(dedupeKey)) {
494
+ return;
495
+ }
496
+ const matchingCandidate =
497
+ findCandidateByDedupeKey(this._visibleCandidates, dedupeKey) ??
498
+ findCandidateByDedupeKey(this._retiringCandidates, dedupeKey);
499
+ if (!defined(matchingCandidate) || !defined(matchingCandidate.label)) {
500
+ return;
501
+ }
502
+ candidate.label = matchingCandidate.label;
503
+ candidate.opacity = matchingCandidate.opacity;
504
+ candidate.appliedOpacity = matchingCandidate.appliedOpacity;
505
+ candidate.transitionStart = matchingCandidate.transitionStart;
506
+ candidate.transitionStartOpacity = matchingCandidate.transitionStartOpacity;
507
+ candidate.transitionTargetOpacity = 1;
508
+ matchingCandidate.label = undefined;
509
+ removeCandidates(this._retiringCandidates, [matchingCandidate]);
510
+ }
511
+
512
+ /** @param {*} time */
513
+ _updateTransitions(time) {
514
+ let needsAnotherFrame = false;
515
+ for (const candidate of this._visibleCandidates) {
516
+ const style = this._styles[candidate.styleIndex];
517
+ needsAnotherFrame =
518
+ this._updateCandidateTransition(candidate, style, time) ||
519
+ needsAnotherFrame;
520
+ }
521
+
522
+ for (let i = this._retiringCandidates.length - 1; i >= 0; i--) {
523
+ const candidate = this._retiringCandidates[i];
524
+ const style = this._styles[candidate.styleIndex];
525
+ if (this._updateCandidateTransition(candidate, style, time)) {
526
+ needsAnotherFrame = true;
527
+ continue;
528
+ }
529
+ if (candidate.opacity === 0 && defined(candidate.label)) {
530
+ this._labelCollection.remove(candidate.label);
531
+ candidate.label = undefined;
532
+ }
533
+ this._retiringCandidates.splice(i, 1);
534
+ }
535
+
536
+ if (needsAnotherFrame) {
537
+ this._scene?.requestRender();
538
+ }
539
+ }
540
+
541
+ /** @param {*} candidate @param {*} style @param {*} time */
542
+ _updateCandidateTransition(candidate, style, time) {
543
+ const targetOpacity = candidate.transitionTargetOpacity ?? 1;
544
+ const startOpacity = candidate.transitionStartOpacity ?? targetOpacity;
545
+ const elapsed = elapsedSeconds(time, candidate.transitionStart);
546
+ const progress =
547
+ this._transitionDuration === 0
548
+ ? 1
549
+ : Math.min(elapsed / this._transitionDuration, 1);
550
+ const opacity = quantizeOpacity(
551
+ startOpacity + (targetOpacity - startOpacity) * progress,
552
+ this._transitionSteps,
553
+ );
554
+ this._applyCandidateOpacity(candidate, style, opacity);
555
+ return progress < 1;
556
+ }
557
+
558
+ /** @param {*} candidate @param {*} style @param {number} opacity */
559
+ _applyCandidateOpacity(candidate, style, opacity) {
560
+ if (candidate.opacity === opacity && candidate.appliedOpacity === opacity) {
561
+ return;
562
+ }
563
+ candidate.opacity = opacity;
564
+ candidate.appliedOpacity = opacity;
565
+ const label = candidate.label;
566
+ if (!defined(label)) {
567
+ return;
568
+ }
569
+ label.show = opacity > 0;
570
+ label.fillColor = withAlpha(style.fillColor, opacity, scratchFillColor);
571
+ label.outlineColor = withAlpha(
572
+ style.outlineColor,
573
+ opacity,
574
+ scratchOutlineColor,
575
+ );
576
+ }
577
+
578
+ /** @param {*} candidate */
579
+ _removeCandidate(candidate) {
580
+ removeCandidates(this._visibleCandidates, [candidate]);
581
+ removeCandidates(this._retiringCandidates, [candidate]);
582
+ if (defined(candidate.label)) {
583
+ this._labelCollection.remove(candidate.label);
584
+ candidate.label = undefined;
585
+ }
586
+ }
587
+
588
+ /** @param {*} frameState */
589
+ _updateDisplayZoom(frameState) {
590
+ const viewZoom = getViewZoom(frameState);
591
+ if (!defined(viewZoom)) {
592
+ return;
593
+ }
594
+ if (!defined(this._displayZoom)) {
595
+ this._displayZoom = Math.max(0, Math.floor(viewZoom));
596
+ return;
597
+ }
598
+ while (viewZoom >= this._displayZoom + levelSwitchThreshold) {
599
+ this._displayZoom++;
600
+ }
601
+ while (viewZoom <= this._displayZoom - levelSwitchThreshold) {
602
+ this._displayZoom--;
603
+ }
604
+ }
605
+
606
+ _rebuildLabelCollectionIfNeeded() {
607
+ const cachedGlyphs = getCachedGlyphCount(this._labelCollection);
608
+ if (
609
+ this._maximumCachedGlyphs === 0 ||
610
+ cachedGlyphs <= this._maximumCachedGlyphs
611
+ ) {
612
+ return;
613
+ }
614
+
615
+ if (
616
+ defined(this._lastRebuildTime) &&
617
+ elapsedSeconds(this._frameTime, this._lastRebuildTime) <
618
+ this._minimumRebuildInterval
619
+ ) {
620
+ return;
621
+ }
622
+
623
+ // Only glyphs that no live label references can be reclaimed. Rebuilding
624
+ // when the live set already fills the budget would discard and immediately
625
+ // re-rasterize the whole atlas, so leave it alone and report it instead.
626
+ const liveGlyphs = countLiveGlyphs(this._labelCollection);
627
+ if (cachedGlyphs - liveGlyphs < this._glyphReclaimMargin) {
628
+ oneTimeWarning(
629
+ "MvtLabelManager.glyphBudget",
630
+ `MVT labels reference ${liveGlyphs} distinct glyphs, at or above the ${this._maximumCachedGlyphs} glyph budget, so the glyph atlas cannot be shrunk. Lower maximumVisibleLabels or raise maximumCachedGlyphs.`,
631
+ );
632
+ return;
633
+ }
634
+
635
+ this._labelCollection = this._labelCollection.destroy();
636
+ this._labelCollection = new LabelCollection({ scene: this._scene });
637
+ for (const entry of this._tiles) {
638
+ for (const candidate of entry.candidates) {
639
+ resetCandidateLabel(candidate);
640
+ }
641
+ }
642
+ for (const candidate of this._retiringCandidates) {
643
+ resetCandidateLabel(candidate);
644
+ }
645
+ this._retiringCandidates.length = 0;
646
+ this._visibleCandidates.length = 0;
647
+ this._labelCollectionRebuilds++;
648
+ this._lastRebuildTime = this._frameTime;
649
+ }
650
+
651
+ isDestroyed() {
652
+ return false;
653
+ }
654
+
655
+ destroy() {
656
+ for (const entry of this._tiles) {
657
+ for (const candidate of entry.candidates) {
658
+ if (defined(candidate.label)) {
659
+ this._labelCollection.remove(candidate.label);
660
+ candidate.label = undefined;
661
+ }
662
+ }
663
+ }
664
+ for (const candidate of this._retiringCandidates) {
665
+ if (defined(candidate.label)) {
666
+ this._labelCollection.remove(candidate.label);
667
+ candidate.label = undefined;
668
+ }
669
+ }
670
+ this._tiles.clear();
671
+ this._retiringCandidates.length = 0;
672
+ this._labelCollection = this._labelCollection.destroy();
673
+ return destroyObject(this);
674
+ }
675
+ }
676
+
677
+ function requestRenderAfterFrame() {
678
+ return true;
679
+ }
680
+
681
+ /** @param {*} labelCollection */
682
+ function getCachedGlyphCount(labelCollection) {
683
+ return (
684
+ labelCollection?._glyphBillboardCollection?.billboardTextureCache?.size ?? 0
685
+ );
686
+ }
687
+
688
+ /**
689
+ * Counts the distinct glyphs still referenced by labels in the collection. The
690
+ * difference against the glyph cache size is how much a rebuild would reclaim.
691
+ * @param {*} labelCollection
692
+ * @returns {number}
693
+ */
694
+ function countLiveGlyphs(labelCollection) {
695
+ const labels = labelCollection?._labels;
696
+ if (!Array.isArray(labels)) {
697
+ return 0;
698
+ }
699
+ const liveIds = new Set();
700
+ for (const label of labels) {
701
+ for (const glyph of label._glyphs ?? []) {
702
+ const id = glyph.billboardTexture?.id;
703
+ if (defined(id)) {
704
+ liveIds.add(id);
705
+ }
706
+ }
707
+ }
708
+ return liveIds.size;
709
+ }
710
+
711
+ /** @param {*} labelCollection */
712
+ function hasPendingGlyphLoads(labelCollection) {
713
+ const cache =
714
+ labelCollection?._glyphBillboardCollection?.billboardTextureCache;
715
+ if (!defined(cache)) {
716
+ return false;
717
+ }
718
+ for (const texture of cache.values()) {
719
+ if (texture.loadState === BillboardLoadState.LOADING) {
720
+ return true;
721
+ }
722
+ }
723
+ return false;
724
+ }
725
+
726
+ /** @param {*} candidate */
727
+ function resetCandidateLabel(candidate) {
728
+ candidate.label = undefined;
729
+ candidate.appliedOpacity = undefined;
730
+ candidate.transitionStart = undefined;
731
+ candidate.transitionStartOpacity = undefined;
732
+ candidate.transitionTargetOpacity = undefined;
733
+ }
734
+
735
+ /** @param {*} time @param {*} startTime */
736
+ function elapsedSeconds(time, startTime) {
737
+ return defined(time) && defined(startTime)
738
+ ? Math.max(time - startTime, 0) / 1000
739
+ : 0;
740
+ }
741
+
742
+ /** @param {*} frameState */
743
+ function getViewZoom(frameState) {
744
+ const camera = frameState.camera;
745
+ const height = camera?.positionCartographic?.height;
746
+ const pixelRatio = frameState.pixelRatio ?? 1;
747
+ const viewportHeight =
748
+ (frameState.context?.drawingBufferHeight ?? 0) / pixelRatio;
749
+ const verticalFov = getVerticalFov(camera?.frustum);
750
+ if (
751
+ !Number.isFinite(height) ||
752
+ !Number.isFinite(viewportHeight) ||
753
+ !Number.isFinite(verticalFov) ||
754
+ height <= 0 ||
755
+ viewportHeight <= 0
756
+ ) {
757
+ return undefined;
758
+ }
759
+ const metersPerPixel =
760
+ (2.0 * height * Math.tan(verticalFov * 0.5)) / viewportHeight;
761
+ const zoom = Math.log2(
762
+ earthCircumference / (webMercatorTileSize * metersPerPixel),
763
+ );
764
+ return Math.max(0, zoom);
765
+ }
766
+
767
+ /** @param {*} scene @param {*} frameState @returns {EllipsoidalOccluder|undefined} */
768
+ function createEllipsoidOccluder(scene, frameState) {
769
+ if (
770
+ frameState.mode !== SceneMode.SCENE3D ||
771
+ !defined(scene) ||
772
+ !defined(scene.ellipsoid)
773
+ ) {
774
+ return undefined;
775
+ }
776
+ const cameraPosition =
777
+ frameState.camera?.positionWC ?? scene.camera?.positionWC;
778
+ if (!defined(cameraPosition)) {
779
+ return undefined;
780
+ }
781
+ return new EllipsoidalOccluder(scene.ellipsoid, cameraPosition);
782
+ }
783
+
784
+ /** @param {SceneMode|undefined} mode @param {HeightReference} heightReference */
785
+ function getHeightReference(mode, heightReference) {
786
+ if (mode === SceneMode.SCENE2D || mode === SceneMode.COLUMBUS_VIEW) {
787
+ return HeightReference.NONE;
788
+ }
789
+ return heightReference;
790
+ }
791
+
792
+ /** @param {Set<*>} entries @param {number} maximumTileZoom */
793
+ /** @param {Map<string, Array<Cartesian2>>} textPositions @param {string} text @param {Cartesian2} position */
794
+ function isDuplicateText(textPositions, text, position) {
795
+ let positions = textPositions.get(text);
796
+ if (defined(positions)) {
797
+ for (const previousPosition of positions) {
798
+ const dx = position.x - previousPosition.x;
799
+ const dy = position.y - previousPosition.y;
800
+ if (dx * dx + dy * dy < duplicateTextDistance ** 2) {
801
+ return true;
802
+ }
803
+ }
804
+ } else {
805
+ positions = [];
806
+ textPositions.set(text, positions);
807
+ }
808
+ positions.push(Cartesian2.clone(position));
809
+ return false;
810
+ }
811
+
812
+ /** @param {*} frustum */
813
+ function getVerticalFov(frustum) {
814
+ if (Number.isFinite(frustum?.fovy)) {
815
+ return frustum.fovy;
816
+ }
817
+ const offCenterFrustum = frustum?.offCenterFrustum;
818
+ if (!defined(offCenterFrustum) || offCenterFrustum.near <= 0) {
819
+ return undefined;
820
+ }
821
+ return (
822
+ Math.atan2(offCenterFrustum.top, offCenterFrustum.near) -
823
+ Math.atan2(offCenterFrustum.bottom, offCenterFrustum.near)
824
+ );
825
+ }
826
+
827
+ /** @param {number} opacity @param {number} steps */
828
+ function quantizeOpacity(opacity, steps) {
829
+ return Math.round(Math.min(Math.max(opacity, 0), 1) * steps) / steps;
830
+ }
831
+
832
+ /** @param {Color} color @param {number} opacity @param {Color} result */
833
+ function withAlpha(color, opacity, result) {
834
+ Color.clone(color, result);
835
+ result.alpha *= opacity;
836
+ return result;
837
+ }
838
+
839
+ /** @param {*} scene @param {*} windowPosition */
840
+ function isInsideViewport(scene, windowPosition) {
841
+ return (
842
+ defined(windowPosition) &&
843
+ windowPosition.x >= 0 &&
844
+ windowPosition.x <= scene.drawingBufferWidth &&
845
+ windowPosition.y >= 0 &&
846
+ windowPosition.y <= scene.drawingBufferHeight
847
+ );
848
+ }
849
+
850
+ /** @param {Array<*>} target @param {Array<*>} candidates */
851
+ function removeCandidates(target, candidates) {
852
+ if (candidates.length === 1) {
853
+ const index = target.indexOf(candidates[0]);
854
+ if (index >= 0) {
855
+ target.splice(index, 1);
856
+ }
857
+ return;
858
+ }
859
+ const removed = new Set(candidates);
860
+ for (let i = target.length - 1; i >= 0; i--) {
861
+ if (removed.has(target[i])) {
862
+ target.splice(i, 1);
863
+ }
864
+ }
865
+ }
866
+
867
+ /** @param {*} candidate */
868
+ function getCandidateDedupeKey(candidate) {
869
+ return candidate.semanticDedupeId ?? candidate.dedupeId;
870
+ }
871
+
872
+ /** @param {Array<*>} candidates @param {string} dedupeKey */
873
+ function findCandidateByDedupeKey(candidates, dedupeKey) {
874
+ return candidates.find(
875
+ (candidate) =>
876
+ getCandidateDedupeKey(candidate) === dedupeKey &&
877
+ defined(candidate.label),
878
+ );
879
+ }
880
+
881
+ /** @param {Array<*>} styles */
882
+ function normalizeStyles(styles) {
883
+ if (!Array.isArray(styles)) {
884
+ return [];
885
+ }
886
+ return styles.map((style, index) => {
887
+ const textSize = style.textSize ?? style["text-size"] ?? 16;
888
+ const font = style.font ?? `${textSize}px sans-serif`;
889
+ return {
890
+ index,
891
+ sourceLayer: style.sourceLayer ?? style["source-layer"],
892
+ textField: style.textField ?? style["text-field"] ?? "name",
893
+ minZoom: style.minZoom ?? style["minzoom"] ?? 0,
894
+ maxZoom: style.maxZoom ?? style["maxzoom"] ?? Number.POSITIVE_INFINITY,
895
+ priority: style.priority ?? style["symbol-sort-key"] ?? 0,
896
+ font,
897
+ fillColor: toColor(style.fillColor ?? style["text-color"], Color.WHITE),
898
+ outlineColor: toColor(
899
+ style.outlineColor ?? style["text-halo-color"],
900
+ Color.BLACK,
901
+ ),
902
+ outlineWidth: style.outlineWidth ?? style["text-halo-width"] ?? 1,
903
+ disableDepthTestDistance:
904
+ style.disableDepthTestDistance ?? style["disable-depth-test-distance"],
905
+ threePointDepthTestDistance:
906
+ style.threePointDepthTestDistance ??
907
+ style["three-point-depth-test-distance"],
908
+ collisionPadding: getCollisionPadding(style),
909
+ pixelOffset: new Cartesian2(
910
+ style.pixelOffset?.x ?? style["text-offset"]?.[0] ?? 0,
911
+ style.pixelOffset?.y ?? style["text-offset"]?.[1] ?? 0,
912
+ ),
913
+ filter: style.filter,
914
+ };
915
+ });
916
+ }
917
+
918
+ /** @param {Array<*>} styles @returns {number|undefined} */
919
+ function getMaximumThreePointDepthTestDistance(styles) {
920
+ let maximum;
921
+ for (const style of styles) {
922
+ const distance = style.threePointDepthTestDistance;
923
+ if (Number.isFinite(distance) && distance >= 0) {
924
+ maximum = Math.max(maximum ?? 0, distance);
925
+ }
926
+ }
927
+ return maximum;
928
+ }
929
+
930
+ /** @param {*} value @param {Color} fallback @returns {Color} */
931
+ function toColor(value, fallback) {
932
+ if (value instanceof Color) {
933
+ return Color.clone(value);
934
+ }
935
+ if (typeof value === "string") {
936
+ return Color.fromCssColorString(value) ?? Color.clone(fallback);
937
+ }
938
+ return Color.clone(fallback);
939
+ }
940
+
941
+ /** @param {*} left @param {*} right */
942
+ function compareCandidates(left, right) {
943
+ const leftStyle = left.stylePriority;
944
+ const rightStyle = right.stylePriority;
945
+ if (leftStyle !== rightStyle) {
946
+ return rightStyle - leftStyle;
947
+ }
948
+ if (left.tileZ !== right.tileZ) {
949
+ return right.tileZ - left.tileZ;
950
+ }
951
+ return left.sortKey < right.sortKey
952
+ ? -1
953
+ : left.sortKey > right.sortKey
954
+ ? 1
955
+ : 0;
956
+ }
957
+
958
+ /** @param {*} candidate @param {Cartesian3} result @returns {Cartesian3} */
959
+ function getWorldPosition(candidate, result) {
960
+ const rectangle = tilingScheme.tileXYToRectangle(
961
+ candidate.tileX,
962
+ candidate.tileY,
963
+ candidate.tileZ,
964
+ scratchTileRectangle,
965
+ );
966
+ const longitude =
967
+ rectangle.west + (rectangle.east - rectangle.west) * candidate.x;
968
+ const northMercatorAngle =
969
+ WebMercatorProjection.geodeticLatitudeToMercatorAngle(rectangle.north);
970
+ const southMercatorAngle =
971
+ WebMercatorProjection.geodeticLatitudeToMercatorAngle(rectangle.south);
972
+ const latitude = WebMercatorProjection.mercatorAngleToGeodeticLatitude(
973
+ northMercatorAngle +
974
+ (southMercatorAngle - northMercatorAngle) * candidate.y,
975
+ );
976
+ Cartesian3.fromRadians(longitude, latitude, 0, undefined, scratchPosition);
977
+ return Matrix4.multiplyByPoint(candidate.transform, scratchPosition, result);
978
+ }
979
+
980
+ /** @param {*} candidate @param {*} style @param {Cartesian2} position @param {*} result */
981
+ function makeCollisionRectangle(candidate, style, position, result) {
982
+ const fontSize = parseFontSize(style.font);
983
+ const width = Math.max(fontSize, estimateTextWidth(candidate.text, fontSize));
984
+ const padding = style.collisionPadding;
985
+ result.minX = position.x + style.pixelOffset.x - width * 0.5 - padding.x;
986
+ result.minY = position.y + style.pixelOffset.y - fontSize * 0.5 - padding.y;
987
+ result.maxX = position.x + style.pixelOffset.x + width * 0.5 + padding.x;
988
+ result.maxY = position.y + style.pixelOffset.y + fontSize * 0.5 + padding.y;
989
+ return result;
990
+ }
991
+
992
+ /** @param {*} style @returns {Cartesian2} */
993
+ function getCollisionPadding(style) {
994
+ const padding = style.collisionPadding ?? style["text-padding"] ?? 6;
995
+ if (typeof padding === "number") {
996
+ const value = Math.max(0, padding);
997
+ return new Cartesian2(value, value);
998
+ }
999
+ return new Cartesian2(
1000
+ Math.max(0, padding?.x ?? padding?.[0] ?? 6),
1001
+ Math.max(0, padding?.y ?? padding?.[1] ?? 6),
1002
+ );
1003
+ }
1004
+
1005
+ /** @param {string} text @param {number} fontSize */
1006
+ function estimateTextWidth(text, fontSize) {
1007
+ let width = 0;
1008
+ for (const character of text) {
1009
+ // CJK glyphs generally occupy the full em width, unlike Latin glyphs.
1010
+ width += isWideCharacter(character) ? fontSize : fontSize * 0.62;
1011
+ }
1012
+ return width;
1013
+ }
1014
+
1015
+ /** @param {string} character */
1016
+ function isWideCharacter(character) {
1017
+ const codePoint = character.codePointAt(0);
1018
+ return (
1019
+ defined(codePoint) &&
1020
+ ((codePoint >= 0x1100 && codePoint <= 0x115f) ||
1021
+ (codePoint >= 0x2e80 && codePoint <= 0xa4cf) ||
1022
+ (codePoint >= 0xac00 && codePoint <= 0xd7af) ||
1023
+ (codePoint >= 0xf900 && codePoint <= 0xfaff) ||
1024
+ (codePoint >= 0xfe10 && codePoint <= 0xfe6f) ||
1025
+ (codePoint >= 0xff01 && codePoint <= 0xff60) ||
1026
+ (codePoint >= 0xffe0 && codePoint <= 0xffe6))
1027
+ );
1028
+ }
1029
+
1030
+ /** @param {string} font */
1031
+ function parseFontSize(font) {
1032
+ const match = /(?:^|\s)(\d+(?:\.\d+)?)px(?:\s|$)/.exec(font);
1033
+ return defined(match) ? Number(match[1]) : 16;
1034
+ }
1035
+
1036
+ /** @param {*} collection @param {*} candidate @param {*} style @param {Cartesian3} position @param {HeightReference} heightReference */
1037
+ function getOrCreateLabel(
1038
+ collection,
1039
+ candidate,
1040
+ style,
1041
+ position,
1042
+ heightReference,
1043
+ ) {
1044
+ let label = candidate.label;
1045
+ if (!defined(label)) {
1046
+ label = candidate.label = collection.add({
1047
+ text: candidate.text,
1048
+ font: style.font,
1049
+ fillColor: style.fillColor,
1050
+ outlineColor: style.outlineColor,
1051
+ outlineWidth: style.outlineWidth,
1052
+ disableDepthTestDistance: style.disableDepthTestDistance,
1053
+ style: LabelStyle.FILL_AND_OUTLINE,
1054
+ horizontalOrigin: HorizontalOrigin.CENTER,
1055
+ verticalOrigin: VerticalOrigin.CENTER,
1056
+ pixelOffset: style.pixelOffset,
1057
+ heightReference: heightReference,
1058
+ id: getCandidateDedupeKey(candidate) ?? candidate.sortKey,
1059
+ show: false,
1060
+ });
1061
+ }
1062
+ label.position = position;
1063
+ if (label.heightReference !== heightReference) {
1064
+ label.heightReference = heightReference;
1065
+ }
1066
+ return label;
1067
+ }
1068
+
1069
+ export default MvtLabelManager;