leaflet-city-mapper 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (819) hide show
  1. package/README.md +22 -26
  2. package/cucumber.mjs +1 -1
  3. package/dist/leaflet-city-mapper-src.js +15326 -0
  4. package/dist/leaflet-city-mapper-src.js.map +7 -0
  5. package/dist/leaflet-city-mapper.js +4 -3
  6. package/dist/leaflet-city-mapper.js.map +4 -4
  7. package/libs/leaflet-lens.js +122 -0
  8. package/libs/leaflet.js +76 -0
  9. package/libs/openlayers-bindings.js +1128 -0
  10. package/libs/openlayers-bindings.min.js +99 -0
  11. package/libs/openlayers-bindings.min.js.map +7 -0
  12. package/package.json +4 -3
  13. package/src/archives/decodeDirectory.js +43 -25
  14. package/src/archives/decodeHeader.js +15 -11
  15. package/src/archives/decompress.js +7 -2
  16. package/src/archives/findDirectoryEntry.js +9 -0
  17. package/src/archives/findTile.js +31 -0
  18. package/src/archives/getDirectoryEntries.js +18 -0
  19. package/src/archives/getHeader.js +7 -3
  20. package/src/archives/getTileData.js +13 -0
  21. package/src/archives/getZxy.js +7 -63
  22. package/src/archives/loadSource.js +24 -10
  23. package/src/archives/read.js +12 -9
  24. package/src/archives/tileId.js +7 -3
  25. package/src/archives/varint.js +7 -3
  26. package/src/camera/angles.js +12 -4
  27. package/src/camera/animationPoint.js +4 -1
  28. package/src/camera/cameraMapReady.js +4 -1
  29. package/src/camera/cancelCameraAnimation.js +11 -7
  30. package/src/camera/cleanupCameraMap.js +7 -4
  31. package/src/camera/fitCameraBounds.js +33 -23
  32. package/src/camera/getBearing.js +5 -0
  33. package/src/camera/getPitch.js +5 -0
  34. package/src/camera/groundBounds.js +13 -6
  35. package/src/camera/initializeCameraMap.js +8 -3
  36. package/src/camera/mapAnimateCamera.js +20 -13
  37. package/src/camera/mapCamera.js +22 -42
  38. package/src/camera/mapContainerPointToLayerPoint.js +4 -2
  39. package/src/camera/mapGetBearing.js +4 -1
  40. package/src/camera/mapGetBounds.js +12 -6
  41. package/src/camera/mapGetBoundsCenterZoom.js +6 -3
  42. package/src/camera/mapGetBoundsZoom.js +17 -7
  43. package/src/camera/mapGetCenterLayerPoint.js +3 -2
  44. package/src/camera/mapGetPitch.js +4 -1
  45. package/src/camera/mapLayerPointToContainerPoint.js +3 -2
  46. package/src/camera/mapLimitCenter.js +12 -7
  47. package/src/camera/mapLimitOffset.js +6 -2
  48. package/src/camera/mapPanBy.js +3 -2
  49. package/src/camera/mapPanInside.js +16 -10
  50. package/src/camera/mapResetNorth.js +4 -1
  51. package/src/camera/mapResetNorthPitch.js +4 -1
  52. package/src/camera/mapSetBearing.js +3 -1
  53. package/src/camera/mapSetPitch.js +3 -1
  54. package/src/camera/mapSetPitchAndBearing.js +19 -11
  55. package/src/camera/mapSetZoomAround.js +12 -8
  56. package/src/camera/mapStopPitchBearingAnimation.js +3 -3
  57. package/src/camera/mapTryAnimatedPan.js +3 -2
  58. package/src/camera/mapUpdateCameraOverlays.js +3 -2
  59. package/src/camera/pointOf.js +4 -2
  60. package/src/camera/project.js +23 -16
  61. package/src/camera/runCameraAnimations.js +15 -12
  62. package/src/camera/scheduleCameraAnimation.js +9 -4
  63. package/src/camera/updateSky.js +20 -14
  64. package/src/cog/decodeCogTile.js +24 -0
  65. package/src/cog/finiteCogValues.js +5 -0
  66. package/src/cog/getCogAssetEntry.js +15 -0
  67. package/src/cog/getCogBase.js +10 -0
  68. package/src/cog/getCogHeader.js +3 -0
  69. package/src/cog/getCogProfile.js +16 -0
  70. package/src/cog/getCogTile.js +12 -0
  71. package/src/cog/getColorTile.js +25 -0
  72. package/src/cog/getElevationTile.js +16 -0
  73. package/src/cog/hasCogProjection.js +9 -0
  74. package/src/cog/initCog.js +7 -0
  75. package/src/cog/invalidCogFullResponse.js +3 -0
  76. package/src/cog/openCog.js +30 -0
  77. package/src/cog/openCogAsset.js +14 -0
  78. package/src/cog/readCog.js +25 -0
  79. package/src/cog/readCogBlock.js +8 -0
  80. package/src/cog/readCogBody.js +20 -0
  81. package/src/cog/readCogDirectories.js +20 -0
  82. package/src/cog/readCogDirectory.js +21 -0
  83. package/src/cog/readCogLevel.js +27 -0
  84. package/src/cog/readCogTag.js +15 -0
  85. package/src/cog/validCogDimensions.js +6 -0
  86. package/src/cog/validCogEncoding.js +5 -0
  87. package/src/cog/validCogGeoArrays.js +8 -0
  88. package/src/cog/validCogGrid.js +9 -0
  89. package/src/cog/validCogTileCoordinates.js +4 -0
  90. package/src/cog/validateCogContainer.js +9 -0
  91. package/src/cog/validateCogContentRange.js +8 -0
  92. package/src/cog/validateCogOffsets.js +10 -0
  93. package/src/cog/validateCogRange.js +7 -0
  94. package/src/cog/validateCogResponse.js +15 -0
  95. package/src/collision/collider.js +13 -20
  96. package/src/collision/hiddenLightHit.js +8 -0
  97. package/src/collision/indexTriangle.js +11 -0
  98. package/src/collision/intersectMeshes.js +32 -133
  99. package/src/collision/localRay.js +21 -0
  100. package/src/collision/mergeHits.js +11 -0
  101. package/src/collision/rayBounds.js +19 -0
  102. package/src/collision/readTriangle.js +20 -0
  103. package/src/collision/sortHits.js +5 -11
  104. package/src/collision/transformTriangle.js +9 -0
  105. package/src/collision/triangleDistance.js +21 -0
  106. package/src/collision/worldHit.js +18 -0
  107. package/src/controls/addCameraHandler.js +9 -0
  108. package/src/controls/adjustCameraDrag.js +7 -2
  109. package/src/controls/cameraControls.js +53 -22
  110. package/src/controls/cameraDragClick.js +3 -2
  111. package/src/controls/cameraDragContextMenu.js +3 -2
  112. package/src/controls/cameraDragDown.js +20 -17
  113. package/src/controls/cameraDragEnd.js +3 -2
  114. package/src/controls/cameraDragMove.js +11 -6
  115. package/src/controls/changeCameraTouch.js +5 -2
  116. package/src/controls/cleanupCameraTouch.js +21 -16
  117. package/src/controls/compassAddHooks.js +13 -10
  118. package/src/controls/compassOrientation.js +2 -1
  119. package/src/controls/containerResizeAddHooks.js +3 -3
  120. package/src/controls/dragCamera.js +18 -14
  121. package/src/controls/endAllCameraDrags.js +4 -2
  122. package/src/controls/endAllCameraTouches.js +4 -2
  123. package/src/controls/endCameraTouch.js +3 -2
  124. package/src/controls/endCameraTouchEvent.js +5 -2
  125. package/src/controls/failCompassPermission.js +4 -0
  126. package/src/controls/finishCompassPermission.js +10 -9
  127. package/src/controls/loadCameraControls.js +2 -2
  128. package/src/controls/moveCameraTouch.js +16 -9
  129. package/src/controls/pitchDragAddHooks.js +3 -1
  130. package/src/controls/refreshRotateControl.js +9 -6
  131. package/src/controls/removeCameraDrag.js +7 -4
  132. package/src/controls/rotateButtonClick.js +8 -4
  133. package/src/controls/rotateButtonKeydown.js +8 -4
  134. package/src/controls/rotateControl.js +3 -2
  135. package/src/controls/rotateOnAdd.js +32 -28
  136. package/src/controls/shiftRotateAddHooks.js +6 -4
  137. package/src/controls/shiftRotateWheel.js +3 -1
  138. package/src/controls/startCameraTouch.js +32 -22
  139. package/src/core/addImageState.js +6 -5
  140. package/src/core/addRasterImage.js +4 -2
  141. package/src/core/adjustCameraMarkerPan.js +24 -18
  142. package/src/core/beforeNativeRender.js +1 -1
  143. package/src/core/boundsQuad.js +7 -6
  144. package/src/core/bringNativeLayerToBack.js +6 -1
  145. package/src/core/bringNativeLayerToFront.js +6 -1
  146. package/src/core/bypassNativeEvent.js +11 -0
  147. package/src/core/cameraCircleBounds.js +3 -2
  148. package/src/core/cameraMarkerDrag.js +16 -13
  149. package/src/core/cameraMarkerOnDrag.js +7 -2
  150. package/src/core/cancelGridFade.js +10 -6
  151. package/src/core/closestCameraLayerPoint.js +3 -2
  152. package/src/core/current.js +4 -1
  153. package/src/core/disposeNativeLayer.js +6 -2
  154. package/src/core/fireRasterLoad.js +3 -2
  155. package/src/core/forwardNativeError.js +2 -2
  156. package/src/core/gridlayerGetEvents.js +7 -4
  157. package/src/core/gridlayerGetTiledPixelBounds.js +8 -4
  158. package/src/core/handleNativeMapEvent.js +16 -36
  159. package/src/core/hideTargets.js +6 -4
  160. package/src/core/initNativeGPU.js +10 -6
  161. package/src/core/initializeGridContainer.js +3 -2
  162. package/src/core/initializeNativeLayer.js +16 -18
  163. package/src/core/layerCallInitHooks.js +14 -0
  164. package/src/core/localPixelForGeometry.js +3 -2
  165. package/src/core/localPosition.js +8 -4
  166. package/src/core/markerCameraIconPoint.js +9 -6
  167. package/src/core/markerGetEvents.js +6 -2
  168. package/src/core/markerImageBounds.js +11 -0
  169. package/src/core/markerInitInteraction.js +4 -2
  170. package/src/core/markerQuadCorners.js +41 -24
  171. package/src/core/markerSetIcon.js +5 -2
  172. package/src/core/markerSetPos.js +10 -5
  173. package/src/core/markerSetRotation.js +9 -7
  174. package/src/core/markerUpdateZIndex.js +9 -5
  175. package/src/core/nativeEventSource.js +18 -0
  176. package/src/core/nativeEvents.js +8 -3
  177. package/src/core/nativeImageError.js +8 -3
  178. package/src/core/nativeImageRefresh.js +6 -2
  179. package/src/core/nativeLayer.js +24 -21
  180. package/src/core/nativeLayerMethod.js +8 -3
  181. package/src/core/popupAdjustPan.js +24 -18
  182. package/src/core/popupGetEvents.js +5 -2
  183. package/src/core/popupUpdatePosition.js +5 -2
  184. package/src/core/pruneNativeResources.js +20 -0
  185. package/src/core/putNativeMesh.js +11 -8
  186. package/src/core/quadNativeMesh.js +9 -4
  187. package/src/core/readyNativeGPU.js +4 -1
  188. package/src/core/redrawPath.js +6 -0
  189. package/src/core/refreshNativeLayer.js +11 -6
  190. package/src/core/refreshNativeLayerContract.js +6 -1
  191. package/src/core/rejectNativeReady.js +1 -0
  192. package/src/core/removeImageState.js +4 -3
  193. package/src/core/removeLayer.js +22 -0
  194. package/src/core/removeNativeEvents.js +2 -1
  195. package/src/core/removeTargets.js +6 -2
  196. package/src/core/reorderNativeLayer.js +4 -1
  197. package/src/core/resolveNativeReady.js +1 -0
  198. package/src/core/runGridFades.js +11 -6
  199. package/src/core/runMarkerPanFrame.js +6 -4
  200. package/src/core/scheduleGridFade.js +10 -5
  201. package/src/core/scheduleMarkerPan.js +7 -4
  202. package/src/core/setRotation.js +5 -0
  203. package/src/core/styleNativeMesh.js +5 -1
  204. package/src/core/syncGridLayer.js +10 -3
  205. package/src/core/syncMarker.js +4 -2
  206. package/src/core/syncVectorLayer.js +12 -9
  207. package/src/core/synchronizeNativeLayer.js +8 -17
  208. package/src/core/textureFor.js +41 -43
  209. package/src/core/tooltipGetEvents.js +5 -2
  210. package/src/core/tooltipSetPosition.js +5 -2
  211. package/src/core/transformNativePoint.js +7 -0
  212. package/src/core/updateGridOpacity.js +7 -3
  213. package/src/core/updateNativeHover.js +7 -0
  214. package/src/core/updateNativeLayerView.js +4 -1
  215. package/src/core/uploadCanvasTexture.js +18 -15
  216. package/src/core/uploadNativeImage.js +13 -0
  217. package/src/geometry/addBridges.js +29 -88
  218. package/src/geometry/below.js +1 -1
  219. package/src/geometry/box.js +6 -1
  220. package/src/geometry/bridgeEdge.js +11 -0
  221. package/src/geometry/bridgeElevation.js +3 -1
  222. package/src/geometry/bridgeFaces.js +15 -0
  223. package/src/geometry/bridgeLocal.js +3 -2
  224. package/src/geometry/bridgePaths.js +11 -0
  225. package/src/geometry/bridgePolygon.js +31 -0
  226. package/src/geometry/bridgeSides.js +11 -0
  227. package/src/geometry/build.js +10 -6
  228. package/src/geometry/circleAt.js +4 -2
  229. package/src/geometry/circleGeometry.js +34 -0
  230. package/src/geometry/clipLine.js +1 -1
  231. package/src/geometry/clipSegment.js +11 -7
  232. package/src/geometry/computeBounds.js +9 -4
  233. package/src/geometry/conformModelToTerrain.js +17 -12
  234. package/src/geometry/cross.js +5 -1
  235. package/src/geometry/dashValues.js +14 -0
  236. package/src/geometry/dashedSegment.js +16 -0
  237. package/src/geometry/diskAt.js +4 -2
  238. package/src/geometry/emitter.js +2 -2
  239. package/src/geometry/indexBridge.js +29 -0
  240. package/src/geometry/lampPostGeometry.js +12 -6
  241. package/src/geometry/lampRing.js +9 -6
  242. package/src/geometry/lightGeometry.js +2 -2
  243. package/src/geometry/line.js +21 -54
  244. package/src/geometry/lineJoin.js +26 -0
  245. package/src/geometry/nativeGeometry.js +10 -44
  246. package/src/geometry/polygon.js +4 -3
  247. package/src/geometry/quad.js +8 -3
  248. package/src/geometry/roofCoverage.js +23 -52
  249. package/src/geometry/roofFootprint.js +29 -0
  250. package/src/geometry/segment.js +2 -1
  251. package/src/geometry/setVertexColor.js +3 -1
  252. package/src/geometry/sub.js +2 -2
  253. package/src/geometry/subtractRoofTile.js +19 -0
  254. package/src/geometry/surface.js +2 -1
  255. package/src/geometry/treeGeometry.js +5 -6
  256. package/src/geometry/treeRing.js +9 -8
  257. package/src/geometry/triangle.js +8 -7
  258. package/src/geometry/validateTree.js +7 -0
  259. package/src/geometry/vertexNormals.js +10 -16
  260. package/src/geometry/visit.js +2 -1
  261. package/src/{constants → globals}/CELL.js +0 -1
  262. package/src/globals/Compass.js +1 -0
  263. package/src/globals/ContainerResize.js +1 -0
  264. package/src/{constants → globals}/HEIGHT.js +1 -1
  265. package/src/globals/L.js +1 -0
  266. package/src/globals/PitchDrag.js +1 -0
  267. package/src/globals/ShiftRotate.js +1 -0
  268. package/src/globals/TouchMode.js +1 -0
  269. package/src/globals/alphaBlend.js +12 -0
  270. package/src/globals/archiveDecoder.js +1 -0
  271. package/src/globals/archiveNorthWest.js +1 -0
  272. package/src/globals/archiveSouthEast.js +1 -0
  273. package/src/globals/atmosphereColor.js +1 -0
  274. package/src/globals/atmosphereStops.js +22 -0
  275. package/src/globals/blobParts.js +1 -0
  276. package/src/globals/boundsMethods.js +1 -0
  277. package/src/globals/cameraAngles.js +1 -0
  278. package/src/globals/cameraAnimatedOptions.js +3 -0
  279. package/src/globals/cameraAnimationFrame.js +1 -0
  280. package/src/globals/cameraAnimations.js +1 -0
  281. package/src/globals/cameraBearingSensitivity.js +1 -0
  282. package/src/globals/cameraByMap.js +1 -0
  283. package/src/globals/cameraDragSensitivity.js +1 -0
  284. package/src/globals/cameraDrags.js +1 -0
  285. package/src/globals/cameraEmptyOptions.js +1 -0
  286. package/src/globals/cameraFocusOptions.js +3 -0
  287. package/src/globals/cameraFov.js +3 -0
  288. package/src/globals/cameraListenerOptions.js +4 -0
  289. package/src/globals/cameraTouchStates.js +1 -0
  290. package/src/globals/cameraZeroPadding.js +1 -0
  291. package/src/globals/closestMethods.js +1 -0
  292. package/src/globals/cogTags.js +1 -0
  293. package/src/{constants → globals}/colliders.js +0 -1
  294. package/src/globals/colorLayout.js +8 -0
  295. package/src/globals/coreEventTypes.js +4 -0
  296. package/src/globals/coreMatrixKeys.js +4 -0
  297. package/src/globals/coreQuadIndices.js +1 -0
  298. package/src/globals/coreQuadUV.js +1 -0
  299. package/src/globals/coreSampler.js +4 -0
  300. package/src/globals/coreWhite.js +1 -0
  301. package/src/globals/cosObliquity.js +3 -0
  302. package/src/globals/coverageTiles.js +1 -0
  303. package/src/globals/defaultMaterial.js +1 -0
  304. package/src/globals/degrees.js +1 -0
  305. package/src/globals/demBuffer.js +4 -0
  306. package/src/globals/demLayout.js +3 -0
  307. package/src/globals/demSize.js +1 -0
  308. package/src/globals/demTarget.js +3 -0
  309. package/src/globals/demTexture.js +5 -0
  310. package/src/globals/depthBindGroup.js +9 -0
  311. package/src/globals/depthTexture.js +5 -0
  312. package/src/globals/directoryReader.js +4 -0
  313. package/src/globals/disabledShadow.js +1 -0
  314. package/src/globals/dragByHandler.js +1 -0
  315. package/src/globals/dragStates.js +1 -0
  316. package/src/globals/drawEntries.js +1 -0
  317. package/src/globals/drawFrameEntry.js +7 -0
  318. package/src/globals/drawMeshEntry.js +7 -0
  319. package/src/globals/drawSamplerEntries.js +18 -0
  320. package/src/globals/drawTerrainEntry.js +4 -0
  321. package/src/globals/drawTextureEntries.js +18 -0
  322. package/src/globals/earthCirc.js +1 -0
  323. package/src/{constants → globals}/elevationWGSL.js +1 -1
  324. package/src/globals/fragmentShader.js +3 -0
  325. package/src/globals/frameBuffer.js +4 -0
  326. package/src/globals/frameCommands.js +1 -0
  327. package/src/globals/frameLayoutEntry.js +7 -0
  328. package/src/globals/geometryDecoder.js +1 -0
  329. package/src/globals/geometryEmpty.js +1 -0
  330. package/src/globals/geometryImageOptions.js +4 -0
  331. package/src/globals/geometryPixelStates.js +1 -0
  332. package/src/globals/geometryQuaternion.js +1 -0
  333. package/src/globals/geometryScale.js +1 -0
  334. package/src/globals/geometrySemantics.js +5 -0
  335. package/src/globals/geometryTranslation.js +1 -0
  336. package/src/globals/gridEvents.js +1 -0
  337. package/src/globals/gridFadeFrame.js +1 -0
  338. package/src/globals/gridInitializers.js +1 -0
  339. package/src/globals/halfRadians.js +1 -0
  340. package/src/globals/headerBounds.js +1 -0
  341. package/src/globals/headerFlags.js +1 -0
  342. package/src/globals/headerOffsets.js +5 -0
  343. package/src/globals/hull.js +10 -0
  344. package/src/globals/imageStates.js +1 -0
  345. package/src/globals/instanceLayout.js +9 -0
  346. package/src/globals/lampDirections.js +8 -0
  347. package/src/globals/layerCallInitHooks.js +1 -0
  348. package/src/globals/layerProto.js +1 -0
  349. package/src/globals/lightScale.js +1 -0
  350. package/src/{constants → globals}/limbs.js +0 -1
  351. package/src/globals/loading.js +1 -0
  352. package/src/globals/mapMethods.js +1 -0
  353. package/src/globals/markerMethods.js +1 -0
  354. package/src/globals/markerPanFrame.js +1 -0
  355. package/src/globals/meshBindGroup.js +4 -0
  356. package/src/globals/meshBuffer.js +4 -0
  357. package/src/globals/meshCopySize.js +1 -0
  358. package/src/globals/meshImage.js +4 -0
  359. package/src/globals/meshLayoutEntry.js +8 -0
  360. package/src/globals/meshOffsets.js +1 -0
  361. package/src/globals/meshPipeline.js +27 -0
  362. package/src/globals/meshStack.js +3 -0
  363. package/src/globals/meshTarget.js +3 -0
  364. package/src/globals/nativeRenderByLayer.js +1 -0
  365. package/src/globals/nextId.js +1 -0
  366. package/src/globals/normalLayout.js +8 -0
  367. package/src/globals/parts.js +24 -0
  368. package/src/globals/pendingGridFades.js +1 -0
  369. package/src/globals/pendingInitializations.js +1 -0
  370. package/src/globals/pendingMapChanges.js +1 -0
  371. package/src/globals/pendingMarkerPan.js +1 -0
  372. package/src/globals/pendingPlacements.js +1 -0
  373. package/src/globals/pendingRasterLoads.js +1 -0
  374. package/src/globals/pendingZoomAnimations.js +1 -0
  375. package/src/globals/pipelineLayout.js +3 -0
  376. package/src/globals/popupEvents.js +1 -0
  377. package/src/globals/popupPan.js +1 -0
  378. package/src/globals/popupPosition.js +1 -0
  379. package/src/globals/positionLayout.js +8 -0
  380. package/src/globals/programEntries.js +1 -0
  381. package/src/globals/programLayout.js +3 -0
  382. package/src/globals/radians.js +1 -0
  383. package/src/globals/rasterBuffer.js +4 -0
  384. package/src/globals/rasterIndices.js +1 -0
  385. package/src/globals/rasterNormals.js +1 -0
  386. package/src/globals/rasterPoint.js +4 -0
  387. package/src/globals/rasterPositions.js +1 -0
  388. package/src/globals/rasterSampler.js +6 -0
  389. package/src/globals/rasterTexture.js +5 -0
  390. package/src/globals/rasterUVs.js +1 -0
  391. package/src/globals/removeLayer.js +1 -0
  392. package/src/globals/renderEmpty.js +1 -0
  393. package/src/globals/rendererDevices.js +1 -0
  394. package/src/globals/ringDirections.js +49 -0
  395. package/src/globals/roofBindGroup.js +17 -0
  396. package/src/globals/roofBlitSampler.js +4 -0
  397. package/src/globals/roofBuffer.js +4 -0
  398. package/src/globals/roofCommands.js +1 -0
  399. package/src/globals/roofCopySize.js +1 -0
  400. package/src/globals/roofImage.js +3 -0
  401. package/src/globals/roofMin.js +4 -0
  402. package/src/globals/roofOpacities.js +1 -0
  403. package/src/globals/roofPass.js +13 -0
  404. package/src/globals/roofPipeline.js +29 -0
  405. package/src/globals/roofSampler.js +4 -0
  406. package/src/globals/roofShader.js +16 -0
  407. package/src/globals/roofSignatures.js +1 -0
  408. package/src/globals/roofSize.js +4 -0
  409. package/src/globals/roofTarget.js +3 -0
  410. package/src/globals/roofTexture.js +5 -0
  411. package/src/globals/roofTiles.js +1 -0
  412. package/src/globals/roundProfile.js +7 -0
  413. package/src/globals/samplerLayoutEntries.js +36 -0
  414. package/src/globals/sceneByLayer.js +1 -0
  415. package/src/globals/sceneCleanupFields.js +1 -0
  416. package/src/globals/sceneEmptyOptions.js +1 -0
  417. package/src/globals/scenePass.js +19 -0
  418. package/src/globals/sceneSunlightUniforms.js +3 -0
  419. package/src/globals/sceneTransferFields.js +1 -0
  420. package/src/globals/sceneWalkHandlers.js +1 -0
  421. package/src/globals/shadowBindGroup.js +10 -0
  422. package/src/globals/shadowBounds.js +4 -0
  423. package/src/globals/shadowCamera.js +15 -0
  424. package/src/globals/shadowDepthLayout.js +9 -0
  425. package/src/globals/shadowHigh.js +1 -0
  426. package/src/globals/shadowInstanceLayouts.js +4 -0
  427. package/src/globals/shadowLayouts.js +3 -0
  428. package/src/globals/shadowLow.js +1 -0
  429. package/src/globals/shadowMeshLayout.js +10 -0
  430. package/src/globals/shadowOffsets.js +1 -0
  431. package/src/globals/shadowPass.js +9 -0
  432. package/src/globals/shadowPipeline.js +24 -0
  433. package/src/globals/shadowPipelineLayout.js +3 -0
  434. package/src/globals/shadowShader.js +3 -0
  435. package/src/globals/shadowTexture.js +5 -0
  436. package/src/globals/shadowValues.js +1 -0
  437. package/src/globals/sinObliquity.js +3 -0
  438. package/src/globals/sizes.js +6 -0
  439. package/src/globals/sunBindGroup.js +20 -0
  440. package/src/globals/sunByMap.js +1 -0
  441. package/src/globals/sunlightByControl.js +1 -0
  442. package/src/globals/tau.js +1 -0
  443. package/src/globals/terrainLayoutEntry.js +8 -0
  444. package/src/globals/textureLayoutEntries.js +41 -0
  445. package/src/globals/tiledBounds.js +1 -0
  446. package/src/globals/tooltipEvents.js +1 -0
  447. package/src/globals/tooltipPosition.js +1 -0
  448. package/src/globals/touchByContainer.js +1 -0
  449. package/src/globals/trafficByLayer.js +1 -0
  450. package/src/globals/trafficClocks.js +1 -0
  451. package/src/globals/trafficEmptyList.js +1 -0
  452. package/src/globals/trafficEmptyOptions.js +1 -0
  453. package/src/globals/trafficRouteMaterial.js +1 -0
  454. package/src/{constants → globals}/trafficShader.js +49 -49
  455. package/src/globals/triangleContexts.js +1 -0
  456. package/src/globals/uVLayout.js +8 -0
  457. package/src/{constants → globals}/vehicles.js +24 -9
  458. package/src/globals/vertexShader.js +3 -0
  459. package/src/globals/walkByMap.js +1 -0
  460. package/src/globals/wantedTiles.js +1 -0
  461. package/src/index.js +27 -25
  462. package/src/lighting/cacheLightGrid.js +14 -5
  463. package/src/lighting/collectLightMeshes.js +4 -1
  464. package/src/lighting/lightGrid.js +9 -8
  465. package/src/lighting/updatePointLights.js +11 -7
  466. package/src/lighting/visitCells.js +4 -11
  467. package/src/lighting/visitLightCells.js +13 -0
  468. package/src/lighting/worldLights.js +10 -12
  469. package/src/lighting/writeLightCell.js +5 -0
  470. package/src/models/applyModelTransform.js +13 -0
  471. package/src/models/buildModelNodes.js +14 -0
  472. package/src/models/createModelContext.js +15 -0
  473. package/src/models/createModelGeometry.js +40 -0
  474. package/src/models/decodeModel.js +9 -6
  475. package/src/models/loadBuffer.js +2 -2
  476. package/src/models/loadImage.js +9 -5
  477. package/src/models/loadModel.js +24 -49
  478. package/src/models/loadModelResources.js +19 -0
  479. package/src/models/materialFor.js +9 -9
  480. package/src/models/modelNode.js +25 -69
  481. package/src/models/nodeMatrix.js +8 -3
  482. package/src/models/normalizeAccessor.js +11 -0
  483. package/src/models/readAccessor.js +11 -31
  484. package/src/models/readAccessorValue.js +7 -0
  485. package/src/models/readAccessorValues.js +10 -6
  486. package/src/models/readModelAttributes.js +20 -0
  487. package/src/models/readModelIndices.js +16 -0
  488. package/src/models/readSparseAccessor.js +19 -0
  489. package/src/models/releaseModelResources.js +10 -0
  490. package/src/models/textureFor.js +9 -6
  491. package/src/models/textureSampler.js +5 -5
  492. package/src/picking/findFeature.js +12 -9
  493. package/src/picking/hit.js +11 -10
  494. package/src/picking/hitColliderCell.js +19 -0
  495. package/src/picking/hitMesh.js +12 -16
  496. package/src/picking/onClick.js +5 -2
  497. package/src/picking/onPointerLeave.js +5 -2
  498. package/src/picking/onPointerMove.js +8 -5
  499. package/src/picking/raycast.js +42 -35
  500. package/src/picking/setHighlight.js +12 -5
  501. package/src/picking/shouldSkipOther.js +4 -1
  502. package/src/picking/showFeature.js +13 -10
  503. package/src/picking/validateCameraInverse.js +8 -0
  504. package/src/raster/addRasterTile.js +39 -84
  505. package/src/raster/comparePendingTiles.js +2 -2
  506. package/src/raster/createGeometry.js +17 -10
  507. package/src/raster/createRasterMesh.js +71 -42
  508. package/src/raster/finishAttachment.js +7 -3
  509. package/src/raster/finishRasterTile.js +54 -40
  510. package/src/raster/getRasterEvents.js +3 -3
  511. package/src/raster/getRasterTileSize.js +5 -3
  512. package/src/raster/initRaster.js +14 -19
  513. package/src/raster/isLoading.js +4 -2
  514. package/src/raster/loadRasterTile.js +10 -7
  515. package/src/raster/onPMTileAdd.js +4 -1
  516. package/src/raster/onPMTileRemove.js +4 -1
  517. package/src/raster/pruneRasterTiles.js +15 -12
  518. package/src/raster/pumpRasterTiles.js +9 -5
  519. package/src/raster/rasterTileRange.js +23 -0
  520. package/src/raster/readyRaster.js +13 -10
  521. package/src/raster/registerTerrainTile.js +12 -9
  522. package/src/raster/releaseRasterTile.js +15 -12
  523. package/src/raster/releaseRasterTiles.js +9 -6
  524. package/src/raster/removeRasterTile.js +6 -3
  525. package/src/raster/reportError.js +3 -3
  526. package/src/raster/retainRasterTiles.js +15 -0
  527. package/src/raster/setRasterOpacity.js +5 -2
  528. package/src/raster/setRasterTerrain.js +10 -6
  529. package/src/raster/setRasterZIndex.js +5 -2
  530. package/src/raster/terrainTileGeometry.js +16 -0
  531. package/src/raster/updateAttachedTiles.js +5 -2
  532. package/src/raster/updateRasterTiles.js +29 -37
  533. package/src/rendering/bindMeshTextures.js +50 -0
  534. package/src/rendering/collectFrameMeshes.js +17 -10
  535. package/src/rendering/collectMeshes.js +2 -24
  536. package/src/rendering/collectRoofTiles.js +15 -0
  537. package/src/rendering/collectVisibleMesh.js +27 -0
  538. package/src/rendering/compareMeshDepth.js +6 -0
  539. package/src/rendering/compareMeshes.js +8 -10
  540. package/src/rendering/compareRoofTiles.js +4 -4
  541. package/src/rendering/composeRoofAtlas.js +53 -36
  542. package/src/rendering/createMesh.js +22 -11
  543. package/src/rendering/createProgram.js +47 -64
  544. package/src/rendering/createProgramLayout.js +36 -0
  545. package/src/rendering/createProgramUniforms.js +17 -0
  546. package/src/rendering/destroyAfterSubmission.js +8 -8
  547. package/src/rendering/destroyTexture.js +4 -1
  548. package/src/rendering/drawGeometry.js +18 -106
  549. package/src/rendering/drawPipeline.js +34 -0
  550. package/src/rendering/drawSceneMeshes.js +14 -17
  551. package/src/rendering/ensureRoofBlit.js +14 -34
  552. package/src/rendering/prepareFrameBuffer.js +17 -0
  553. package/src/rendering/prepareFrameMeshes.js +6 -11
  554. package/src/rendering/prepareFrameUniforms.js +7 -12
  555. package/src/rendering/prepareMeshCutout.js +12 -0
  556. package/src/rendering/prepareMeshTextures.js +23 -0
  557. package/src/rendering/prepareMeshUniforms.js +25 -0
  558. package/src/rendering/rebuildRoofAtlas.js +41 -56
  559. package/src/rendering/render.js +25 -13
  560. package/src/rendering/reportCompilation.js +6 -6
  561. package/src/rendering/resizeRenderer.js +19 -14
  562. package/src/rendering/resizeRoofTexture.js +24 -0
  563. package/src/rendering/revealRoofMesh.js +15 -0
  564. package/src/rendering/synchronizeZoomView.js +10 -18
  565. package/src/rendering/textureBinding.js +7 -7
  566. package/src/rendering/updateMapCamera.js +30 -16
  567. package/src/rendering/updateRoofAtlas.js +20 -0
  568. package/src/rendering/updateRoofRaster.js +12 -19
  569. package/src/rendering/updateZoomCamera.js +18 -0
  570. package/src/rendering/uploadMeshTexture.js +26 -0
  571. package/src/rendering/uploadRoofTile.js +23 -0
  572. package/src/scene/addSceneLayer.js +17 -0
  573. package/src/scene/attach.js +54 -161
  574. package/src/scene/attachLayer.js +5 -2
  575. package/src/scene/callLayer.js +26 -0
  576. package/src/scene/cancelUpdate.js +6 -3
  577. package/src/scene/composeLocalTransform.js +16 -0
  578. package/src/scene/createLayer.js +7 -0
  579. package/src/scene/createSceneCamera.js +21 -0
  580. package/src/scene/emptyEvents.js +1 -1
  581. package/src/scene/emptyNode.js +8 -7
  582. package/src/scene/endZoom.js +13 -6
  583. package/src/scene/failAttachment.js +6 -3
  584. package/src/scene/get3DEvents.js +12 -9
  585. package/src/scene/getLocation.js +7 -0
  586. package/src/scene/init3D.js +28 -15
  587. package/src/scene/initializeLayer.js +11 -5
  588. package/src/scene/initializeRendererResources.js +35 -0
  589. package/src/scene/initializeSharedRenderer.js +45 -0
  590. package/src/scene/initializerFor.js +3 -1
  591. package/src/scene/isNativeLayer.js +12 -0
  592. package/src/scene/layerCountTitle.js +4 -0
  593. package/src/scene/layerInitialize.js +24 -14
  594. package/src/scene/layerLayerAdd.js +31 -9
  595. package/src/scene/mountRenderer.js +25 -0
  596. package/src/scene/onAdd3DLayer.js +16 -12
  597. package/src/scene/onMapChange.js +8 -6
  598. package/src/scene/onRemove3DLayer.js +30 -36
  599. package/src/scene/onZoomAnim.js +8 -6
  600. package/src/scene/placeEntry.js +3 -1
  601. package/src/scene/placeEntryElement.js +22 -0
  602. package/src/scene/ready.js +9 -0
  603. package/src/scene/ready3D.js +28 -18
  604. package/src/scene/releaseRenderer.js +1 -1
  605. package/src/scene/releaseSharedScene.js +25 -0
  606. package/src/scene/removeEntry.js +2 -0
  607. package/src/scene/removeLayerEvents.js +9 -0
  608. package/src/scene/removeSceneLayer.js +15 -0
  609. package/src/scene/renderLayerCount.js +13 -0
  610. package/src/scene/renderPendingMapChange.js +8 -4
  611. package/src/scene/renderPendingUpdates.js +8 -4
  612. package/src/scene/renderPendingZoomAnimation.js +7 -3
  613. package/src/scene/rendererDeviceError.js +10 -6
  614. package/src/scene/rendererDeviceLost.js +10 -7
  615. package/src/scene/replaceEntry.js +4 -2
  616. package/src/scene/reportError.js +2 -2
  617. package/src/scene/requestAdapter.js +1 -1
  618. package/src/scene/resolveNextInitialization.js +7 -6
  619. package/src/scene/restoreGeometry.js +23 -0
  620. package/src/scene/restoreMaterialTextures.js +16 -0
  621. package/src/scene/restoreObject.js +22 -58
  622. package/src/scene/runPlacements.js +4 -2
  623. package/src/scene/startZoom.js +4 -1
  624. package/src/scene/underEntry.js +2 -3
  625. package/src/scene/update.js +8 -4
  626. package/src/scene/updateCamera.js +51 -28
  627. package/src/scene/updateLayerCount.js +22 -0
  628. package/src/scene/updateWorldMatrix.js +23 -28
  629. package/src/scene/worldMatrixChanged.js +18 -0
  630. package/src/shaders/materialBaseShader.js +17 -0
  631. package/src/shaders/materialShaders.js +14 -130
  632. package/src/shaders/materialSurfaceShader.js +47 -0
  633. package/src/shaders/materialVertexShader.js +72 -0
  634. package/src/shaders/roofVertexShader.js +9 -0
  635. package/src/shaders/validateRoofMaterial.js +10 -0
  636. package/src/shadows/bindSunlight.js +18 -9
  637. package/src/shadows/drawShadowMeshes.js +24 -14
  638. package/src/shadows/ensureShadowPipeline.js +46 -35
  639. package/src/shadows/meshShadowBounds.js +24 -0
  640. package/src/shadows/renderSunlight.js +10 -8
  641. package/src/shadows/resizeSunlight.js +12 -6
  642. package/src/shadows/shadowBounds.js +10 -19
  643. package/src/shadows/shadowCacheMatches.js +3 -9
  644. package/src/shadows/shadowMatrix.js +36 -26
  645. package/src/shadows/shadowMeshMatches.js +11 -0
  646. package/src/sources/addGeneratedTriangle.js +3 -2
  647. package/src/sources/attachAreaMesh.js +32 -26
  648. package/src/sources/buildArea.js +12 -8
  649. package/src/sources/buildAreaFeature.js +12 -17
  650. package/src/sources/buildAreaPoint.js +4 -4
  651. package/src/sources/buildAreaPolygon.js +3 -3
  652. package/src/sources/compareAreaDistance.js +1 -2
  653. package/src/sources/extrusionStyle.js +10 -0
  654. package/src/sources/featureAnchor.js +9 -0
  655. package/src/sources/generateTreeGeometry.js +5 -3
  656. package/src/sources/initializeGeoJSON.js +4 -2
  657. package/src/sources/instanceAreaGeometry.js +9 -7
  658. package/src/sources/pendingSourceAreas.js +20 -0
  659. package/src/sources/projectRing.js +17 -10
  660. package/src/sources/projectedTree.js +16 -10
  661. package/src/sources/pump.js +16 -26
  662. package/src/sources/releaseArea.js +5 -2
  663. package/src/sources/setGeoJSONData.js +5 -2
  664. package/src/sources/sourceAreaContext.js +16 -6
  665. package/src/sources/updateArea.js +23 -16
  666. package/src/sources/updateStatus.js +5 -2
  667. package/src/sunlight/addTimeLayer.js +4 -1
  668. package/src/sunlight/addTo.js +1 -0
  669. package/src/sunlight/atmosphere.js +7 -10
  670. package/src/sunlight/createSun.js +54 -0
  671. package/src/sunlight/horizontalPosition.js +8 -8
  672. package/src/sunlight/initSunlight.js +3 -0
  673. package/src/sunlight/initialize.js +7 -4
  674. package/src/sunlight/mix.js +4 -3
  675. package/src/sunlight/moonPosition.js +10 -9
  676. package/src/sunlight/onAddSun.js +27 -66
  677. package/src/sunlight/onRemoveSun.js +10 -0
  678. package/src/sunlight/projectCelestialBody.js +5 -5
  679. package/src/sunlight/remove.js +1 -0
  680. package/src/sunlight/removeSun.js +9 -3
  681. package/src/sunlight/removeTimeLayer.js +5 -1
  682. package/src/sunlight/render.js +4 -2
  683. package/src/sunlight/rgb.js +6 -4
  684. package/src/sunlight/solarPosition.js +10 -9
  685. package/src/sunlight/solarTime.js +11 -0
  686. package/src/sunlight/styleTimeControl.js +3 -3
  687. package/src/sunlight/updateCelestialDisc.js +12 -0
  688. package/src/sunlight/updateSky.js +12 -15
  689. package/src/sunlight/updateSun.js +10 -4
  690. package/src/sunlight/useSelectedTime.js +7 -4
  691. package/src/terrain/applyTerrain.js +21 -0
  692. package/src/terrain/clearLayerTerrain.js +8 -5
  693. package/src/terrain/copyTerrainTile.js +12 -0
  694. package/src/terrain/getElevation.js +7 -3
  695. package/src/terrain/initTerrain.js +12 -9
  696. package/src/terrain/loadTerrain.js +25 -45
  697. package/src/terrain/loadTerrainTiles.js +7 -3
  698. package/src/terrain/onTerrainAdd.js +10 -6
  699. package/src/terrain/onTerrainChange.js +5 -2
  700. package/src/terrain/onTerrainRemove.js +22 -18
  701. package/src/terrain/rasterProgram.js +51 -0
  702. package/src/terrain/readBridges.js +1 -1
  703. package/src/terrain/setLayerTerrain.js +8 -5
  704. package/src/terrain/setTerrainHeight.js +9 -5
  705. package/src/terrain/terrainAtlas.js +7 -13
  706. package/src/terrain/terrainBuffers.js +27 -0
  707. package/src/terrain/terrainElevation.js +5 -10
  708. package/src/terrain/terrainGrid.js +19 -11
  709. package/src/terrain/terrainTileQueue.js +25 -0
  710. package/src/traffic/addTraffic.js +6 -3
  711. package/src/traffic/along.js +8 -2
  712. package/src/traffic/appendRouteDash.js +15 -0
  713. package/src/traffic/appendRouteSegment.js +15 -0
  714. package/src/traffic/destroyTrafficGpu.js +4 -2
  715. package/src/traffic/disposeTrafficObject.js +5 -2
  716. package/src/traffic/drawTrafficRoute.js +5 -2
  717. package/src/traffic/failTraffic.js +2 -2
  718. package/src/traffic/fetchTrafficLanes.js +4 -4
  719. package/src/traffic/groundTraffic.js +5 -1
  720. package/src/traffic/initTraffic.js +60 -48
  721. package/src/traffic/loadTraffic.js +9 -9
  722. package/src/traffic/locateTraffic.js +7 -5
  723. package/src/traffic/moveTraffic.js +2 -2
  724. package/src/traffic/prepareTraffic.js +11 -6
  725. package/src/traffic/rebaseTraffic.js +32 -30
  726. package/src/traffic/rebuildTrafficMesh.js +9 -5
  727. package/src/traffic/refreshTrafficTrips.js +32 -0
  728. package/src/traffic/removeTraffic.js +16 -13
  729. package/src/traffic/routeColor.js +3 -3
  730. package/src/traffic/routeGeometry.js +11 -21
  731. package/src/traffic/scheduledTrips.js +22 -11
  732. package/src/traffic/tickTraffic.js +9 -40
  733. package/src/traffic/toLanes.js +16 -8
  734. package/src/traffic/tooltip.js +4 -6
  735. package/src/traffic/trafficBounds.js +6 -2
  736. package/src/traffic/trafficNow.js +9 -3
  737. package/src/traffic/trafficStatusText.js +5 -0
  738. package/src/traffic/trafficStorage.js +2 -2
  739. package/src/traffic/tripsAt.js +4 -4
  740. package/src/traffic/updateTraffic.js +4 -1
  741. package/src/traffic/updateTrafficLights.js +16 -0
  742. package/src/traffic/updateTrafficPose.js +8 -0
  743. package/src/traffic/uploadTrafficLanes.js +21 -0
  744. package/src/traffic/vehicleOffsets.js +3 -2
  745. package/src/triangulation/clean.js +1 -1
  746. package/src/triangulation/clipEars.js +23 -0
  747. package/src/triangulation/connectHole.js +18 -0
  748. package/src/triangulation/mergeHoles.js +11 -0
  749. package/src/triangulation/minimumX.js +3 -3
  750. package/src/triangulation/polygonRings.js +14 -0
  751. package/src/triangulation/sortHoles.js +7 -12
  752. package/src/triangulation/triangulate.js +18 -56
  753. package/src/triangulation/validateArea.js +10 -0
  754. package/src/utils/parseColor.js +4 -4
  755. package/src/vehicles/bicycleModel.js +21 -20
  756. package/src/vehicles/boatBenches.js +3 -2
  757. package/src/vehicles/boatModel.js +25 -17
  758. package/src/vehicles/carModel.js +26 -10
  759. package/src/vehicles/carriage.js +17 -16
  760. package/src/vehicles/metroModel.js +1 -1
  761. package/src/vehicles/mirror.js +3 -3
  762. package/src/vehicles/pedestrianModel.js +15 -14
  763. package/src/vehicles/tramModel.js +1 -1
  764. package/src/walk/blocked.js +4 -4
  765. package/src/walk/createWalk.js +66 -60
  766. package/src/walk/initWalk.js +1 -0
  767. package/src/walk/initialize.js +1 -0
  768. package/src/walk/land.js +32 -0
  769. package/src/walk/local.js +15 -7
  770. package/src/walk/moveWalker.js +23 -0
  771. package/src/walk/onAdd.js +25 -0
  772. package/src/walk/onKey.js +12 -9
  773. package/src/walk/onPointer.js +17 -12
  774. package/src/walk/onRemove.js +9 -1
  775. package/src/walk/place.js +4 -2
  776. package/src/walk/start.js +19 -10
  777. package/src/walk/step.js +21 -29
  778. package/src/walk/stepWalkerHeight.js +11 -0
  779. package/src/walk/stop.js +7 -4
  780. package/src/walk/updateWalkerView.js +22 -0
  781. package/src/constants/Compass.js +0 -7
  782. package/src/constants/ContainerResize.js +0 -7
  783. package/src/constants/PitchDrag.js +0 -7
  784. package/src/constants/ShiftRotate.js +0 -7
  785. package/src/constants/TouchMode.js +0 -6
  786. package/src/constants/accessorSizes.js +0 -1
  787. package/src/constants/attachState.js +0 -1
  788. package/src/constants/cameraControlsState.js +0 -1
  789. package/src/constants/cityMapper.js +0 -6
  790. package/src/constants/hull.js +0 -1
  791. package/src/constants/indexState.js +0 -1
  792. package/src/constants/mapCameraState.js +0 -1
  793. package/src/constants/nativeLayerState.js +0 -1
  794. package/src/constants/onMapChangeState.js +0 -1
  795. package/src/constants/onZoomAnimState.js +0 -1
  796. package/src/constants/parts.js +0 -19
  797. package/src/constants/pumpState.js +0 -1
  798. package/src/constants/ringDirections.js +0 -10
  799. package/src/constants/roundProfile.js +0 -1
  800. package/src/constants/underEntryState.js +0 -1
  801. /package/src/{constants → globals}/TILE_RADIUS.js +0 -0
  802. /package/src/{constants → globals}/TILE_SIZE.js +0 -0
  803. /package/src/{constants → globals}/dark.js +0 -0
  804. /package/src/{constants → globals}/glass.js +0 -0
  805. /package/src/{constants → globals}/headlight.js +0 -0
  806. /package/src/{constants → globals}/moves.js +0 -0
  807. /package/src/{constants → globals}/nativeEventMaps.js +0 -0
  808. /package/src/{constants → globals}/nativeMethodHandlers.js +0 -0
  809. /package/src/{constants → globals}/paints.js +0 -0
  810. /package/src/{constants → globals}/pendingUpdates.js +0 -0
  811. /package/src/{constants → globals}/renderers.js +0 -0
  812. /package/src/{constants → globals}/shirt.js +0 -0
  813. /package/src/{constants → globals}/skin.js +0 -0
  814. /package/src/{constants → globals}/speed.js +0 -0
  815. /package/src/{constants → globals}/taillight.js +0 -0
  816. /package/src/{constants → globals}/trousers.js +0 -0
  817. /package/src/{constants/accessorTypes.js → globals/types.js} +0 -0
  818. /package/src/{constants → globals}/tyre.js +0 -0
  819. /package/src/{constants → globals}/white.js +0 -0
