leaflet-city-mapper 0.0.1 → 0.0.3

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 (629) hide show
  1. package/README.md +61 -13
  2. package/cucumber.mjs +4 -0
  3. package/dist/leaflet-city-mapper.js +3 -1
  4. package/dist/leaflet-city-mapper.js.map +4 -4
  5. package/package.json +3 -4
  6. package/src/archives/decodeDirectory.js +32 -0
  7. package/src/archives/decodeHeader.js +19 -0
  8. package/src/archives/decompress.js +5 -0
  9. package/src/archives/getHeader.js +9 -0
  10. package/src/archives/getZxy.js +75 -0
  11. package/src/archives/loadDirectory.js +7 -0
  12. package/src/archives/loadSource.js +17 -0
  13. package/src/archives/read.js +29 -0
  14. package/src/archives/tileId.js +19 -0
  15. package/src/archives/varint.js +15 -0
  16. package/src/camera/angles.js +6 -0
  17. package/src/camera/animationPoint.js +8 -0
  18. package/src/camera/cameraMapReady.js +8 -0
  19. package/src/camera/cancelCameraAnimation.js +11 -0
  20. package/src/camera/cleanupCameraMap.js +11 -0
  21. package/src/camera/constrainCameraToBounds.js +3 -0
  22. package/src/camera/displayPoint.js +3 -0
  23. package/src/camera/fitCameraBounds.js +48 -0
  24. package/src/camera/groundBounds.js +11 -0
  25. package/src/camera/initializeCameraMap.js +25 -0
  26. package/src/camera/mapAnimateCamera.js +17 -0
  27. package/src/camera/mapCamera.js +123 -0
  28. package/src/camera/mapContainerPointToLayerPoint.js +7 -0
  29. package/src/camera/mapGetBearing.js +1 -0
  30. package/src/camera/mapGetBounds.js +14 -0
  31. package/src/camera/mapGetBoundsCenterZoom.js +7 -0
  32. package/src/camera/mapGetBoundsZoom.js +14 -0
  33. package/src/camera/mapGetCenterLayerPoint.js +5 -0
  34. package/src/camera/mapGetPitch.js +1 -0
  35. package/src/camera/mapLayerPointToContainerPoint.js +7 -0
  36. package/src/camera/mapLimitCenter.js +12 -0
  37. package/src/camera/mapLimitOffset.js +10 -0
  38. package/src/camera/mapPanBy.js +9 -0
  39. package/src/camera/mapPanInside.js +14 -0
  40. package/src/camera/mapResetNorth.js +1 -0
  41. package/src/camera/mapResetNorthPitch.js +1 -0
  42. package/src/camera/mapSetBearing.js +1 -0
  43. package/src/camera/mapSetPitch.js +1 -0
  44. package/src/camera/mapSetPitchAndBearing.js +14 -0
  45. package/src/camera/mapSetZoomAround.js +11 -0
  46. package/src/camera/mapStopPitchBearingAnimation.js +6 -0
  47. package/src/camera/mapTryAnimatedPan.js +9 -0
  48. package/src/camera/mapUpdateCameraOverlays.js +7 -0
  49. package/src/camera/pointOf.js +3 -0
  50. package/src/camera/project.js +20 -0
  51. package/src/camera/runCameraAnimations.js +28 -0
  52. package/src/camera/scheduleCameraAnimation.js +8 -0
  53. package/src/camera/updateSky.js +16 -0
  54. package/src/camera/verticalGroundY.js +4 -0
  55. package/src/collision/collectMeshes.js +5 -0
  56. package/src/collision/collider.js +63 -0
  57. package/src/collision/horizontalRay.js +12 -0
  58. package/src/collision/intersectMeshes.js +133 -0
  59. package/src/collision/sortHits.js +23 -0
  60. package/src/constants/CELL.js +4 -0
  61. package/src/constants/Compass.js +7 -0
  62. package/src/constants/ContainerResize.js +7 -0
  63. package/src/constants/HEIGHT.js +1 -0
  64. package/src/constants/PitchDrag.js +7 -0
  65. package/src/constants/ShiftRotate.js +7 -0
  66. package/src/constants/TILE_RADIUS.js +1 -0
  67. package/src/constants/TILE_SIZE.js +1 -0
  68. package/src/constants/TouchMode.js +6 -0
  69. package/src/constants/accessorSizes.js +1 -0
  70. package/src/constants/accessorTypes.js +8 -0
  71. package/src/constants/attachState.js +1 -0
  72. package/src/constants/cameraControlsState.js +1 -0
  73. package/src/constants/cityMapper.js +6 -0
  74. package/src/constants/colliders.js +2 -0
  75. package/src/constants/dark.js +1 -0
  76. package/src/constants/elevationWGSL.js +27 -0
  77. package/src/constants/glass.js +1 -0
  78. package/src/constants/headlight.js +1 -0
  79. package/src/constants/hull.js +1 -0
  80. package/src/constants/indexState.js +1 -0
  81. package/src/constants/limbs.js +9 -0
  82. package/src/constants/mapCameraState.js +1 -0
  83. package/src/constants/moves.js +11 -0
  84. package/src/constants/nativeEventMaps.js +1 -0
  85. package/src/constants/nativeLayerState.js +1 -0
  86. package/src/constants/nativeMethodHandlers.js +31 -0
  87. package/src/constants/onMapChangeState.js +1 -0
  88. package/src/constants/onZoomAnimState.js +1 -0
  89. package/src/constants/paints.js +10 -0
  90. package/src/constants/parts.js +19 -0
  91. package/src/constants/pendingUpdates.js +1 -0
  92. package/src/constants/pumpState.js +1 -0
  93. package/src/constants/renderers.js +2 -0
  94. package/src/constants/ringDirections.js +10 -0
  95. package/src/constants/roundProfile.js +1 -0
  96. package/src/constants/shirt.js +1 -0
  97. package/src/constants/skin.js +2 -0
  98. package/src/constants/speed.js +3 -0
  99. package/src/constants/taillight.js +1 -0
  100. package/src/constants/trafficShader.js +49 -0
  101. package/src/constants/trousers.js +1 -0
  102. package/src/constants/tyre.js +1 -0
  103. package/src/constants/underEntryState.js +1 -0
  104. package/src/constants/vehicles.js +40 -0
  105. package/src/constants/white.js +1 -0
  106. package/src/controls/acceptPitchDrag.js +4 -0
  107. package/src/controls/acceptRotateDrag.js +3 -0
  108. package/src/controls/adjustCameraDrag.js +10 -0
  109. package/src/controls/cameraControls.js +60 -0
  110. package/src/controls/cameraDragClick.js +9 -0
  111. package/src/controls/cameraDragContextMenu.js +8 -0
  112. package/src/controls/cameraDragDown.js +20 -0
  113. package/src/controls/cameraDragEnd.js +6 -0
  114. package/src/controls/cameraDragMove.js +23 -0
  115. package/src/controls/changeCameraTouch.js +14 -0
  116. package/src/controls/cleanupCameraTouch.js +24 -0
  117. package/src/controls/compassAddHooks.js +15 -0
  118. package/src/controls/compassOrientation.js +6 -0
  119. package/src/controls/compassRemoveHooks.js +5 -0
  120. package/src/controls/containerResizeAddHooks.js +8 -0
  121. package/src/controls/containerResizeRemoveHooks.js +5 -0
  122. package/src/controls/dragCamera.js +22 -0
  123. package/src/controls/editable.js +3 -0
  124. package/src/controls/endAllCameraDrags.js +7 -0
  125. package/src/controls/endAllCameraTouches.js +7 -0
  126. package/src/controls/endCameraTouch.js +11 -0
  127. package/src/controls/endCameraTouchEvent.js +5 -0
  128. package/src/controls/finishCameraDrag.js +9 -0
  129. package/src/controls/finishCompassPermission.js +16 -0
  130. package/src/controls/loadCameraControls.js +9 -0
  131. package/src/controls/moveCameraTouch.js +22 -0
  132. package/src/controls/notifyCameraTouchChange.js +1 -0
  133. package/src/controls/pitchDragAddHooks.js +6 -0
  134. package/src/controls/pitchDragRemoveHooks.js +5 -0
  135. package/src/controls/refreshRotateControl.js +7 -0
  136. package/src/controls/refreshRotateFocus.js +5 -0
  137. package/src/controls/removeCameraDrag.js +23 -0
  138. package/src/controls/resizeMap.js +3 -0
  139. package/src/controls/rotateButtonClick.js +7 -0
  140. package/src/controls/rotateButtonKeydown.js +11 -0
  141. package/src/controls/rotateControl.js +3 -0
  142. package/src/controls/rotateOnAdd.js +38 -0
  143. package/src/controls/rotateOnRemove.js +6 -0
  144. package/src/controls/shiftRotateAddHooks.js +8 -0
  145. package/src/controls/shiftRotateRemoveHooks.js +5 -0
  146. package/src/controls/shiftRotateWheel.js +9 -0
  147. package/src/controls/startCameraTouch.js +23 -0
  148. package/src/core/addImageState.js +7 -0
  149. package/src/core/addRasterImage.js +10 -0
  150. package/src/core/adjustCameraMarkerPan.js +22 -0
  151. package/src/core/beforeNativeRender.js +10 -0
  152. package/src/core/boundsQuad.js +11 -0
  153. package/src/core/bringNativeLayerToBack.js +3 -0
  154. package/src/core/bringNativeLayerToFront.js +3 -0
  155. package/src/core/cameraCircleBounds.js +6 -0
  156. package/src/core/cameraMarkerDrag.js +18 -0
  157. package/src/core/cameraMarkerOnDrag.js +8 -0
  158. package/src/core/cancelGridFade.js +10 -0
  159. package/src/core/closestCameraLayerPoint.js +7 -0
  160. package/src/core/compareNativeHits.js +3 -0
  161. package/src/core/current.js +3 -0
  162. package/src/core/disposeNativeLayer.js +35 -0
  163. package/src/core/fireRasterLoad.js +5 -0
  164. package/src/core/forwardNativeError.js +3 -0
  165. package/src/core/gridlayerGetEvents.js +7 -0
  166. package/src/core/gridlayerGetTiledPixelBounds.js +8 -0
  167. package/src/core/handleNativeMapEvent.js +47 -0
  168. package/src/core/hideTargets.js +16 -0
  169. package/src/core/initNativeGPU.js +21 -0
  170. package/src/core/initializeGridContainer.js +6 -0
  171. package/src/core/initializeNativeLayer.js +42 -0
  172. package/src/core/localPixel.js +5 -0
  173. package/src/core/localPixelForGeometry.js +6 -0
  174. package/src/core/localPosition.js +6 -0
  175. package/src/core/markerCameraIconPoint.js +9 -0
  176. package/src/core/markerGetEvents.js +5 -0
  177. package/src/core/markerInitInteraction.js +8 -0
  178. package/src/core/markerQuadCorners.js +31 -0
  179. package/src/core/markerSetIcon.js +9 -0
  180. package/src/core/markerSetPos.js +14 -0
  181. package/src/core/markerSetRotation.js +7 -0
  182. package/src/core/markerUpdateZIndex.js +8 -0
  183. package/src/core/nativeAddLatLng.js +3 -0
  184. package/src/core/nativeBringToBack.js +3 -0
  185. package/src/core/nativeBringToFront.js +3 -0
  186. package/src/core/nativeEvents.js +26 -0
  187. package/src/core/nativeImageError.js +8 -0
  188. package/src/core/nativeImageRefresh.js +7 -0
  189. package/src/core/nativeLayer.js +97 -0
  190. package/src/core/nativeLayerMethod.js +21 -0
  191. package/src/core/nativeRedraw.js +3 -0
  192. package/src/core/nativeSetBounds.js +3 -0
  193. package/src/core/nativeSetIcon.js +3 -0
  194. package/src/core/nativeSetLatLng.js +3 -0
  195. package/src/core/nativeSetLatLngs.js +3 -0
  196. package/src/core/nativeSetOpacity.js +3 -0
  197. package/src/core/nativeSetRadius.js +3 -0
  198. package/src/core/nativeSetStyle.js +3 -0
  199. package/src/core/nativeSetUrl.js +3 -0
  200. package/src/core/nativeSetZIndex.js +3 -0
  201. package/src/core/nativeSetZIndexOffset.js +3 -0
  202. package/src/core/popupAdjustPan.js +23 -0
  203. package/src/core/popupGetEvents.js +5 -0
  204. package/src/core/popupUpdatePosition.js +14 -0
  205. package/src/core/putNativeMesh.js +33 -0
  206. package/src/core/quadNativeMesh.js +15 -0
  207. package/src/core/readyNativeGPU.js +6 -0
  208. package/src/core/refreshNativeEvent.js +5 -0
  209. package/src/core/refreshNativeLayer.js +29 -0
  210. package/src/core/refreshNativeLayerContract.js +3 -0
  211. package/src/core/rejectNativeReady.js +3 -0
  212. package/src/core/removeImageState.js +8 -0
  213. package/src/core/removeNativeEvents.js +16 -0
  214. package/src/core/removeTargets.js +8 -0
  215. package/src/core/reorderNativeLayer.js +6 -0
  216. package/src/core/resolveNativeReady.js +3 -0
  217. package/src/core/restoreNativeEvents.js +6 -0
  218. package/src/core/runGridFades.js +14 -0
  219. package/src/core/runMarkerPanFrame.js +12 -0
  220. package/src/core/scheduleGridFade.js +9 -0
  221. package/src/core/scheduleMarkerPan.js +8 -0
  222. package/src/core/styleNativeMesh.js +10 -0
  223. package/src/core/syncGridLayer.js +22 -0
  224. package/src/core/syncImageOverlay.js +9 -0
  225. package/src/core/syncMarker.js +12 -0
  226. package/src/core/syncVectorLayer.js +26 -0
  227. package/src/core/synchronizeNativeLayer.js +35 -0
  228. package/src/core/textureFor.js +48 -0
  229. package/src/core/tooltipGetEvents.js +5 -0
  230. package/src/core/tooltipSetPosition.js +8 -0
  231. package/src/core/updateGridOpacity.js +23 -0
  232. package/src/core/updateNativeLayerView.js +6 -0
  233. package/src/core/uploadCanvasTexture.js +19 -0
  234. package/src/geometry/addBridges.js +88 -0
  235. package/src/geometry/below.js +3 -0
  236. package/src/geometry/box.js +3 -0
  237. package/src/geometry/bridgeElevation.js +19 -0
  238. package/src/geometry/bridgeLocal.js +4 -0
  239. package/src/geometry/build.js +19 -0
  240. package/src/geometry/circleAt.js +5 -0
  241. package/src/geometry/clipLine.js +23 -0
  242. package/src/geometry/clipSegment.js +19 -0
  243. package/src/geometry/computeBounds.js +33 -0
  244. package/src/geometry/conformModelToTerrain.js +67 -0
  245. package/src/geometry/cross.js +3 -0
  246. package/src/geometry/disk.js +11 -0
  247. package/src/geometry/diskAt.js +4 -0
  248. package/src/geometry/dot.js +6 -0
  249. package/src/geometry/emitter.js +8 -0
  250. package/src/geometry/lampPostGeometry.js +24 -0
  251. package/src/geometry/lampRing.js +11 -0
  252. package/src/geometry/lightGeometry.js +15 -0
  253. package/src/geometry/line.js +54 -0
  254. package/src/geometry/nativeGeometry.js +55 -0
  255. package/src/geometry/nativeTriangle.js +3 -0
  256. package/src/geometry/polygon.js +22 -0
  257. package/src/geometry/push.js +3 -0
  258. package/src/geometry/quad.js +4 -0
  259. package/src/geometry/roofCoverage.js +52 -0
  260. package/src/geometry/samePoint.js +3 -0
  261. package/src/geometry/segment.js +21 -0
  262. package/src/geometry/setVertexColor.js +15 -0
  263. package/src/geometry/sub.js +6 -0
  264. package/src/geometry/surface.js +17 -0
  265. package/src/geometry/treeGeometry.js +31 -0
  266. package/src/geometry/treeRing.js +14 -0
  267. package/src/geometry/triangle.js +12 -0
  268. package/src/geometry/vertexNormals.js +32 -0
  269. package/src/geometry/visit.js +9 -0
  270. package/src/index.js +98 -65
  271. package/src/lighting/cacheLightGrid.js +23 -0
  272. package/src/lighting/collectLightMeshes.js +6 -0
  273. package/src/lighting/lightGrid.js +42 -0
  274. package/src/lighting/updatePointLights.js +34 -0
  275. package/src/lighting/visitCells.js +15 -0
  276. package/src/lighting/worldLights.js +27 -0
  277. package/src/models/decodeModel.js +45 -0
  278. package/src/models/hasUnsupportedPrimitives.js +10 -0
  279. package/src/models/loadBuffer.js +6 -0
  280. package/src/models/loadImage.js +15 -0
  281. package/src/models/loadModel.js +69 -0
  282. package/src/models/materialFor.js +21 -0
  283. package/src/models/modelNode.js +93 -0
  284. package/src/models/nodeMatrix.js +22 -0
  285. package/src/models/readAccessor.js +53 -0
  286. package/src/models/readAccessorValues.js +16 -0
  287. package/src/models/textureFor.js +35 -0
  288. package/src/models/textureSampler.js +10 -0
  289. package/src/picking/collectVisibleMesh.js +4 -0
  290. package/src/picking/findFeature.js +49 -0
  291. package/src/picking/hit.js +23 -0
  292. package/src/picking/hitMesh.js +30 -0
  293. package/src/picking/onClick.js +13 -0
  294. package/src/picking/onPointerLeave.js +11 -0
  295. package/src/picking/onPointerMove.js +15 -0
  296. package/src/picking/pointerClick.js +5 -0
  297. package/src/picking/pointerLeave.js +5 -0
  298. package/src/picking/pointerMove.js +5 -0
  299. package/src/picking/raycast.js +59 -0
  300. package/src/picking/setHighlight.js +13 -0
  301. package/src/picking/shouldSkipOther.js +3 -0
  302. package/src/picking/showFeature.js +34 -0
  303. package/src/raster/addRasterTile.js +114 -0
  304. package/src/raster/comparePendingTiles.js +5 -0
  305. package/src/raster/createGeometry.js +22 -0
  306. package/src/raster/createRasterMesh.js +47 -0
  307. package/src/raster/finishAttachment.js +11 -0
  308. package/src/raster/finishRasterTile.js +47 -0
  309. package/src/raster/getRasterEvents.js +6 -0
  310. package/src/raster/getRasterTileSize.js +5 -0
  311. package/src/raster/initRaster.js +38 -0
  312. package/src/raster/isLoading.js +5 -0
  313. package/src/raster/loadRasterTile.js +10 -0
  314. package/src/raster/onPMTileAdd.js +10 -0
  315. package/src/raster/onPMTileRemove.js +8 -0
  316. package/src/raster/pruneRasterTiles.js +37 -0
  317. package/src/raster/pumpRasterTiles.js +22 -0
  318. package/src/raster/readyRaster.js +13 -0
  319. package/src/raster/registerTerrainTile.js +12 -0
  320. package/src/raster/releaseRasterTile.js +18 -0
  321. package/src/raster/releaseRasterTiles.js +15 -0
  322. package/src/raster/removeRasterTile.js +13 -0
  323. package/src/raster/reportError.js +6 -0
  324. package/src/raster/setPMTileOpacity.js +7 -0
  325. package/src/raster/setPMTileZIndex.js +7 -0
  326. package/src/raster/setRasterOpacity.js +11 -0
  327. package/src/raster/setRasterTerrain.js +21 -0
  328. package/src/raster/setRasterZIndex.js +11 -0
  329. package/src/raster/updateAttachedTiles.js +10 -0
  330. package/src/raster/updateRasterTiles.js +59 -0
  331. package/src/rendering/collectFrameMeshes.js +31 -0
  332. package/src/rendering/collectMeshes.js +36 -0
  333. package/src/rendering/compareMeshes.js +10 -0
  334. package/src/rendering/compareRoofTiles.js +4 -0
  335. package/src/rendering/composeRoofAtlas.js +52 -0
  336. package/src/rendering/createMesh.js +33 -0
  337. package/src/rendering/createProgram.js +92 -0
  338. package/src/rendering/destroyAfterSubmission.js +8 -0
  339. package/src/rendering/destroyTexture.js +6 -0
  340. package/src/rendering/disposeMesh.js +14 -0
  341. package/src/rendering/drawGeometry.js +129 -0
  342. package/src/rendering/drawSceneMeshes.js +51 -0
  343. package/src/rendering/ensureRoofBlit.js +40 -0
  344. package/src/rendering/prepareFrameMeshes.js +42 -0
  345. package/src/rendering/prepareFrameUniforms.js +49 -0
  346. package/src/rendering/rebuildRoofAtlas.js +67 -0
  347. package/src/rendering/render.js +57 -0
  348. package/src/rendering/reportCompilation.js +17 -0
  349. package/src/rendering/resizeRenderer.js +19 -0
  350. package/src/rendering/sortMeshes.js +6 -0
  351. package/src/rendering/synchronizeZoomView.js +34 -0
  352. package/src/rendering/textureBinding.js +7 -0
  353. package/src/rendering/updateMapCamera.js +32 -0
  354. package/src/rendering/updateRoofRaster.js +32 -0
  355. package/src/scene/attach.js +161 -0
  356. package/src/scene/attachLayer.js +10 -0
  357. package/src/scene/cancelUpdate.js +10 -0
  358. package/src/scene/emptyEvents.js +3 -0
  359. package/src/scene/emptyNode.js +11 -0
  360. package/src/scene/endZoom.js +16 -0
  361. package/src/scene/failAttachment.js +9 -0
  362. package/src/scene/get3DEvents.js +13 -0
  363. package/src/scene/init3D.js +30 -0
  364. package/src/scene/initializeLayer.js +16 -0
  365. package/src/scene/initializerFor.js +14 -0
  366. package/src/scene/layerInitialize.js +38 -0
  367. package/src/scene/layerLayerAdd.js +21 -0
  368. package/src/scene/onAdd3DLayer.js +35 -0
  369. package/src/scene/onMapChange.js +16 -0
  370. package/src/scene/onRemove3DLayer.js +69 -0
  371. package/src/scene/onZoomAnim.js +16 -0
  372. package/src/scene/placeEntry.js +11 -0
  373. package/src/scene/placeUnderEntry.js +8 -0
  374. package/src/scene/ready3D.js +25 -0
  375. package/src/scene/releaseRenderer.js +14 -0
  376. package/src/scene/removeEntry.js +6 -0
  377. package/src/scene/renderPendingMapChange.js +11 -0
  378. package/src/scene/renderPendingUpdates.js +19 -0
  379. package/src/scene/renderPendingZoomAnimation.js +7 -0
  380. package/src/scene/rendererDeviceError.js +10 -0
  381. package/src/scene/rendererDeviceLost.js +11 -0
  382. package/src/scene/replaceEntry.js +7 -0
  383. package/src/scene/reportError.js +3 -0
  384. package/src/scene/requestAdapter.js +12 -0
  385. package/src/scene/requestDevice.js +9 -0
  386. package/src/scene/resolveNextInitialization.js +12 -0
  387. package/src/scene/restoreObject.js +71 -0
  388. package/src/scene/runPlacements.js +7 -0
  389. package/src/scene/setParent.js +7 -0
  390. package/src/scene/showWebGPUWarning.js +16 -0
  391. package/src/scene/startZoom.js +5 -0
  392. package/src/scene/traverse.js +7 -0
  393. package/src/scene/underEntry.js +17 -0
  394. package/src/scene/update.js +19 -0
  395. package/src/scene/updateCamera.js +34 -0
  396. package/src/scene/updateWorldMatrix.js +48 -0
  397. package/src/{utils/shaders.js → shaders/materialShaders.js} +246 -237
  398. package/src/shadows/bindSunlight.js +12 -0
  399. package/src/shadows/drawShadowMeshes.js +48 -0
  400. package/src/shadows/ensureShadowPipeline.js +53 -0
  401. package/src/shadows/renderSunlight.js +46 -0
  402. package/src/shadows/resizeSunlight.js +15 -0
  403. package/src/shadows/shadowBounds.js +32 -0
  404. package/src/shadows/shadowCacheMatches.js +23 -0
  405. package/src/shadows/shadowMatrix.js +39 -0
  406. package/src/sources/addGeneratedTriangle.js +6 -0
  407. package/src/sources/addTriangle.js +17 -0
  408. package/src/sources/attachAreaMesh.js +58 -0
  409. package/src/sources/buildArea.js +42 -0
  410. package/src/sources/buildAreaFeature.js +41 -0
  411. package/src/sources/buildAreaPoint.js +25 -0
  412. package/src/sources/buildAreaPolygon.js +29 -0
  413. package/src/sources/compareAreaDistance.js +4 -0
  414. package/src/sources/generateTreeGeometry.js +11 -0
  415. package/src/sources/groundOffset.js +3 -0
  416. package/src/sources/initializeGeoJSON.js +8 -0
  417. package/src/sources/instanceAreaGeometry.js +29 -0
  418. package/src/sources/projectRing.js +20 -0
  419. package/src/sources/projectedTree.js +13 -0
  420. package/src/sources/pump.js +54 -0
  421. package/src/sources/releaseArea.js +22 -0
  422. package/src/sources/setGeoJSONData.js +12 -0
  423. package/src/sources/setGeoJSONLayerData.js +5 -0
  424. package/src/sources/sourceAreaContext.js +9 -0
  425. package/src/sources/updateArea.js +45 -0
  426. package/src/sources/updateStatus.js +12 -0
  427. package/src/sunlight/addTimeLayer.js +3 -0
  428. package/src/sunlight/addTo.js +10 -0
  429. package/src/sunlight/atmosphere.js +28 -0
  430. package/src/sunlight/horizontalPosition.js +16 -0
  431. package/src/sunlight/initSunlight.js +14 -0
  432. package/src/sunlight/initialize.js +11 -0
  433. package/src/sunlight/mix.js +6 -0
  434. package/src/sunlight/moonPosition.js +17 -0
  435. package/src/sunlight/onAdd.js +5 -0
  436. package/src/sunlight/onAddSun.js +66 -0
  437. package/src/sunlight/projectCelestialBody.js +13 -0
  438. package/src/sunlight/remove.js +7 -0
  439. package/src/sunlight/removeSun.js +15 -0
  440. package/src/sunlight/removeTimeLayer.js +3 -0
  441. package/src/sunlight/render.js +7 -0
  442. package/src/sunlight/rgb.js +6 -0
  443. package/src/sunlight/solarPosition.js +17 -0
  444. package/src/sunlight/styleTimeControl.js +7 -0
  445. package/src/sunlight/tickSun.js +5 -0
  446. package/src/sunlight/updateSky.js +20 -0
  447. package/src/sunlight/updateSun.js +34 -0
  448. package/src/sunlight/useLiveTime.js +6 -0
  449. package/src/sunlight/useSelectedTime.js +20 -0
  450. package/src/terrain/clearLayerTerrain.js +5 -0
  451. package/src/terrain/getElevation.js +10 -0
  452. package/src/terrain/initTerrain.js +20 -0
  453. package/src/terrain/loadReadyTerrain.js +5 -0
  454. package/src/terrain/loadTerrain.js +63 -0
  455. package/src/terrain/loadTerrainTiles.js +13 -0
  456. package/src/terrain/onTerrainAdd.js +21 -0
  457. package/src/terrain/onTerrainChange.js +14 -0
  458. package/src/terrain/onTerrainRemove.js +41 -0
  459. package/src/terrain/readBridges.js +4 -0
  460. package/src/terrain/sample.js +7 -0
  461. package/src/terrain/setLayerTerrain.js +5 -0
  462. package/src/terrain/setTerrainHeight.js +10 -0
  463. package/src/terrain/terrainAtlas.js +23 -0
  464. package/src/terrain/terrainElevation.js +20 -0
  465. package/src/terrain/terrainGrid.js +24 -0
  466. package/src/traffic/addTraffic.js +7 -0
  467. package/src/traffic/along.js +14 -0
  468. package/src/traffic/clockMinutes.js +6 -0
  469. package/src/traffic/compareDepartures.js +5 -0
  470. package/src/traffic/createTrafficMesh.js +7 -0
  471. package/src/traffic/destroyTrafficGpu.js +5 -0
  472. package/src/traffic/disposeTrafficObject.js +13 -0
  473. package/src/traffic/drawTrafficRoute.js +6 -0
  474. package/src/traffic/failTraffic.js +6 -0
  475. package/src/traffic/failedTrafficLoad.js +5 -0
  476. package/src/traffic/fetchTrafficLanes.js +10 -0
  477. package/src/traffic/groundTraffic.js +15 -0
  478. package/src/traffic/initTraffic.js +54 -0
  479. package/src/traffic/loadTraffic.js +15 -0
  480. package/src/traffic/loadedTrafficLanes.js +16 -0
  481. package/src/traffic/locateTraffic.js +9 -0
  482. package/src/traffic/moveTraffic.js +15 -0
  483. package/src/traffic/placeTraffic.js +21 -0
  484. package/src/traffic/prepareTraffic.js +25 -0
  485. package/src/traffic/readyTraffic.js +6 -0
  486. package/src/traffic/rebaseTraffic.js +58 -0
  487. package/src/traffic/rebuildTrafficMesh.js +28 -0
  488. package/src/traffic/removeTraffic.js +17 -0
  489. package/src/traffic/routeColor.js +6 -0
  490. package/src/traffic/routeGeometry.js +31 -0
  491. package/src/traffic/scheduledTrips.js +40 -0
  492. package/src/traffic/startTraffic.js +8 -0
  493. package/src/traffic/tickTraffic.js +57 -0
  494. package/src/traffic/toLanes.js +16 -0
  495. package/src/traffic/tooltip.js +11 -0
  496. package/src/traffic/trafficBounds.js +17 -0
  497. package/src/traffic/trafficNow.js +4 -0
  498. package/src/traffic/trafficStorage.js +5 -0
  499. package/src/traffic/tripsAt.js +27 -0
  500. package/src/traffic/updateTraffic.js +8 -0
  501. package/src/traffic/updateTrafficTerrain.js +12 -0
  502. package/src/traffic/vehicleOffsets.js +11 -0
  503. package/src/triangulation/area.js +9 -0
  504. package/src/triangulation/clean.js +18 -0
  505. package/src/triangulation/containsVertex.js +11 -0
  506. package/src/triangulation/cross.js +3 -0
  507. package/src/triangulation/crossesBoundary.js +8 -0
  508. package/src/triangulation/crossesRing.js +9 -0
  509. package/src/triangulation/equal.js +3 -0
  510. package/src/triangulation/inside.js +10 -0
  511. package/src/triangulation/insideHole.js +7 -0
  512. package/src/triangulation/intersects.js +11 -0
  513. package/src/triangulation/isClockWise.js +13 -0
  514. package/src/triangulation/minimumX.js +6 -0
  515. package/src/triangulation/on.js +4 -0
  516. package/src/triangulation/sortHoles.js +26 -0
  517. package/src/triangulation/triangulate.js +86 -0
  518. package/src/utils/channel.js +4 -0
  519. package/src/utils/compareDistance.js +3 -0
  520. package/src/utils/noOperation.js +1 -0
  521. package/src/utils/parseColor.js +42 -0
  522. package/src/utils/toSRGB.js +3 -0
  523. package/src/utils/wrap.js +3 -0
  524. package/src/vehicles/bicycleModel.js +23 -0
  525. package/src/vehicles/boatBenches.js +8 -0
  526. package/src/vehicles/boatModel.js +27 -0
  527. package/src/vehicles/busModel.js +6 -0
  528. package/src/vehicles/carModel.js +22 -0
  529. package/src/vehicles/carriage.js +19 -0
  530. package/src/vehicles/metroModel.js +9 -0
  531. package/src/vehicles/mirror.js +8 -0
  532. package/src/vehicles/pedestrianModel.js +17 -0
  533. package/src/vehicles/tramModel.js +9 -0
  534. package/src/walk/blocked.js +6 -0
  535. package/src/walk/createWalk.js +60 -0
  536. package/src/walk/initWalk.js +18 -0
  537. package/src/walk/initialize.js +6 -0
  538. package/src/walk/local.js +10 -0
  539. package/src/walk/onAdd.js +4 -0
  540. package/src/walk/onBlur.js +3 -0
  541. package/src/walk/onKey.js +12 -0
  542. package/src/walk/onPointer.js +13 -0
  543. package/src/walk/onRemove.js +4 -0
  544. package/src/walk/onTerrain.js +5 -0
  545. package/src/walk/place.js +18 -0
  546. package/src/walk/start.js +37 -0
  547. package/src/walk/step.js +53 -0
  548. package/src/walk/stop.js +27 -0
  549. package/src/walk/toggle.js +6 -0
  550. package/dist/scene/gpu.js +0 -3
  551. package/dist/scene/gpu.js.map +0 -7
  552. package/dist/scene/lighting.js +0 -9
  553. package/dist/scene/lighting.js.map +0 -7
  554. package/dist/scene/model.js +0 -2
  555. package/dist/scene/model.js.map +0 -7
  556. package/dist/scene/picking.js +0 -2
  557. package/dist/scene/picking.js.map +0 -7
  558. package/dist/scene/pmtiles.js +0 -2
  559. package/dist/scene/pmtiles.js.map +0 -7
  560. package/dist/scene/render.js +0 -15
  561. package/dist/scene/render.js.map +0 -7
  562. package/dist/scene/sources.js +0 -2
  563. package/dist/scene/sources.js.map +0 -7
  564. package/dist/types/3d.js +0 -2
  565. package/dist/types/3d.js.map +0 -7
  566. package/dist/types/geojson.js +0 -2
  567. package/dist/types/geojson.js.map +0 -7
  568. package/dist/types/pmtiles.js +0 -2
  569. package/dist/types/pmtiles.js.map +0 -7
  570. package/dist/types/sunlight.js +0 -2
  571. package/dist/types/sunlight.js.map +0 -7
  572. package/dist/types/terrain.js +0 -24
  573. package/dist/types/terrain.js.map +0 -7
  574. package/dist/types/traffic.js +0 -41
  575. package/dist/types/traffic.js.map +0 -7
  576. package/dist/types/walk.js +0 -2
  577. package/dist/types/walk.js.map +0 -7
  578. package/dist/utils/control.js +0 -2
  579. package/dist/utils/control.js.map +0 -7
  580. package/dist/utils/geometry.js +0 -2
  581. package/dist/utils/geometry.js.map +0 -7
  582. package/dist/utils/lighting.js +0 -2
  583. package/dist/utils/lighting.js.map +0 -7
  584. package/dist/utils/model.js +0 -2
  585. package/dist/utils/model.js.map +0 -7
  586. package/dist/utils/picking.js +0 -2
  587. package/dist/utils/picking.js.map +0 -7
  588. package/dist/utils/pmtiles.js +0 -2
  589. package/dist/utils/pmtiles.js.map +0 -7
  590. package/dist/utils/scene.js +0 -2
  591. package/dist/utils/scene.js.map +0 -7
  592. package/dist/utils/shaders.js +0 -203
  593. package/dist/utils/shaders.js.map +0 -7
  594. package/dist/utils/sun.js +0 -2
  595. package/dist/utils/sun.js.map +0 -7
  596. package/dist/utils/terrain.js +0 -2
  597. package/dist/utils/terrain.js.map +0 -7
  598. package/dist/utils/traffic.js +0 -2
  599. package/dist/utils/traffic.js.map +0 -7
  600. package/dist/utils/vehicles.js +0 -2
  601. package/dist/utils/vehicles.js.map +0 -7
  602. package/dist/utils/walk.js +0 -2
  603. package/dist/utils/walk.js.map +0 -7
  604. package/src/scene/gpu.js +0 -438
  605. package/src/scene/lighting.js +0 -193
  606. package/src/scene/model.js +0 -204
  607. package/src/scene/picking.js +0 -150
  608. package/src/scene/pmtiles.js +0 -94
  609. package/src/scene/render.js +0 -467
  610. package/src/scene/sources.js +0 -265
  611. package/src/types/3d.js +0 -337
  612. package/src/types/geojson.js +0 -42
  613. package/src/types/pmtiles.js +0 -143
  614. package/src/types/sunlight.js +0 -142
  615. package/src/types/terrain.js +0 -331
  616. package/src/types/traffic.js +0 -356
  617. package/src/types/walk.js +0 -219
  618. package/src/utils/control.js +0 -18
  619. package/src/utils/geometry.js +0 -256
  620. package/src/utils/lighting.js +0 -51
  621. package/src/utils/model.js +0 -178
  622. package/src/utils/picking.js +0 -119
  623. package/src/utils/pmtiles.js +0 -79
  624. package/src/utils/scene.js +0 -102
  625. package/src/utils/sun.js +0 -71
  626. package/src/utils/terrain.js +0 -78
  627. package/src/utils/traffic.js +0 -90
  628. package/src/utils/vehicles.js +0 -69
  629. package/src/utils/walk.js +0 -72
@@ -1,356 +0,0 @@
1
- import './3d.js';
2
- import { computeBounds } from '../utils/geometry.js';
3
- import { along, speed, toLanes, tripsAt, routeGeometry } from '../utils/traffic.js';
4
- import { build, vehicles } from '../utils/vehicles.js';
5
- import { underEntry } from '../utils/control.js';
6
-
7
- const tooltip = ({ properties: p }) => {
8
- const content = document.createElement('div');
9
- content.style.whiteSpace = 'pre-line';
10
- content.textContent = [p.name, p.departure && `Departure ${p.departure} ${p.timetable.timeZone}`, p.description].filter(Boolean).join('\n');
11
- return content;
12
- };
13
-
14
- function installTraffic(layer, { url, model, lights, side, outline, velocity }) {
15
- const L = globalThis.L;
16
- // The 'sunlight' layer on the same map drives the simulation time; without one, vehicles run live.
17
- const now = () => {
18
- let control = { live: true };
19
- layer._map?.eachLayer(other => { if (other.control?.time) control = other.control; });
20
- return { live: control.live, time: control.live ? new Date() : control.time };
21
- };
22
- const status = L.DomUtil.create('small', 'traffic-status');
23
- status.style.cssText = 'display:block;max-width:200px;margin:0 0 4px 20px;color:#555;';
24
- const template = build(model(0)), stride = template.position.length, vertices = stride / 3;
25
- let ready = false, frame, request, lanes = [], tripsKey, mesh, route, litAt = -Infinity;
26
- // Vehicles move on the GPU: `trips` are rebased at most once per second, a compute pass places them every frame.
27
- let trips = [], rebasedAt = 0, nextCheck = -Infinity, elapsed = 0, gpu = null, lanesDirty = true, stale = false;
28
- const params = new ArrayBuffer(16), paramFloats = new Float32Array(params), paramInts = new Uint32Array(params);
29
-
30
- const createMesh = (data, featureFaces, material, usage = 0) => {
31
- const result = layer._createMesh(data, material, usage);
32
- result.extras.featureFaces = featureFaces;
33
- return result;
34
- };
35
- const dispose = object => {
36
- if (!object) return;
37
- if (layer.highlightedFeature?.mesh === object) {
38
- layer._setHighlight(null);
39
- layer.hoveredFeature = null;
40
- layer._showFeature(null);
41
- }
42
- layer._disposeMesh(object);
43
- };
44
- const fail = error => {
45
- status.textContent = `Error: ${error.message}`;
46
- status.setAttribute('role', 'alert');
47
- console.error('Traffic layer', error);
48
- };
49
-
50
- const ground = () => {
51
- const terrain = layer._map._terrain3D?._terrainReady && layer._map._terrain3D, base = layer.root.position[1];
52
- for (const lane of lanes) lane.points.forEach((point, i) => {
53
- const elevation = terrain && (lane.elevation ?? terrain._getElevation(lane.latlngs[i]));
54
- point[2] = Number.isFinite(elevation) && Number.isFinite(base) ? elevation - base : 0;
55
- });
56
- lanesDirty = true;
57
- nextCheck = -Infinity;
58
- };
59
- const prepare = () => {
60
- const crs = layer._map.options.crs, origin = crs.project(layer.location);
61
- const metres = Math.cos(layer.location.lat * Math.PI / 180);
62
- for (const lane of lanes) {
63
- lane.points = lane.latlngs.map(([lat, lng]) => {
64
- const point = crs.project(new L.LatLng(lat, lng));
65
- return [(point.x - origin.x) * metres, -(point.y - origin.y) * metres, 0];
66
- });
67
- lane.lengths = [0];
68
- for (let i = 1; i < lane.points.length; i++) {
69
- 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]));
70
- }
71
- lane.length = lane.lengths.at(-1);
72
- }
73
- ground();
74
- dispose(route); route = null;
75
- tripsKey = null;
76
- };
77
-
78
- // Dashed lane outline, just above the lanes.
79
- const drawRoute = () => {
80
-
81
- route = createMesh(routeGeometry(lanes), [], { emissive: [0.03, 0.25, 0.3], alphaMode: 'BLEND' });
82
- route.renderOrder = 1000;
83
- };
84
- // One batched mesh, `vertices` per vehicle; the compute pass writes its position/normal buffers (STORAGE).
85
- const rebuild = () => {
86
- dispose(mesh); mesh = null;
87
- if (!trips.length) return;
88
- const color = trips.flatMap((trip, i) => build(model(i)).color), count = color.length / 3;
89
- mesh = createMesh({ position: color.map(() => 0), normal: color.map(() => 0), color },
90
- trips.map((trip, i) => ({ id: trip.id, properties: trip.properties, faceStart: i * vertices / 3, faceEnd: (i + 1) * vertices / 3,
91
- vertexStart: i * vertices, vertexEnd: (i + 1) * vertices })), {}, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC);
92
- mesh.geometry.drawRange.count = count;
93
- bounds();
94
- };
95
- // Vehicles never leave their lanes: cull and pick against the lanes' extent.
96
- const bounds = () => {
97
- const extent = { attributes: { position: { data: lanes.flatMap(lane => lane.points.flatMap(([x, z, y]) => [x - 20, y, z - 20, x + 20, y + 5, z + 20])) } } };
98
- computeBounds(extent);
99
- mesh.geometry.bounds = extent.bounds;
100
- };
101
-
102
- const destroyGpu = () => {
103
- for (const buffer of [gpu?.params, gpu?.template, gpu?.points, gpu?.vehicles]) buffer?.destroy();
104
- gpu = null;
105
- };
106
- const storage = (device, data) => {
107
- const buffer = device.createBuffer({ size: Math.max(16, data.byteLength), usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST });
108
- device.queue.writeBuffer(buffer, 0, data);
109
- return buffer;
110
- };
111
- // Lane points are [x, z, ground, cumulative length]. Mirrors along() and place().
112
- const shader = `
113
- struct Params { seconds: f32, side: f32, vertices: u32, total: u32 }
114
- struct Vehicle { start: u32, count: u32, base: f32, speed: f32 }
115
- @group(0) @binding(0) var<uniform> params: Params;
116
- @group(0) @binding(1) var<storage, read> model: array<f32>;
117
- @group(0) @binding(2) var<storage, read> points: array<vec4f>;
118
- @group(0) @binding(3) var<storage, read> vehicles: array<Vehicle>;
119
- @group(0) @binding(4) var<storage, read_write> position: array<f32>;
120
- @group(0) @binding(5) var<storage, read_write> normal: array<f32>;
121
- @compute @workgroup_size(64)
122
- fn main(@builtin(global_invocation_id) id: vec3u) {
123
- let v = id.x;
124
- if (v >= params.total) { return; }
125
- let vehicle = vehicles[v / params.vertices];
126
- let last = vehicle.start + vehicle.count - 1u;
127
- let length = points[last].w;
128
- var s = vehicle.base + params.seconds * vehicle.speed;
129
- s -= length * floor(s / length);
130
- var i = vehicle.start + 1u;
131
- while (i < last && points[i].w < s) { i++; }
132
- let a = points[i - 1u];
133
- let b = points[i];
134
- let d = select(b.w - a.w, 1.0, b.w == a.w);
135
- let t = (s - a.w) / d;
136
- let dx = (b.x - a.x) / d;
137
- let dz = (b.y - a.y) / d;
138
- let cx = a.x + (b.x - a.x) * t - dz * params.side;
139
- let cz = a.y + (b.y - a.y) * t + dx * params.side;
140
- let y = a.z + (b.z - a.z) * t;
141
- let k = (v % params.vertices) * 3u;
142
- let n = params.vertices * 3u + k;
143
- let o = v * 3u;
144
- position[o] = cx - model[k] * dz - model[k + 2u] * dx;
145
- position[o + 1u] = y + model[k + 1u];
146
- position[o + 2u] = cz + model[k] * dx - model[k + 2u] * dz;
147
- normal[o] = -model[n] * dz - model[n + 2u] * dx;
148
- normal[o + 1u] = model[n + 1u];
149
- normal[o + 2u] = model[n] * dx - model[n + 2u] * dz;
150
- }`;
151
- // Upload lanes and the rebased trips; the CPU copy is refreshed only for picking (place()).
152
- const rebase = () => {
153
- const { device } = layer.renderer;
154
- if (gpu?.device !== device) {
155
- destroyGpu();
156
- gpu = {
157
- device,
158
- pipeline: device.createComputePipeline({ layout: 'auto', compute: { module: device.createShaderModule({ code: shader }), entryPoint: 'main' } }),
159
- params: device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }),
160
- template: storage(device, new Float32Array([...template.position, ...template.normal])),
161
- };
162
- lanesDirty = true;
163
- }
164
- if (lanesDirty) {
165
- const data = new Float32Array(lanes.reduce((count, lane) => count + lane.points.length, 0) * 4);
166
- let offset = 0;
167
- for (const lane of lanes) {
168
- lane.start = offset / 4;
169
- lane.points.forEach((point, i) => { data.set([point[0], point[1], point[2], lane.lengths[i]], offset); offset += 4; });
170
- }
171
- gpu.points?.destroy();
172
- gpu.points = storage(device, data);
173
- lanesDirty = false;
174
- }
175
- const data = new Float32Array(trips.length * 4), index = new Uint32Array(data.buffer);
176
- trips.forEach((trip, i) => {
177
- index[i * 4] = trip.lane.start;
178
- index[i * 4 + 1] = trip.lane.points.length;
179
- data[i * 4 + 2] = trip.distance;
180
- data[i * 4 + 3] = trip.speed;
181
- mesh.extras.featureFaces[i].properties = trip.properties;
182
- });
183
- if (gpu.vehicles?.size >= data.byteLength) device.queue.writeBuffer(gpu.vehicles, 0, data);
184
- else {
185
- gpu.vehicles?.destroy();
186
- gpu.vehicles = storage(device, data);
187
- }
188
- const { position, normal } = mesh.geometry.attributes;
189
- gpu.bindGroup = device.createBindGroup({
190
- layout: gpu.pipeline.getBindGroupLayout(0),
191
- entries: [gpu.params, gpu.template, gpu.points, gpu.vehicles, position.buffer, normal.buffer]
192
- .map((buffer, binding) => ({ binding, resource: { buffer } })),
193
- });
194
- };
195
- const move = seconds => {
196
- const { device } = gpu;
197
- paramFloats[0] = elapsed = seconds;
198
- paramFloats[1] = side;
199
- paramInts[2] = vertices;
200
- paramInts[3] = trips.length * vertices;
201
- device.queue.writeBuffer(gpu.params, 0, params);
202
- const encoder = device.createCommandEncoder(), pass = encoder.beginComputePass();
203
- pass.setPipeline(gpu.pipeline);
204
- pass.setBindGroup(0, gpu.bindGroup);
205
- pass.dispatchWorkgroups(Math.ceil(paramInts[3] / 64));
206
- pass.end();
207
- device.queue.submit([encoder.finish()]);
208
- stale = true;
209
- };
210
- // CPU twin of the compute pass: the centre of `trip` and its heading.
211
- const locate = trip => {
212
- const { points, lengths, length } = trip.lane;
213
- let distance = trip.distance + elapsed * trip.speed;
214
- distance -= length * Math.floor(distance / length);
215
- const { x, y, z, dx, dz } = along(points, lengths, distance);
216
- return { x: x - dz * side, y, z: z + dx * side, dx, dz };
217
- };
218
- // Run lazily before picking.
219
- const place = () => {
220
- if (!mesh || !stale) return;
221
- stale = false;
222
- const { position, normal } = mesh.geometry.attributes;
223
- trips.forEach((trip, i) => {
224
- const { x: cx, y, z: cz, dx, dz } = locate(trip);
225
- for (let k = 0, o = i * stride; k < stride; k += 3, o += 3) {
226
- const lx = template.position[k], lz = template.position[k + 2], nx = template.normal[k], nz = template.normal[k + 2];
227
- position.data[o] = cx - lx * dz - lz * dx;
228
- position.data[o + 1] = y + template.position[k + 1];
229
- position.data[o + 2] = cz + lx * dx - lz * dz;
230
- normal.data[o] = -nx * dz - nz * dx;
231
- normal.data[o + 1] = template.normal[k + 1];
232
- normal.data[o + 2] = nx * dx - nz * dz;
233
- }
234
- });
235
- };
236
- const raycast = layer.raycast;
237
- layer.raycast = function (...args) {
238
- place();
239
- return raycast.apply(this, args);
240
- };
241
-
242
- const tick = () => {
243
- frame = undefined;
244
- if (!ready || !layer._map) return;
245
- // Re-adding after the last GPU owner was removed can attach asynchronously.
246
- if (!layer.renderer) { frame = requestAnimationFrame(tick); return; }
247
- // A renderer change re-creates vertex buffers without STORAGE: rebuild the mesh.
248
- if (mesh && !(mesh.geometry.attributes.position.buffer.usage & GPUBufferUsage.STORAGE)) { tripsKey = null; nextCheck = -Infinity; }
249
- const { live, time } = now(), ms = time?.getTime(), valid = Number.isFinite(ms);
250
- let changed = false;
251
- // Trips only change at timetable/hour boundaries: re-check once per second while live.
252
- if (!live || !valid || !(ms >= rebasedAt && ms < nextCheck)) {
253
- let text;
254
- try {
255
- trips = valid ? tripsAt(time, lanes, velocity) : [];
256
- text = !valid ? 'Select a valid simulation date' : !loaded ? 'Loading…' :
257
- `${trips.length} vehicle${trips.length === 1 ? '' : 's'}${loaded.note ? ` · ${loaded.note}` : ''}`;
258
- } catch (error) { return fail(error); }
259
- rebasedAt = ms;
260
- nextCheck = ms + 1000;
261
- const key = trips.map(trip => trip.id).join();
262
- changed = key !== tripsKey || (outline && !route && lanes.length);
263
- if (outline && !route && lanes.length) drawRoute();
264
- if (key !== tripsKey) { rebuild(); tripsKey = key; }
265
- if (mesh) rebase();
266
- if (status.textContent !== text) status.textContent = text;
267
- status.removeAttribute('role');
268
- }
269
- if (mesh) move((ms - rebasedAt) / 1000);
270
- // ponytail: night point lights follow the vehicles at 10 Hz via the shared CPU light grid (~5 ms with thousands of lamps);
271
- // bin the lights in a compute pass if it shows up in profiles.
272
- if (mesh && lights && (!live || !(performance.now() - litAt < 100))) {
273
- litAt = performance.now();
274
- mesh.extras.lights = trips.flatMap(trip => {
275
- const { x, y, z, dx, dz } = locate(trip);
276
- return lights.map(({ position: [lx, ly, lz], ...light }) => ({ ...light, position: [x - lx * dz - lz * dx, y + ly, z + lx * dx - lz * dz] }));
277
- });
278
- }
279
- if (mesh || changed) layer.update();
280
- if (live && valid) frame = requestAnimationFrame(tick);
281
- };
282
- let loaded, file;
283
- // A JS module serves time-dependent lanes; anything else is a static GeoJSON file, fetched once.
284
- const fetchLanes = async (time, signal) => {
285
- const href = new URL(url, document.baseURI).href;
286
- if (/\.m?js(?:[?#]|$)/i.test(url)) return (await import(href)).default(time, layer, signal);
287
- if (!file) {
288
- const response = await fetch(href, { signal });
289
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
290
- file = await response.json();
291
- }
292
- return file;
293
- };
294
- const load = () => {
295
- const { time } = now();
296
- if (!Number.isFinite(time?.getTime())) return;
297
- request?.abort();
298
- const { signal } = request = new AbortController();
299
- fetchLanes(time, signal).then(data => {
300
- if (signal.aborted || !layer._map || data === loaded) return;
301
- loaded = data;
302
- lanes = toLanes(data);
303
- prepare();
304
- if (!frame) tick();
305
- }, error => { if (error.name !== 'AbortError') fail(error); });
306
- };
307
- // 'layerremove' fires once the clock layer has really left the map.
308
- const update = event => {
309
- if (event?.layer === layer) return;
310
- cancelAnimationFrame(frame);
311
- load();
312
- tick();
313
- };
314
- const terrain = () => {
315
- if (!lanes.length) return;
316
- ground();
317
- dispose(route); route = null;
318
- if (mesh) bounds();
319
- if (!frame) tick();
320
- };
321
- const start = () => {
322
- layer._map.off('simulationtimechange layerremove', update).on('simulationtimechange layerremove', update);
323
- layer._map.off('terrainchange', terrain).on('terrainchange', terrain);
324
- underEntry(layer, status);
325
- update();
326
- };
327
- layer.on('ready', () => { ready = true; if (layer._map) start(); });
328
- layer.on('add', () => { if (ready) start(); });
329
- layer.on('remove', () => {
330
- request?.abort();
331
- cancelAnimationFrame(frame); frame = undefined;
332
- layer._map.off('simulationtimechange layerremove', update).off('terrainchange', terrain);
333
- dispose(mesh); dispose(route); mesh = route = null;
334
- destroyGpu();
335
- lanes = []; trips = []; tripsKey = loaded = null;
336
- });
337
- }
338
-
339
- /**
340
- * Vehicles moving along GeoJSON lanes; a compute pass places them on the GPU every frame.
341
- * Source options:
342
- * - `url`: GeoJSON (Multi)LineStrings, or a JS module whose default export `(time, layer, signal)` returns them (time-dependent data);
343
- * - `vehicle`: 'car' (default) or 'boat'; `side`: offset right of the lane centreline in metres (vehicle default);
344
- * - `speed`: m/s of `flow` lanes; `outline`: draw the lanes.
345
- * Lane properties: `flow` (vehicles/h) or `timetable` (see scheduledTrips in utils/traffic.js), optional fixed `elevation`
346
- * in metres, `name`/`description` for the default tooltip. The status line (vehicle count, then the FeatureCollection `note`) sits under the layer's entry in the layers control.
347
- * The 'sunlight' layer on the same map drives the time; without one, vehicles run live.
348
- */
349
- L.Layer.types.traffic = L.Layer.types['3d'].extend({
350
- initialize({ url, vehicle = 'car', side, outline = false, speed: velocity = speed, ...options } = {}) {
351
- if (!url) throw new Error('Traffic needs a source url');
352
- if (!vehicles[vehicle]) throw new Error(`Unknown vehicle: ${vehicle}`);
353
- L.Layer.types['3d'].prototype.initialize.call(this, { tooltipContent: tooltip, nightLight: Boolean(vehicles[vehicle].lights), ...options });
354
- installTraffic(this, { url, ...vehicles[vehicle], side: side ?? vehicles[vehicle].side, outline, velocity });
355
- },
356
- });
package/src/types/walk.js DELETED
@@ -1,219 +0,0 @@
1
- import { CELL, collider, horizontalRay, parts, limbs } from '../utils/walk.js';
2
- import './3d.js';
3
- import { computeBounds } from '../utils/geometry.js';
4
- import { traverse, updateWorldMatrix } from '../utils/scene.js';
5
- import { build } from '../utils/vehicles.js';
6
-
7
- // W/S (↑/↓) run forward/back along the heading, A/D (←/→) turn: [forward, turn].
8
- const moves = { KeyW: [1, 0], ArrowUp: [1, 0], KeyS: [-1, 0], ArrowDown: [-1, 0], KeyD: [0, 1], ArrowRight: [0, 1], KeyA: [0, -1], ArrowLeft: [0, -1] };
9
- const wrap = angle => Math.atan2(Math.sin(angle), Math.cos(angle));
10
-
11
- // Horizontal normal of the nearest wall faced within `reach` metres of the feet at world (x, y, z), walking along
12
- // the unit (dx, dz); knee and chest rays, so arches and tree crowns above the head let the walker through.
13
- // ponytail: traffic vehicles and boats move on the GPU and are not obstacles.
14
- function hit(layer, x, y, z, dx, dz, reach) {
15
- const types = globalThis.L.Layer.types, skip = other => other === layer ||
16
- ['terrain', 'traffic'].some(name => types[name] && other instanceof types[name]);
17
- updateWorldMatrix(layer.scene);
18
- let best = reach, found = null;
19
- for (const other of layer._shared._layers) {
20
- if (skip(other)) continue;
21
- traverse(other.root, mesh => {
22
- if (!mesh.visible) return true;
23
- if (!mesh.geometry?.attributes?.position?.data || mesh.program?.depthTest === false) return;
24
- if (!mesh.geometry.bounds) computeBounds(mesh.geometry);
25
- const m = mesh.worldMatrix, { center: k, radius } = mesh.geometry.bounds;
26
- if (Math.hypot(m[0] * k[0] + m[4] * k[1] + m[8] * k[2] + m[12] - x, m[2] * k[0] + m[6] * k[1] + m[10] * k[2] + m[14] - z) >
27
- radius * Math.hypot(m[0], m[1], m[2]) + reach) return;
28
- const c = collider(mesh), ox = x - m[12] + c.origin[0], oy = y - m[13] + c.origin[1], oz = z - m[14] + c.origin[2];
29
- const seen = new Set();
30
- for (let ix = Math.floor(Math.min(ox, ox + dx * reach) / CELL); ix <= Math.floor(Math.max(ox, ox + dx * reach) / CELL); ix++)
31
- for (let iz = Math.floor(Math.min(oz, oz + dz * reach) / CELL); iz <= Math.floor(Math.max(oz, oz + dz * reach) / CELL); iz++)
32
- for (const t of c.cells.get(ix + ',' + iz) || []) {
33
- // Walls are one-way: walking out of a building (e.g. starting inside one) is allowed.
34
- if (seen.has(t) || dx * c.nrm[t * 2] + dz * c.nrm[t * 2 + 1] >= 0) continue;
35
- seen.add(t);
36
- for (const height of [0.4, 1.5]) {
37
- const d = horizontalRay(c.tri, t, ox, oy + height, oz, dx, dz);
38
- if (d >= 0 && d < best) { best = d; found = [c.nrm[t * 2], c.nrm[t * 2 + 1]]; }
39
- }
40
- }
41
- });
42
- }
43
- return found;
44
- }
45
-
46
- function installWalk(layer, { speed, distance, position }) {
47
- const L = globalThis.L, keys = new Set();
48
- // Map button (leaflet-bar look) toggling the walk; the key hint shows beside it while walking.
49
- const control = new L.Control({ position });
50
- const container = L.DomUtil.create('div', 'leaflet-bar leaflet-control');
51
- container.style.cssText = 'display:flex;align-items:center;background:#fff;';
52
- const button = L.DomUtil.create('button', '', container);
53
- button.type = 'button';
54
- button.title = 'Walk';
55
- button.setAttribute('aria-label', 'Walk');
56
- button.setAttribute('aria-pressed', 'false');
57
- button.textContent = '🚶';
58
- button.style.cssText = 'width:30px;height:30px;padding:0;border:0;border-radius:4px;background:#fff;font-size:18px;line-height:30px;cursor:pointer;';
59
- const hint = L.DomUtil.create('small', '', container);
60
- hint.style.cssText = 'display:none;padding:0 8px;color:#333;white-space:nowrap;';
61
- hint.textContent = 'W/S: run · A/D: turn · drag: look around · Esc: exit';
62
- L.DomEvent.disableClickPropagation(container);
63
- control.onAdd = () => container;
64
- let meshes, frame, last, swing = 0, saved, drag;
65
- // Walker state: position, compass heading (radians, clockwise from north) and stride phase.
66
- const state = layer.walker = { latlng: null, heading: 0, phase: 0 };
67
-
68
- // Feet position in this layer's root space.
69
- const local = () => {
70
- const map = layer._map, crs = map.options.crs, origin = crs.project(layer.location), metres = Math.cos(layer.location.lat * Math.PI / 180);
71
- const p = crs.project(state.latlng), terrain = map._terrain3D?._terrainReady && map._terrain3D;
72
- const ground = (terrain && terrain._getElevation(state.latlng)) || 0;
73
- return [(p.x - origin.x) * metres, ground - layer.root.position[1], -(p.y - origin.y) * metres];
74
- };
75
- const place = () => {
76
- const [x, y, z] = local();
77
- // Model forward is -z; a yaw of -heading turns it to the compass heading (x east, -z north).
78
- const yaw = -state.heading, cos = Math.cos(yaw), sin = Math.sin(yaw);
79
- limbs.forEach(([, px, py, sign], i) => {
80
- const mesh = meshes[i];
81
- mesh.position[0] = x + px * cos; mesh.position[1] = y + py; mesh.position[2] = z - px * sin;
82
- mesh.rotation[0] = sign * swing * Math.sin(state.phase);
83
- mesh.rotation[1] = yaw;
84
- });
85
- layer.update();
86
- };
87
-
88
- const step = now => {
89
- frame = requestAnimationFrame(step);
90
- const map = layer._map, dt = Math.min(0.1, (now - (last ?? now)) / 1000);
91
- last = now;
92
- if (!layer.renderer) return;
93
- let changed = false;
94
- if (!meshes) { meshes = limbs.map(([part]) => layer._createMesh(build(parts[part]))); changed = true; }
95
- let forward = 0, turn = 0;
96
- for (const key of keys) { forward += moves[key]?.[0] || 0; turn += moves[key]?.[1] || 0; }
97
- forward = Math.sign(forward); turn = Math.sign(turn);
98
- if (turn) { state.heading = wrap(state.heading + turn * 2.5 * dt); changed = true; }
99
- if (forward) {
100
- const metres = forward * speed * dt, { lat, lng } = state.latlng, { position, scale } = layer.root;
101
- let east = Math.sin(state.heading) * metres, north = Math.cos(state.heading) * metres;
102
- const feet = local().map((value, i) => position[i] + scale[i] * value);
103
- // World x is east, z south; keep 0.3 m from walls and slide along the one in the way.
104
- const blocked = () => {
105
- const length = Math.hypot(east, north);
106
- return length > 1e-6 && hit(layer, feet[0], feet[1], feet[2], east / length, -north / length, length + 0.3);
107
- };
108
- const wall = blocked();
109
- if (wall) {
110
- const into = east * wall[0] - north * wall[1];
111
- east -= into * wall[0]; north += into * wall[1];
112
- if (blocked()) east = north = 0;
113
- }
114
- state.latlng = new L.LatLng(lat + north / 111320, lng + east / (111320 * Math.cos(lat * Math.PI / 180)));
115
- state.phase += Math.hypot(east, north) / 1.6 * Math.PI;
116
- changed = true;
117
- }
118
- if (forward || turn) {
119
- // The camera (looking along -bearing) swings back behind the walker.
120
- const bearing = map.getBearing() * Math.PI / 180, behind = wrap(-state.heading - bearing);
121
- if (Math.abs(behind) > 1e-3) map._setPitchAndBearing(map.getPitch(), (bearing + behind * Math.min(1, dt * 4)) * 180 / Math.PI);
122
- map.setView(state.latlng, map.getZoom(), { animate: false });
123
- }
124
- const target = forward ? 0.9 : 0;
125
- if (Math.abs(swing - target) > 1e-3) { swing += (target - swing) * Math.min(1, dt * 10); changed = true; }
126
- if (changed) place();
127
- };
128
-
129
- const onKey = event => {
130
- // Text fields and sliders keep their keys; buttons and checkboxes (e.g. the Walk button, focused once clicked) don't.
131
- if (event.target.closest?.('input:not([type=checkbox], [type=radio]), select, textarea, [contenteditable]') ||
132
- event.ctrlKey || event.altKey || event.metaKey) return;
133
- if (event.type === 'keydown' && event.code === 'Escape') { stop(); return; }
134
- if (!moves[event.code]) return;
135
- event.preventDefault();
136
- if (event.type === 'keydown') keys.add(event.code); else keys.delete(event.code);
137
- };
138
- const onBlur = () => keys.clear();
139
- // Dragging only turns the camera around the walker: horizontal = bearing, vertical = pitch.
140
- const onPointer = event => {
141
- const map = layer._map;
142
- if (event.type === 'pointerdown') {
143
- if (event.button !== 0 || event.target.closest('.leaflet-control')) return;
144
- drag = { x: event.clientX, y: event.clientY };
145
- map.getContainer().setPointerCapture(event.pointerId);
146
- } else if (drag && event.type === 'pointermove') {
147
- map._setPitchAndBearing(Math.max(20, Math.min(85, map.getPitch() - (event.clientY - drag.y) * 0.2)),
148
- map.getBearing() - (event.clientX - drag.x) * 0.25);
149
- drag = { x: event.clientX, y: event.clientY };
150
- } else drag = null;
151
- };
152
- const onTerrain = () => { if (meshes) place(); };
153
-
154
- const start = () => {
155
- const map = layer._map;
156
- if (saved || !map) return;
157
- state.latlng = map.getCenter();
158
- // Zoom whose camera distance (1.5 viewport heights, as in scene/render.js) is about `distance` metres behind the walker.
159
- const pixelsPerMetre = map.getSize().y * 1.5 / distance;
160
- const zoom = Math.min(map.getMaxZoom(), Math.log2(pixelsPerMetre * 40075016.68557849 * Math.cos(state.latlng.lat * Math.PI / 180) / 256));
161
- saved = { zoom: map.getZoom(), pitch: map.getPitch(), scrollWheelZoom: map.options.scrollWheelZoom,
162
- handlers: ['dragging', 'keyboard', 'doubleClickZoom', 'boxZoom'].filter(name => map[name]?.enabled()) };
163
- for (const name of saved.handlers) map[name].disable();
164
- // Wheel zoom moves the camera closer or farther, keeping the walker centred.
165
- map.options.scrollWheelZoom = saved.scrollWheelZoom && 'center';
166
- state.heading = -map.getBearing() * Math.PI / 180;
167
- map.setView(state.latlng, zoom, { animate: false });
168
- map.setPitch(75);
169
- L.DomEvent.on(document, 'keydown keyup', onKey);
170
- L.DomEvent.on(window, 'blur', onBlur);
171
- L.DomEvent.on(map.getContainer(), 'pointerdown pointermove pointerup pointercancel', onPointer);
172
- map.on('terrainchange', onTerrain);
173
- button.setAttribute('aria-pressed', 'true');
174
- button.style.background = '#e4e4e4';
175
- hint.style.display = '';
176
- last = undefined;
177
- frame = requestAnimationFrame(step);
178
- };
179
- const stop = () => {
180
- const map = layer._map;
181
- cancelAnimationFrame(frame);
182
- keys.clear(); drag = null;
183
- L.DomEvent.off(document, 'keydown keyup', onKey);
184
- L.DomEvent.off(window, 'blur', onBlur);
185
- for (const mesh of meshes || []) layer._disposeMesh(mesh);
186
- meshes = null;
187
- button.setAttribute('aria-pressed', 'false');
188
- button.style.background = '#fff';
189
- hint.style.display = 'none';
190
- if (!map || !saved) return;
191
- L.DomEvent.off(map.getContainer(), 'pointerdown pointermove pointerup pointercancel', onPointer);
192
- map.off('terrainchange', onTerrain);
193
- map.options.scrollWheelZoom = saved.scrollWheelZoom;
194
- for (const name of saved.handlers) map[name].enable();
195
- map.setView(state.latlng, saved.zoom, { animate: false });
196
- map.setPitch(saved.pitch);
197
- saved = null;
198
- };
199
- L.DomEvent.on(button, 'click', () => (saved ? stop() : start()));
200
- let ready = false;
201
- layer.on('ready', () => { ready = true; if (layer._map) control.addTo(layer._map); });
202
- layer.on('add', () => { if (ready) control.addTo(layer._map); });
203
- layer.on('remove', () => { stop(); control.remove(); });
204
- }
205
-
206
- /**
207
- * Third-person walk mode, toggled by a map button (and Esc): a pedestrian at the map centre runs with W/S (or ↑/↓) and
208
- * turns with A/D (or ←/→); the camera swings back behind it while it moves. Dragging the map only turns the camera
209
- * (bearing, pitch); the wheel changes the camera distance.
210
- * The walker follows the terrain, bridges included, and `layer.walker` exposes `{ latlng, heading, phase }`.
211
- * Source options: `speed` (m/s, default 6), `distance` (camera distance in metres, default 20), `position` (button corner, default 'topleft').
212
- * Visible meshes of the other 3D layers (buildings, trees, models, streetlights) are solid; terrain and traffic are not.
213
- */
214
- L.Layer.types.walk = L.Layer.types['3d'].extend({
215
- initialize({ speed = 70, distance = 20, position = 'bottomright', ...options } = {}) {
216
- L.Layer.types['3d'].prototype.initialize.call(this, options);
217
- installWalk(this, { speed, distance, position });
218
- },
219
- });
@@ -1,18 +0,0 @@
1
- /**
2
- * Keeps `element` right under `layer`'s entry in the map's layers control while the layer is on the map.
3
- * Returns false when no layers control lists the layer.
4
- */
5
- export function underEntry(layer, element) {
6
- const map = layer._map;
7
- const place = () => {
8
- const input = [...map.getContainer().querySelectorAll('.leaflet-control-layers-selector')]
9
- .find(input => input.layerId === globalThis.L.Util.stamp(layer));
10
- input?.closest('label').after(element);
11
- return Boolean(input);
12
- };
13
- // Leaflet rebuilds the list after 'layeradd'/'layerremove' (on the layer's own 'add'/'remove'): re-place afterwards.
14
- const replace = () => queueMicrotask(() => map.hasLayer(layer) && place());
15
- map.on('layeradd layerremove', replace);
16
- layer.once('remove', () => { map.off('layeradd layerremove', replace); element.remove(); });
17
- return place();
18
- }