@@ -0,0 +1,27 @@
1
+ import { demBuffer } from '../globals/demBuffer.js';
2
+ import { sceneByLayer } from '../globals/sceneByLayer.js';
3
+ import { terrainGrid } from './terrainGrid.js';
4
+
5
+ export function terrainBuffers(backend, divisions) {
6
+ const state = sceneByLayer.get(backend), device = state.renderer.device;
7
+ let attributes = state._terrainGrids.get(divisions);
8
+ if (!attributes) {
9
+ attributes = terrainGrid(divisions);
10
+ let name, attribute;
11
+ for ([name, attribute] of Object.entries(attributes)) {
12
+ attribute.size ||= 1;
13
+ attribute.count = attribute.data.length / attribute.size;
14
+ attribute.indexFormat = 'uint16';
15
+ attribute.buffer = device.createBuffer((
16
+ demBuffer.size = Math.max(4, attribute.data.byteLength),
17
+ demBuffer.usage = name === 'index'
18
+ ? GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST
19
+ : GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
20
+ demBuffer
21
+ ));
22
+ device.queue.writeBuffer(attribute.buffer, 0, attribute.data);
23
+ }
24
+ state._terrainGrids.set(divisions, attributes);
25
+ }
26
+ return attributes;
27
+ }
@@ -6,15 +6,10 @@ export function terrainElevation(point, tiles) {
6
6
  const x = point.x - 0.5, y = point.y - 0.5;
7
7
  const x0 = Math.floor(x), y0 = Math.floor(y);
8
8
  const fx = x - x0, fy = y - y0;
9
- const values = [sample(tiles, x0, y0), sample(tiles, x0 + 1, y0), sample(tiles, x0, y0 + 1), sample(tiles, x0 + 1, y0 + 1)];
10
- let valid = 0, first = null;
11
- let value;
12
- for (value of values) {
13
- if (!Number.isFinite(value)) continue;
14
- if (!valid) first = value;
15
- valid++;
9
+ const a = sample(tiles, x0, y0), b = sample(tiles, x0 + 1, y0);
10
+ const c = sample(tiles, x0, y0 + 1), d = sample(tiles, x0 + 1, y0 + 1);
11
+ if (!Number.isFinite(a) || !Number.isFinite(b) || !Number.isFinite(c) || !Number.isFinite(d)) {
12
+ return Number.isFinite(a) ? a : Number.isFinite(b) ? b : Number.isFinite(c) ? c : Number.isFinite(d) ? d : null;
16
13
  }
17
- if (valid < 4) return first;
18
- return (values[0] * (1 - fx) + values[1] * fx) * (1 - fy) +
19
- (values[2] * (1 - fx) + values[3] * fx) * fy;
14
+ return (a * (1 - fx) + b * fx) * (1 - fy) + (c * (1 - fx) + d * fx) * fy;
20
15
  }
@@ -1,24 +1,32 @@
1
1
  /** Unit tile grid; the vertex shader supplies the elevation. */
2
2
 
3
3
  export function terrainGrid(divisions) {
4
- const positions = [], normals = [], uvs = [], indices = [];
5
- let row, column, a, b, c, d;
4
+ const vertices = (divisions + 1) ** 2;
5
+ const positions = /* alloc */ new Float32Array(vertices * 3);
6
+ const normals = /* alloc */ new Float32Array(vertices * 3);
7
+ const uvs = /* alloc */ new Float32Array(vertices * 2);
8
+ const indices = /* alloc */ new Uint16Array(divisions * divisions * 6);
9
+ let row, column, a, b, c, d, vertex = 0, index = 0;
6
10
  for (row = 0; row <= divisions; row++) {
7
11
  for (column = 0; column <= divisions; column++) {
8
- positions.push(column / divisions, 0, row / divisions);
9
- normals.push(0, 1, 0);
10
- uvs.push(column / divisions, row / divisions);
12
+ positions[vertex * 3] = column / divisions;
13
+ positions[vertex * 3 + 2] = row / divisions;
14
+ normals[vertex * 3 + 1] = 1;
15
+ uvs[vertex * 2] = column / divisions;
16
+ uvs[vertex * 2 + 1] = row / divisions;
17
+ vertex++;
11
18
  if (row < divisions && column < divisions) {
12
19
  a = row * (divisions + 1) + column;
13
20
  b = a + 1, c = a + divisions + 1, d = c + 1;
14
- indices.push(a, c, b, b, c, d);
21
+ indices[index++] = a; indices[index++] = c; indices[index++] = b;
22
+ indices[index++] = b; indices[index++] = c; indices[index++] = d;
15
23
  }
16
24
  }
17
25
  }
18
- return {
19
- position: { size: 3, data: new Float32Array(positions) },
20
- normal: { size: 3, data: new Float32Array(normals) },
21
- uv: { size: 2, data: new Float32Array(uvs) },
22
- index: { data: new Uint16Array(indices) },
26
+ return /* alloc */ {
27
+ position: /* alloc */ { size: 3, data: positions },
28
+ normal: /* alloc */ { size: 3, data: normals },
29
+ uv: /* alloc */ { size: 2, data: uvs },
30
+ index: /* alloc */ { data: indices },
23
31
  };
24
32
  }
@@ -0,0 +1,25 @@
1
+ import { L } from '../globals/L.js';
2
+ import { sceneByLayer } from '../globals/sceneByLayer.js';
3
+ import { archiveNorthWest } from '../globals/archiveNorthWest.js';
4
+ import { archiveSouthEast } from '../globals/archiveSouthEast.js';
5
+ import { compareDistance } from '../utils/compareDistance.js';
6
+
7
+ export function terrainTileQueue(backend, header) {
8
+ const scene = sceneByLayer.get(backend), map = backend._map;
9
+ scene._terrainZoom = header.maxZoom;
10
+ archiveNorthWest[0] = header.maxLat; archiveNorthWest[1] = header.minLon;
11
+ const northwest = map.project(archiveNorthWest, scene._terrainZoom).divideBy(256).floor();
12
+ archiveSouthEast[0] = header.minLat; archiveSouthEast[1] = header.maxLon;
13
+ const southeast = map.project(archiveSouthEast, scene._terrainZoom).divideBy(256).floor();
14
+ scene._terrainBounds = /* alloc */ new L.Bounds(northwest, southeast);
15
+ const tiles = /* alloc */ [];
16
+ const center = map.project(map.getCenter(), scene._terrainZoom).divideBy(256);
17
+ let x, y;
18
+ for (x = northwest.x; x <= southeast.x; x++) {
19
+ for (y = northwest.y; y <= southeast.y; y++) {
20
+ tiles.push(/* alloc */ { z: scene._terrainZoom, x, y, distance: Math.hypot(x + 0.5 - center.x, y + 0.5 - center.y) });
21
+ }
22
+ }
23
+ tiles.sort(compareDistance);
24
+ return tiles;
25
+ }
@@ -1,7 +1,10 @@
1
+ import { trafficByLayer } from '../globals/trafficByLayer.js';
2
+
3
+
1
4
  import { placeTraffic } from './placeTraffic.js';
2
5
  import { startTraffic } from './startTraffic.js';
3
6
 
4
- export function addTraffic(state) {
5
- state.layer._beforeRaycast = placeTraffic.bind(null, state);
6
- if (state.ready) startTraffic(state);
7
+ export function addTraffic(state) {
8
+ trafficByLayer.set(state.layer, state);
9
+ if (state.ready) startTraffic(state);
7
10
  }
@@ -1,6 +1,6 @@
1
1
  /** Point and unit direction at distance `s` along `points` ([x, z, y?]) with cumulative `lengths`. */
2
2
 
3
- export function along(points, lengths, s) {
3
+ export function along(points, lengths, s, target) {
4
4
  let i = 1, end = lengths.length - 1;
5
5
  let middle;
6
6
  while (i < end) {
@@ -10,5 +10,11 @@ export function along(points, lengths, s) {
10
10
  }
11
11
  const a = points[i - 1], b = points[i], d = lengths[i] - lengths[i - 1] || 1;
12
12
  const t = (s - lengths[i - 1]) / d;
13
- return { x: a[0] + (b[0] - a[0]) * t, y: (a[2] ?? 0) + ((b[2] ?? 0) - (a[2] ?? 0)) * t, z: a[1] + (b[1] - a[1]) * t, dx: (b[0] - a[0]) / d, dz: (b[1] - a[1]) / d };
13
+ target ||= /* alloc */ {};
14
+ target.x = a[0] + (b[0] - a[0]) * t;
15
+ target.y = (a[2] ?? 0) + ((b[2] ?? 0) - (a[2] ?? 0)) * t;
16
+ target.z = a[1] + (b[1] - a[1]) * t;
17
+ target.dx = (b[0] - a[0]) / d;
18
+ target.dz = (b[1] - a[1]) / d;
19
+ return target;
14
20
  }
@@ -0,0 +1,15 @@
1
+ export function appendRouteDash(position, normal, color, a, b, dx, dz, x, z, start, end, r, g, blue) {
2
+ const px = a[0] + dx * start, pz = a[1] + dz * start;
3
+ const py = a[2] + (b[2] - a[2]) * start + 0.4;
4
+ const qx = a[0] + dx * end, qz = a[1] + dz * end;
5
+ const qy = a[2] + (b[2] - a[2]) * end + 0.4;
6
+ let vertex;
7
+ for (vertex = 0; vertex < 6; vertex++) {
8
+ if (vertex === 0 || vertex === 3) position.push(px - x, py, pz - z);
9
+ else if (vertex === 1) position.push(px + x, py, pz + z);
10
+ else if (vertex === 5) position.push(qx - x, qy, qz - z);
11
+ else position.push(qx + x, qy, qz + z);
12
+ normal.push(0, 1, 0);
13
+ color.push(r, g, blue);
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ import { appendRouteDash } from './appendRouteDash.js';
2
+
3
+ export function appendRouteSegment(position, normal, color, points, lengths, i, r, g, blue) {
4
+ const a = points[i - 1], b = points[i];
5
+ const dx = b[0] - a[0], dz = b[1] - a[1], length = lengths[i] - lengths[i - 1];
6
+ if (!length) return;
7
+ const x = -dz / length * 2.5, z = dx / length * 2.5;
8
+ let distance, start, end;
9
+ for (distance = Math.floor(lengths[i - 1] / 30) * 30; distance < lengths[i]; distance += 30) {
10
+ start = Math.max(0, (distance - lengths[i - 1]) / length);
11
+ end = Math.min(1, (distance + 18 - lengths[i - 1]) / length);
12
+ if (end <= start) continue;
13
+ appendRouteDash(position, normal, color, a, b, dx, dz, x, z, start, end, r, g, blue);
14
+ }
15
+ }
@@ -1,5 +1,7 @@
1
1
  export function destroyTrafficGpu(state) {
2
- let buffer;
3
- for (buffer of [state.gpu?.params, state.gpu?.template, state.gpu?.points, state.gpu?.vehicles]) buffer?.destroy();
2
+ state.gpu?.params?.destroy();
3
+ state.gpu?.template?.destroy();
4
+ state.gpu?.points?.destroy();
5
+ state.gpu?.vehicles?.destroy();
4
6
  state.gpu = null;
5
7
  }
@@ -1,12 +1,15 @@
1
+ import { sceneByLayer } from '../globals/sceneByLayer.js';
2
+
3
+
1
4
  import * as disposeMesh from '../rendering/disposeMesh.js';
2
5
  import * as setHighlight from '../picking/setHighlight.js';
3
6
  import * as showFeature from '../picking/showFeature.js';
4
7
 
5
8
  export function disposeTrafficObject(state, object) {
6
9
  if (!object) return;
7
- if (state.layer.highlightedFeature?.mesh === object) {
10
+ if (sceneByLayer.get(state.layer).highlightedFeature?.mesh === object) {
8
11
  setHighlight.setHighlight(state.layer, null);
9
- state.layer.hoveredFeature = null;
12
+ sceneByLayer.get(state.layer).hoveredFeature = null;
10
13
  showFeature.showFeature(state.layer, null);
11
14
  };
12
15
  disposeMesh.disposeMesh(state.layer, object);
@@ -1,6 +1,9 @@
1
+ import { trafficRouteMaterial } from '../globals/trafficRouteMaterial.js';
1
2
  import { routeGeometry } from './routeGeometry.js';
2
3
  import { createTrafficMesh } from './createTrafficMesh.js';
3
4
 
4
- export function drawTrafficRoute(state) {
5
- state.route = createTrafficMesh(state, routeGeometry(state.lanes), [], { unlit: true });
5
+
6
+ export function drawTrafficRoute(state) {
7
+ state.route = createTrafficMesh(state, routeGeometry(state.lanes),
8
+ /* alloc */ [], trafficRouteMaterial);
6
9
  }
@@ -1,6 +1,6 @@
1
1
  export function failTraffic(state, error) {
2
2
  state.error = error;
3
- state.status.textContent = `Error: ${error.message}`;
3
+ state.status.textContent = `${state.vehicle}: Error: ${error.message}`;
4
4
  state.status.setAttribute('role', 'alert');
5
5
  console.error('Traffic layer', error);
6
- }
6
+ }
@@ -1,10 +1,10 @@
1
1
  export async function fetchTrafficLanes(state, time, signal) {
2
- const href = new URL(state.url, document.baseURI).href;
2
+ const href = /* alloc */ new URL(state.url, document.baseURI).href;
3
3
  if (/\.m?js(?:[?#]|$)/i.test(state.url)) return (await import(href)).default(time, state.layer, signal);
4
4
  if (!state.file) {
5
- const response = await fetch(href, { signal });
6
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
5
+ const response = await fetch(href, /* alloc */ { signal });
6
+ if (!response.ok) throw /* alloc */ new Error(`HTTP ${response.status}`);
7
7
  state.file = await response.json();
8
8
  }
9
9
  return state.file;
10
- }
10
+ }
@@ -1,8 +1,12 @@
1
+ import { sceneByLayer } from '../globals/sceneByLayer.js';
2
+ import { cameraByMap } from '../globals/cameraByMap.js';
3
+
4
+
1
5
  import { getElevation } from '../terrain/getElevation.js';
2
6
 
3
7
  export function groundTraffic(state) {
4
8
  const { layer, lanes } = state;
5
- const terrain = layer._map._terrain3D?._terrainReady && layer._map._terrain3D, base = layer.root.position[1];
9
+ const terrain = sceneByLayer.get(cameraByMap.get(layer._map)._terrain3D)?._terrainReady && cameraByMap.get(layer._map)._terrain3D, base = sceneByLayer.get(layer).root.position[1];
6
10
  let lane, i, elevation;
7
11
  for (lane of lanes) {
8
12
  for (i = 0; i < lane.points.length; i++) {
@@ -1,54 +1,66 @@
1
- /**
2
- * Vehicles moving along GeoJSON lanes; a compute pass places them on the GPU every frame.
3
- * Source options:
4
- * - `url`: GeoJSON (Multi)LineStrings, or a JS module whose default export `(time, layer, signal)` returns them (time-dependent data);
5
- * - `vehicle`: 'car' (default), 'boat', 'bus', 'tram', 'metro', 'bicycle' or 'pedestrian'; `side`: offset right of the lane centreline in metres (vehicle default);
6
- * - `speed`: m/s of `flow` lanes; `outline`: draw the lanes.
7
- * Lane properties: `flow` (vehicles/h) or `timetable` (see scheduledTrips.js), optional fixed `elevation`
8
- * in metres, `name`/`description` for the default tooltip. The status line (count and vehicle type) sits under the layer's entry in the layers control.
9
- * L.Control.Time on the same map drives the time; without one, vehicles run live.
10
- */
11
- import { build } from '../geometry/build.js';
12
- import { init3D } from '../scene/init3D.js';
13
- import { tooltip } from './tooltip.js';
14
- import { speed } from '../constants/speed.js';
15
- import { vehicles } from '../constants/vehicles.js';
16
- import { trafficShader } from '../constants/trafficShader.js';
1
+ import { L } from '../globals/L.js';
2
+ import { speed as sharedSpeed } from '../globals/speed.js';
3
+ import { trafficEmptyOptions } from '../globals/trafficEmptyOptions.js';
4
+ import { vehicles } from '../globals/vehicles.js';
5
+ import { trafficShader } from '../globals/trafficShader.js';
6
+ import { trafficByLayer } from '../globals/trafficByLayer.js';
7
+
8
+
9
+ /**
10
+ * Vehicles moving along GeoJSON lanes; a compute pass places them on the GPU every frame.
11
+ * Source options:
12
+ * - `url`: GeoJSON (Multi)LineStrings, or a JS module whose default export `(time, layer, signal)` returns them (time-dependent data);
13
+ * - `vehicle`: 'car' (default), 'boat', 'bus', 'tram', 'metro', 'bicycle' or 'pedestrian'; `side`: offset right of the lane centreline in metres (vehicle default);
14
+ * - `speed`: m/s of `flow` lanes; `outline`: draw the lanes.
15
+ * Lane properties: `flow` (vehicles/h) or `timetable` (see scheduledTrips.js), optional fixed `elevation`
16
+ * in metres, `name`/`description` for the default tooltip. The status line (count and vehicle type) sits under the layer's entry in the layers control.
17
+ * L.Control.Time on the same map drives the time; without one, vehicles run live.
18
+ */
19
+ import { build } from '../geometry/build.js';
20
+ import { init3D } from '../scene/init3D.js';
21
+ import { tooltip } from './tooltip.js';
22
+
23
+
24
+
17
25
  import { addTraffic } from './addTraffic.js';
18
26
  import { placeTraffic } from './placeTraffic.js';
19
27
  import { removeTraffic } from './removeTraffic.js';
20
28
  import { readyTraffic } from './readyTraffic.js';
21
29
  import { tickTraffic } from './tickTraffic.js';
22
30
  import { updateTraffic } from './updateTraffic.js';
23
- import { updateTrafficTerrain } from './updateTrafficTerrain.js';
24
-
25
- export function initTraffic(layer, { url, vehicle = 'car', side, outline, speed: velocity = speed, ...options } = {}) {
26
- const { model, lights, side: defaultSide } = vehicles[vehicle];
27
- side ??= defaultSide;
28
- init3D(layer, {
29
- tooltip,
30
- nightLight: Boolean(lights),
31
- ...options,
32
- });
33
- const status = L.DomUtil.create('small', 'traffic-status');
34
- status.style.cssText = 'display:block;max-width:200px;margin:0 0 4px 20px;color:#555;';
35
- const template = build(model(0)), stride = template.position.length, vertices = stride / 3;
36
- const params = new ArrayBuffer(16), paramFloats = new Float32Array(params), paramInts = new Uint32Array(params);
37
- const state = {
38
- layer, url, model, lights, side, outline, velocity, vehicle, status, template, stride, vertices,
39
- params, paramFloats, paramInts,
40
- ready: false, frame: undefined, request: undefined, lanes: [], tripsKey: undefined,
41
- mesh: undefined, route: undefined, litAt: -Infinity,
42
- trips: [], rebasedAt: 0, nextCheck: -Infinity, elapsed: 0, gpu: null,
43
- lanesDirty: true, stale: false, loaded: undefined, file: undefined,
44
- };
45
- // Lane points are [x, z, ground, cumulative length]. Mirrors along() and place().
46
- state.shader = trafficShader;
47
- state.tick = tickTraffic.bind(null, state);
48
- state.update = updateTraffic.bind(null, state);
49
- state.terrain = updateTrafficTerrain.bind(null, state);
50
- layer._beforeRaycast = placeTraffic.bind(null, state);
51
- layer.on('ready', readyTraffic.bind(null, state));
52
- layer.on('add', addTraffic.bind(null, state));
53
- layer.on('remove', removeTraffic.bind(null, state));
54
- }
31
+ import { updateTrafficTerrain } from './updateTrafficTerrain.js';
32
+
33
+ export function initTraffic(layer, { url, vehicle = 'car', side, outline, speed: velocity = sharedSpeed, ...options } = trafficEmptyOptions) {
34
+ const { model, lights, side: defaultSide } = vehicles[vehicle];
35
+ side ??= defaultSide;
36
+ init3D(layer, /* alloc */ {
37
+ tooltip,
38
+ nightLight: Boolean(lights),
39
+ ...options,
40
+ });
41
+ const status = L.DomUtil.create('small', 'traffic-status');
42
+ status.style.cssText = 'flex:0 1 auto;padding:1px 5px;border-radius:3px;background:#00000008;color:#555;';
43
+ status.title = vehicle;
44
+ status.textContent = `${vehicle}: loading…`;
45
+ const template = build(model(0)), stride = template.position.length, vertices = stride / 3;
46
+ const params = /* alloc */ new ArrayBuffer(16);
47
+ const paramFloats = /* alloc */ new Float32Array(params);
48
+ const paramInts = /* alloc */ new Uint32Array(params);
49
+ const state = /* alloc */ {
50
+ layer, url, model, lights, side, outline, velocity, vehicle, status, template, stride, vertices,
51
+ params, paramFloats, paramInts,
52
+ ready: false, frame: undefined, request: undefined, lanes: /* alloc */ [], tripsKey: undefined,
53
+ mesh: undefined, route: undefined, litAt: -Infinity,
54
+ trips: /* alloc */ [], rebasedAt: 0, nextCheck: -Infinity, elapsed: 0, gpu: null,
55
+ lanesDirty: true, stale: false, loaded: undefined, file: undefined,
56
+ };
57
+ // Lane points are [x, z, ground, cumulative length]. Mirrors along() and place().
58
+ state.shader = trafficShader;
59
+ state.tick = tickTraffic.bind(null, state);
60
+ state.update = updateTraffic.bind(null, state);
61
+ state.terrain = updateTrafficTerrain.bind(null, state);
62
+ trafficByLayer.set(layer, state);
63
+ layer.on('ready', readyTraffic.bind(null, state));
64
+ layer.on('add', addTraffic.bind(null, state));
65
+ layer.on('remove', removeTraffic.bind(null, state));
66
+ }
@@ -3,13 +3,13 @@ import { fetchTrafficLanes } from './fetchTrafficLanes.js';
3
3
  import { loadedTrafficLanes } from './loadedTrafficLanes.js';
4
4
  import { failedTrafficLoad } from './failedTrafficLoad.js';
5
5
 
6
- export function loadTraffic(state) {
7
- const { time } = trafficNow(state);
8
- if (!Number.isFinite(time?.getTime())) return;
9
- state.request?.abort();
10
- const { signal } = state.request = new AbortController();
11
- fetchTrafficLanes(state, time, signal).then(
12
- loadedTrafficLanes.bind(null, state, signal),
13
- failedTrafficLoad.bind(null, state, signal),
14
- );
6
+ export function loadTraffic(state) {
7
+ const { time } = trafficNow(state);
8
+ if (!Number.isFinite(time?.getTime())) return;
9
+ state.request?.abort();
10
+ const { signal } = state.request = /* alloc */ new AbortController();
11
+ fetchTrafficLanes(state, time, signal).then(
12
+ loadedTrafficLanes.bind(null, state, signal),
13
+ failedTrafficLoad.bind(null, state, signal),
14
+ );
15
15
  }
@@ -1,9 +1,11 @@
1
- import { along } from './along.js';
2
-
1
+ import { along } from './along.js';
2
+
3
3
  export function locateTraffic(state, trip) {
4
4
  const { points, lengths, length } = trip.lane;
5
5
  let distance = trip.distance + state.elapsed * trip.speed;
6
6
  distance -= length * Math.floor(distance / length);
7
- const { x, y, z, dx, dz } = along(points, lengths, distance);
8
- return { x: x - dz * state.side, y, z: z + dx * state.side, dx, dz };
9
- }
7
+ const position = along(points, lengths, distance);
8
+ position.x -= position.dz * state.side;
9
+ position.z += position.dx * state.side;
10
+ return position;
11
+ }
@@ -10,6 +10,6 @@ export function moveTraffic(state, seconds) {
10
10
  pass.setBindGroup(0, state.gpu.bindGroup);
11
11
  pass.dispatchWorkgroups(state.trips.length);
12
12
  pass.end();
13
- device.queue.submit([encoder.finish()]);
13
+ device.queue.submit(/* alloc */ [encoder.finish()]);
14
14
  state.stale = true;
15
- }
15
+ }
@@ -1,18 +1,23 @@
1
+ import { radians } from '../globals/radians.js';
2
+ import { L } from '../globals/L.js';
3
+ import { sceneByLayer } from '../globals/sceneByLayer.js';
4
+
5
+
1
6
  import { disposeTrafficObject } from './disposeTrafficObject.js';
2
7
  import { groundTraffic } from './groundTraffic.js';
3
8
 
4
9
  export function prepareTraffic(state) {
5
10
  const { layer, lanes } = state;
6
- const crs = layer._map.options.crs, origin = crs.project(layer.location);
7
- const metres = Math.cos(layer.location.lat * Math.PI / 180);
11
+ const crs = layer._map.options.crs, origin = crs.project(sceneByLayer.get(layer).location);
12
+ const metres = Math.cos(sceneByLayer.get(layer).location.lat * radians);
8
13
  let lane, lat, lng, point, i;
9
14
  for (lane of lanes) {
10
- lane.points = [];
15
+ lane.points = /* alloc */ [];
11
16
  for ([lat, lng] of lane.latlngs) {
12
- point = crs.project(new L.LatLng(lat, lng));
13
- lane.points.push([(point.x - origin.x) * metres, -(point.y - origin.y) * metres, 0]);
17
+ point = crs.project(/* alloc */ new L.LatLng(lat, lng));
18
+ lane.points.push(/* alloc */ [(point.x - origin.x) * metres, -(point.y - origin.y) * metres, 0]);
14
19
  }
15
- lane.lengths = [0];
20
+ lane.lengths = /* alloc */ [0];
16
21
  for (i = 1; i < lane.points.length; i++) {
17
22
  lane.lengths.push(lane.lengths[i - 1] + Math.hypot(lane.points[i][0] - lane.points[i - 1][0], lane.points[i][1] - lane.points[i - 1][1]));
18
23
  }
@@ -1,39 +1,34 @@
1
+ import { sceneByLayer } from '../globals/sceneByLayer.js';
2
+
3
+
1
4
  import { destroyTrafficGpu } from './destroyTrafficGpu.js';
2
5
  import { trafficStorage } from './trafficStorage.js';
6
+ import { uploadTrafficLanes } from './uploadTrafficLanes.js';
3
7
 
4
8
  export function rebaseTraffic(state) {
5
- const { device } = state.layer.renderer;
9
+ const { device } = sceneByLayer.get(state.layer).renderer;
6
10
  if (state.gpu?.device !== device) {
7
11
  destroyTrafficGpu(state);
8
- state.gpu = {
12
+ const template = /* alloc */ new Float32Array(
13
+ state.template.position.length + state.template.normal.length);
14
+ template.set(state.template.position);
15
+ template.set(state.template.normal, state.template.position.length);
16
+ state.gpu = /* alloc */ {
9
17
  device,
10
- pipeline: device.createComputePipeline({ layout: 'auto', compute: { module: device.createShaderModule({ code: state.shader }), entryPoint: 'main' } }),
11
- params: device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }),
12
- template: trafficStorage(device, new Float32Array([...state.template.position, ...state.template.normal])),
18
+ pipeline: device.createComputePipeline(/* alloc */ {
19
+ layout: 'auto', compute: /* alloc */ {
20
+ module: device.createShaderModule(/* alloc */ { code: state.shader }), entryPoint: 'main',
21
+ },
22
+ }),
23
+ params: device.createBuffer(/* alloc */ { size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }),
24
+ template: trafficStorage(device, template),
13
25
  };
14
26
  state.lanesDirty = true;
15
27
  }
16
- let lane, i, point, trip, binding;
17
- if (state.lanesDirty) {
18
- let count = 0;
19
- for (lane of state.lanes) count += lane.points.length;
20
- const data = new Float32Array(count * 4);
21
- let offset = 0;
22
- for (lane of state.lanes) {
23
- lane.start = offset / 4;
24
- for (i = 0; i < lane.points.length; i++) {
25
- point = lane.points[i];
26
- data[offset++] = point[0];
27
- data[offset++] = point[1];
28
- data[offset++] = point[2];
29
- data[offset++] = lane.lengths[i];
30
- }
31
- }
32
- state.gpu.points?.destroy();
33
- state.gpu.points = trafficStorage(device, data);
34
- state.lanesDirty = false;
35
- }
36
- const data = new Float32Array(state.trips.length * 4), index = new Uint32Array(data.buffer);
28
+ let i, trip, binding;
29
+ if (state.lanesDirty) uploadTrafficLanes(state, device);
30
+ const data = /* alloc */ new Float32Array(state.trips.length * 4);
31
+ const index = /* alloc */ new Uint32Array(data.buffer);
37
32
  for (i = 0; i < state.trips.length; i++) {
38
33
  trip = state.trips[i];
39
34
  index[i * 4] = trip.lane.start;
@@ -48,10 +43,17 @@ export function rebaseTraffic(state) {
48
43
  state.gpu.vehicles = trafficStorage(device, data);
49
44
  }
50
45
  const { position, normal } = state.mesh.geometry.attributes;
51
- const buffers = [state.gpu.params, state.gpu.template, state.gpu.points, state.gpu.vehicles, position.buffer, normal.buffer];
52
- const entries = [];
53
- for (binding = 0; binding < buffers.length; binding++) entries.push({ binding, resource: { buffer: buffers[binding] } });
54
- state.gpu.bindGroup = device.createBindGroup({
46
+ const entries = /* alloc */ [];
47
+ let buffer;
48
+ for (binding = 0; binding < 6; binding++) {
49
+ buffer = binding === 0 ? state.gpu.params : binding === 1 ? state.gpu.template
50
+ : binding === 2 ? state.gpu.points : binding === 3 ? state.gpu.vehicles
51
+ : binding === 4 ? position.buffer : normal.buffer;
52
+ entries.push(/* alloc */ {
53
+ binding, resource: /* alloc */ { buffer },
54
+ });
55
+ }
56
+ state.gpu.bindGroup = device.createBindGroup(/* alloc */ {
55
57
  layout: state.gpu.pipeline.getBindGroupLayout(0),
56
58
  entries,
57
59
  });
@@ -1,27 +1,31 @@
1
+ import { trafficEmptyOptions } from '../globals/trafficEmptyOptions.js';
1
2
  import { build } from '../geometry/build.js';
2
3
  import { createTrafficMesh } from './createTrafficMesh.js';
3
4
  import { disposeTrafficObject } from './disposeTrafficObject.js';
4
5
  import { trafficBounds } from './trafficBounds.js';
5
6
 
7
+
6
8
  export function rebuildTrafficMesh(state) {
7
9
  const { trips, model, vertices } = state;
8
10
  disposeTrafficObject(state, state.mesh);
9
11
  state.mesh = null;
10
12
  if (!trips.length) return;
11
- const color = [], featureFaces = [];
13
+ const color = /* alloc */ [];
14
+ const featureFaces = /* alloc */ [];
12
15
  let i, trip, component;
13
16
  for (i = 0; i < trips.length; i++) {
14
17
  trip = trips[i];
15
18
  for (component of build(model(i, trip.properties)).color) color.push(component);
16
- featureFaces.push({
19
+ featureFaces.push(/* alloc */ {
17
20
  id: trip.id, properties: trip.properties, faceStart: i * vertices / 3, faceEnd: (i + 1) * vertices / 3,
18
21
  vertexStart: i * vertices, vertexEnd: (i + 1) * vertices
19
22
  });
20
23
  }
21
24
  const count = color.length / 3;
22
- state.mesh = createTrafficMesh(state, {
23
- position: new Array(color.length).fill(0), normal: new Array(color.length).fill(0), color,
24
- }, featureFaces, {}, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC);
25
+ state.mesh = createTrafficMesh(state, /* alloc */ {
26
+ position: /* alloc */ new Array(color.length).fill(0),
27
+ normal: /* alloc */ new Array(color.length).fill(0), color,
28
+ }, featureFaces, trafficEmptyOptions, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC);
25
29
  state.mesh.geometry.drawRange.count = count;
26
30
  state.mesh.extras.dynamicLights = true;
27
31
  trafficBounds(state);
@@ -0,0 +1,32 @@
1
+ import { tripsAt } from './tripsAt.js';
2
+ import { failTraffic } from './failTraffic.js';
3
+ import { drawTrafficRoute } from './drawTrafficRoute.js';
4
+ import { rebuildTrafficMesh } from './rebuildTrafficMesh.js';
5
+ import { rebaseTraffic } from './rebaseTraffic.js';
6
+ import { trafficStatusText } from './trafficStatusText.js';
7
+
8
+ export function refreshTrafficTrips(state, time, ms, valid) {
9
+ let text;
10
+ try {
11
+ if (valid) state.trips = tripsAt(time, state.lanes, state.velocity);
12
+ else state.trips.length = 0;
13
+ text = trafficStatusText(state, valid);
14
+ } catch (error) {
15
+ failTraffic(state, error);
16
+ return;
17
+ }
18
+ state.rebasedAt = ms;
19
+ state.nextCheck = ms + 1000;
20
+ let key = '', trip;
21
+ for (trip of state.trips) key += `${key ? ',' : ''}${trip.id}`;
22
+ const routeNeeded = state.outline && !state.route && state.lanes.length;
23
+ const changed = key !== state.tripsKey || Boolean(routeNeeded);
24
+ if (routeNeeded) drawTrafficRoute(state);
25
+ if (key !== state.tripsKey) { rebuildTrafficMesh(state); state.tripsKey = key; }
26
+ if (state.mesh) rebaseTraffic(state);
27
+ if (!state.error) {
28
+ if (state.status.textContent !== text) state.status.textContent = text;
29
+ state.status.removeAttribute('role');
30
+ }
31
+ return changed;
32
+ }