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.
- package/README.md +61 -13
- package/cucumber.mjs +4 -0
- package/dist/leaflet-city-mapper.js +3 -1
- package/dist/leaflet-city-mapper.js.map +4 -4
- package/package.json +3 -4
- package/src/archives/decodeDirectory.js +32 -0
- package/src/archives/decodeHeader.js +19 -0
- package/src/archives/decompress.js +5 -0
- package/src/archives/getHeader.js +9 -0
- package/src/archives/getZxy.js +75 -0
- package/src/archives/loadDirectory.js +7 -0
- package/src/archives/loadSource.js +17 -0
- package/src/archives/read.js +29 -0
- package/src/archives/tileId.js +19 -0
- package/src/archives/varint.js +15 -0
- package/src/camera/angles.js +6 -0
- package/src/camera/animationPoint.js +8 -0
- package/src/camera/cameraMapReady.js +8 -0
- package/src/camera/cancelCameraAnimation.js +11 -0
- package/src/camera/cleanupCameraMap.js +11 -0
- package/src/camera/constrainCameraToBounds.js +3 -0
- package/src/camera/displayPoint.js +3 -0
- package/src/camera/fitCameraBounds.js +48 -0
- package/src/camera/groundBounds.js +11 -0
- package/src/camera/initializeCameraMap.js +25 -0
- package/src/camera/mapAnimateCamera.js +17 -0
- package/src/camera/mapCamera.js +123 -0
- package/src/camera/mapContainerPointToLayerPoint.js +7 -0
- package/src/camera/mapGetBearing.js +1 -0
- package/src/camera/mapGetBounds.js +14 -0
- package/src/camera/mapGetBoundsCenterZoom.js +7 -0
- package/src/camera/mapGetBoundsZoom.js +14 -0
- package/src/camera/mapGetCenterLayerPoint.js +5 -0
- package/src/camera/mapGetPitch.js +1 -0
- package/src/camera/mapLayerPointToContainerPoint.js +7 -0
- package/src/camera/mapLimitCenter.js +12 -0
- package/src/camera/mapLimitOffset.js +10 -0
- package/src/camera/mapPanBy.js +9 -0
- package/src/camera/mapPanInside.js +14 -0
- package/src/camera/mapResetNorth.js +1 -0
- package/src/camera/mapResetNorthPitch.js +1 -0
- package/src/camera/mapSetBearing.js +1 -0
- package/src/camera/mapSetPitch.js +1 -0
- package/src/camera/mapSetPitchAndBearing.js +14 -0
- package/src/camera/mapSetZoomAround.js +11 -0
- package/src/camera/mapStopPitchBearingAnimation.js +6 -0
- package/src/camera/mapTryAnimatedPan.js +9 -0
- package/src/camera/mapUpdateCameraOverlays.js +7 -0
- package/src/camera/pointOf.js +3 -0
- package/src/camera/project.js +20 -0
- package/src/camera/runCameraAnimations.js +28 -0
- package/src/camera/scheduleCameraAnimation.js +8 -0
- package/src/camera/updateSky.js +16 -0
- package/src/camera/verticalGroundY.js +4 -0
- package/src/collision/collectMeshes.js +5 -0
- package/src/collision/collider.js +63 -0
- package/src/collision/horizontalRay.js +12 -0
- package/src/collision/intersectMeshes.js +133 -0
- package/src/collision/sortHits.js +23 -0
- package/src/constants/CELL.js +4 -0
- package/src/constants/Compass.js +7 -0
- package/src/constants/ContainerResize.js +7 -0
- package/src/constants/HEIGHT.js +1 -0
- package/src/constants/PitchDrag.js +7 -0
- package/src/constants/ShiftRotate.js +7 -0
- package/src/constants/TILE_RADIUS.js +1 -0
- package/src/constants/TILE_SIZE.js +1 -0
- package/src/constants/TouchMode.js +6 -0
- package/src/constants/accessorSizes.js +1 -0
- package/src/constants/accessorTypes.js +8 -0
- package/src/constants/attachState.js +1 -0
- package/src/constants/cameraControlsState.js +1 -0
- package/src/constants/cityMapper.js +6 -0
- package/src/constants/colliders.js +2 -0
- package/src/constants/dark.js +1 -0
- package/src/constants/elevationWGSL.js +27 -0
- package/src/constants/glass.js +1 -0
- package/src/constants/headlight.js +1 -0
- package/src/constants/hull.js +1 -0
- package/src/constants/indexState.js +1 -0
- package/src/constants/limbs.js +9 -0
- package/src/constants/mapCameraState.js +1 -0
- package/src/constants/moves.js +11 -0
- package/src/constants/nativeEventMaps.js +1 -0
- package/src/constants/nativeLayerState.js +1 -0
- package/src/constants/nativeMethodHandlers.js +31 -0
- package/src/constants/onMapChangeState.js +1 -0
- package/src/constants/onZoomAnimState.js +1 -0
- package/src/constants/paints.js +10 -0
- package/src/constants/parts.js +19 -0
- package/src/constants/pendingUpdates.js +1 -0
- package/src/constants/pumpState.js +1 -0
- package/src/constants/renderers.js +2 -0
- package/src/constants/ringDirections.js +10 -0
- package/src/constants/roundProfile.js +1 -0
- package/src/constants/shirt.js +1 -0
- package/src/constants/skin.js +2 -0
- package/src/constants/speed.js +3 -0
- package/src/constants/taillight.js +1 -0
- package/src/constants/trafficShader.js +49 -0
- package/src/constants/trousers.js +1 -0
- package/src/constants/tyre.js +1 -0
- package/src/constants/underEntryState.js +1 -0
- package/src/constants/vehicles.js +40 -0
- package/src/constants/white.js +1 -0
- package/src/controls/acceptPitchDrag.js +4 -0
- package/src/controls/acceptRotateDrag.js +3 -0
- package/src/controls/adjustCameraDrag.js +10 -0
- package/src/controls/cameraControls.js +60 -0
- package/src/controls/cameraDragClick.js +9 -0
- package/src/controls/cameraDragContextMenu.js +8 -0
- package/src/controls/cameraDragDown.js +20 -0
- package/src/controls/cameraDragEnd.js +6 -0
- package/src/controls/cameraDragMove.js +23 -0
- package/src/controls/changeCameraTouch.js +14 -0
- package/src/controls/cleanupCameraTouch.js +24 -0
- package/src/controls/compassAddHooks.js +15 -0
- package/src/controls/compassOrientation.js +6 -0
- package/src/controls/compassRemoveHooks.js +5 -0
- package/src/controls/containerResizeAddHooks.js +8 -0
- package/src/controls/containerResizeRemoveHooks.js +5 -0
- package/src/controls/dragCamera.js +22 -0
- package/src/controls/editable.js +3 -0
- package/src/controls/endAllCameraDrags.js +7 -0
- package/src/controls/endAllCameraTouches.js +7 -0
- package/src/controls/endCameraTouch.js +11 -0
- package/src/controls/endCameraTouchEvent.js +5 -0
- package/src/controls/finishCameraDrag.js +9 -0
- package/src/controls/finishCompassPermission.js +16 -0
- package/src/controls/loadCameraControls.js +9 -0
- package/src/controls/moveCameraTouch.js +22 -0
- package/src/controls/notifyCameraTouchChange.js +1 -0
- package/src/controls/pitchDragAddHooks.js +6 -0
- package/src/controls/pitchDragRemoveHooks.js +5 -0
- package/src/controls/refreshRotateControl.js +7 -0
- package/src/controls/refreshRotateFocus.js +5 -0
- package/src/controls/removeCameraDrag.js +23 -0
- package/src/controls/resizeMap.js +3 -0
- package/src/controls/rotateButtonClick.js +7 -0
- package/src/controls/rotateButtonKeydown.js +11 -0
- package/src/controls/rotateControl.js +3 -0
- package/src/controls/rotateOnAdd.js +38 -0
- package/src/controls/rotateOnRemove.js +6 -0
- package/src/controls/shiftRotateAddHooks.js +8 -0
- package/src/controls/shiftRotateRemoveHooks.js +5 -0
- package/src/controls/shiftRotateWheel.js +9 -0
- package/src/controls/startCameraTouch.js +23 -0
- package/src/core/addImageState.js +7 -0
- package/src/core/addRasterImage.js +10 -0
- package/src/core/adjustCameraMarkerPan.js +22 -0
- package/src/core/beforeNativeRender.js +10 -0
- package/src/core/boundsQuad.js +11 -0
- package/src/core/bringNativeLayerToBack.js +3 -0
- package/src/core/bringNativeLayerToFront.js +3 -0
- package/src/core/cameraCircleBounds.js +6 -0
- package/src/core/cameraMarkerDrag.js +18 -0
- package/src/core/cameraMarkerOnDrag.js +8 -0
- package/src/core/cancelGridFade.js +10 -0
- package/src/core/closestCameraLayerPoint.js +7 -0
- package/src/core/compareNativeHits.js +3 -0
- package/src/core/current.js +3 -0
- package/src/core/disposeNativeLayer.js +35 -0
- package/src/core/fireRasterLoad.js +5 -0
- package/src/core/forwardNativeError.js +3 -0
- package/src/core/gridlayerGetEvents.js +7 -0
- package/src/core/gridlayerGetTiledPixelBounds.js +8 -0
- package/src/core/handleNativeMapEvent.js +47 -0
- package/src/core/hideTargets.js +16 -0
- package/src/core/initNativeGPU.js +21 -0
- package/src/core/initializeGridContainer.js +6 -0
- package/src/core/initializeNativeLayer.js +42 -0
- package/src/core/localPixel.js +5 -0
- package/src/core/localPixelForGeometry.js +6 -0
- package/src/core/localPosition.js +6 -0
- package/src/core/markerCameraIconPoint.js +9 -0
- package/src/core/markerGetEvents.js +5 -0
- package/src/core/markerInitInteraction.js +8 -0
- package/src/core/markerQuadCorners.js +31 -0
- package/src/core/markerSetIcon.js +9 -0
- package/src/core/markerSetPos.js +14 -0
- package/src/core/markerSetRotation.js +7 -0
- package/src/core/markerUpdateZIndex.js +8 -0
- package/src/core/nativeAddLatLng.js +3 -0
- package/src/core/nativeBringToBack.js +3 -0
- package/src/core/nativeBringToFront.js +3 -0
- package/src/core/nativeEvents.js +26 -0
- package/src/core/nativeImageError.js +8 -0
- package/src/core/nativeImageRefresh.js +7 -0
- package/src/core/nativeLayer.js +97 -0
- package/src/core/nativeLayerMethod.js +21 -0
- package/src/core/nativeRedraw.js +3 -0
- package/src/core/nativeSetBounds.js +3 -0
- package/src/core/nativeSetIcon.js +3 -0
- package/src/core/nativeSetLatLng.js +3 -0
- package/src/core/nativeSetLatLngs.js +3 -0
- package/src/core/nativeSetOpacity.js +3 -0
- package/src/core/nativeSetRadius.js +3 -0
- package/src/core/nativeSetStyle.js +3 -0
- package/src/core/nativeSetUrl.js +3 -0
- package/src/core/nativeSetZIndex.js +3 -0
- package/src/core/nativeSetZIndexOffset.js +3 -0
- package/src/core/popupAdjustPan.js +23 -0
- package/src/core/popupGetEvents.js +5 -0
- package/src/core/popupUpdatePosition.js +14 -0
- package/src/core/putNativeMesh.js +33 -0
- package/src/core/quadNativeMesh.js +15 -0
- package/src/core/readyNativeGPU.js +6 -0
- package/src/core/refreshNativeEvent.js +5 -0
- package/src/core/refreshNativeLayer.js +29 -0
- package/src/core/refreshNativeLayerContract.js +3 -0
- package/src/core/rejectNativeReady.js +3 -0
- package/src/core/removeImageState.js +8 -0
- package/src/core/removeNativeEvents.js +16 -0
- package/src/core/removeTargets.js +8 -0
- package/src/core/reorderNativeLayer.js +6 -0
- package/src/core/resolveNativeReady.js +3 -0
- package/src/core/restoreNativeEvents.js +6 -0
- package/src/core/runGridFades.js +14 -0
- package/src/core/runMarkerPanFrame.js +12 -0
- package/src/core/scheduleGridFade.js +9 -0
- package/src/core/scheduleMarkerPan.js +8 -0
- package/src/core/styleNativeMesh.js +10 -0
- package/src/core/syncGridLayer.js +22 -0
- package/src/core/syncImageOverlay.js +9 -0
- package/src/core/syncMarker.js +12 -0
- package/src/core/syncVectorLayer.js +26 -0
- package/src/core/synchronizeNativeLayer.js +35 -0
- package/src/core/textureFor.js +48 -0
- package/src/core/tooltipGetEvents.js +5 -0
- package/src/core/tooltipSetPosition.js +8 -0
- package/src/core/updateGridOpacity.js +23 -0
- package/src/core/updateNativeLayerView.js +6 -0
- package/src/core/uploadCanvasTexture.js +19 -0
- package/src/geometry/addBridges.js +88 -0
- package/src/geometry/below.js +3 -0
- package/src/geometry/box.js +3 -0
- package/src/geometry/bridgeElevation.js +19 -0
- package/src/geometry/bridgeLocal.js +4 -0
- package/src/geometry/build.js +19 -0
- package/src/geometry/circleAt.js +5 -0
- package/src/geometry/clipLine.js +23 -0
- package/src/geometry/clipSegment.js +19 -0
- package/src/geometry/computeBounds.js +33 -0
- package/src/geometry/conformModelToTerrain.js +67 -0
- package/src/geometry/cross.js +3 -0
- package/src/geometry/disk.js +11 -0
- package/src/geometry/diskAt.js +4 -0
- package/src/geometry/dot.js +6 -0
- package/src/geometry/emitter.js +8 -0
- package/src/geometry/lampPostGeometry.js +24 -0
- package/src/geometry/lampRing.js +11 -0
- package/src/geometry/lightGeometry.js +15 -0
- package/src/geometry/line.js +54 -0
- package/src/geometry/nativeGeometry.js +55 -0
- package/src/geometry/nativeTriangle.js +3 -0
- package/src/geometry/polygon.js +22 -0
- package/src/geometry/push.js +3 -0
- package/src/geometry/quad.js +4 -0
- package/src/geometry/roofCoverage.js +52 -0
- package/src/geometry/samePoint.js +3 -0
- package/src/geometry/segment.js +21 -0
- package/src/geometry/setVertexColor.js +15 -0
- package/src/geometry/sub.js +6 -0
- package/src/geometry/surface.js +17 -0
- package/src/geometry/treeGeometry.js +31 -0
- package/src/geometry/treeRing.js +14 -0
- package/src/geometry/triangle.js +12 -0
- package/src/geometry/vertexNormals.js +32 -0
- package/src/geometry/visit.js +9 -0
- package/src/index.js +98 -65
- package/src/lighting/cacheLightGrid.js +23 -0
- package/src/lighting/collectLightMeshes.js +6 -0
- package/src/lighting/lightGrid.js +42 -0
- package/src/lighting/updatePointLights.js +34 -0
- package/src/lighting/visitCells.js +15 -0
- package/src/lighting/worldLights.js +27 -0
- package/src/models/decodeModel.js +45 -0
- package/src/models/hasUnsupportedPrimitives.js +10 -0
- package/src/models/loadBuffer.js +6 -0
- package/src/models/loadImage.js +15 -0
- package/src/models/loadModel.js +69 -0
- package/src/models/materialFor.js +21 -0
- package/src/models/modelNode.js +93 -0
- package/src/models/nodeMatrix.js +22 -0
- package/src/models/readAccessor.js +53 -0
- package/src/models/readAccessorValues.js +16 -0
- package/src/models/textureFor.js +35 -0
- package/src/models/textureSampler.js +10 -0
- package/src/picking/collectVisibleMesh.js +4 -0
- package/src/picking/findFeature.js +49 -0
- package/src/picking/hit.js +23 -0
- package/src/picking/hitMesh.js +30 -0
- package/src/picking/onClick.js +13 -0
- package/src/picking/onPointerLeave.js +11 -0
- package/src/picking/onPointerMove.js +15 -0
- package/src/picking/pointerClick.js +5 -0
- package/src/picking/pointerLeave.js +5 -0
- package/src/picking/pointerMove.js +5 -0
- package/src/picking/raycast.js +59 -0
- package/src/picking/setHighlight.js +13 -0
- package/src/picking/shouldSkipOther.js +3 -0
- package/src/picking/showFeature.js +34 -0
- package/src/raster/addRasterTile.js +114 -0
- package/src/raster/comparePendingTiles.js +5 -0
- package/src/raster/createGeometry.js +22 -0
- package/src/raster/createRasterMesh.js +47 -0
- package/src/raster/finishAttachment.js +11 -0
- package/src/raster/finishRasterTile.js +47 -0
- package/src/raster/getRasterEvents.js +6 -0
- package/src/raster/getRasterTileSize.js +5 -0
- package/src/raster/initRaster.js +38 -0
- package/src/raster/isLoading.js +5 -0
- package/src/raster/loadRasterTile.js +10 -0
- package/src/raster/onPMTileAdd.js +10 -0
- package/src/raster/onPMTileRemove.js +8 -0
- package/src/raster/pruneRasterTiles.js +37 -0
- package/src/raster/pumpRasterTiles.js +22 -0
- package/src/raster/readyRaster.js +13 -0
- package/src/raster/registerTerrainTile.js +12 -0
- package/src/raster/releaseRasterTile.js +18 -0
- package/src/raster/releaseRasterTiles.js +15 -0
- package/src/raster/removeRasterTile.js +13 -0
- package/src/raster/reportError.js +6 -0
- package/src/raster/setPMTileOpacity.js +7 -0
- package/src/raster/setPMTileZIndex.js +7 -0
- package/src/raster/setRasterOpacity.js +11 -0
- package/src/raster/setRasterTerrain.js +21 -0
- package/src/raster/setRasterZIndex.js +11 -0
- package/src/raster/updateAttachedTiles.js +10 -0
- package/src/raster/updateRasterTiles.js +59 -0
- package/src/rendering/collectFrameMeshes.js +31 -0
- package/src/rendering/collectMeshes.js +36 -0
- package/src/rendering/compareMeshes.js +10 -0
- package/src/rendering/compareRoofTiles.js +4 -0
- package/src/rendering/composeRoofAtlas.js +52 -0
- package/src/rendering/createMesh.js +33 -0
- package/src/rendering/createProgram.js +92 -0
- package/src/rendering/destroyAfterSubmission.js +8 -0
- package/src/rendering/destroyTexture.js +6 -0
- package/src/rendering/disposeMesh.js +14 -0
- package/src/rendering/drawGeometry.js +129 -0
- package/src/rendering/drawSceneMeshes.js +51 -0
- package/src/rendering/ensureRoofBlit.js +40 -0
- package/src/rendering/prepareFrameMeshes.js +42 -0
- package/src/rendering/prepareFrameUniforms.js +49 -0
- package/src/rendering/rebuildRoofAtlas.js +67 -0
- package/src/rendering/render.js +57 -0
- package/src/rendering/reportCompilation.js +17 -0
- package/src/rendering/resizeRenderer.js +19 -0
- package/src/rendering/sortMeshes.js +6 -0
- package/src/rendering/synchronizeZoomView.js +34 -0
- package/src/rendering/textureBinding.js +7 -0
- package/src/rendering/updateMapCamera.js +32 -0
- package/src/rendering/updateRoofRaster.js +32 -0
- package/src/scene/attach.js +161 -0
- package/src/scene/attachLayer.js +10 -0
- package/src/scene/cancelUpdate.js +10 -0
- package/src/scene/emptyEvents.js +3 -0
- package/src/scene/emptyNode.js +11 -0
- package/src/scene/endZoom.js +16 -0
- package/src/scene/failAttachment.js +9 -0
- package/src/scene/get3DEvents.js +13 -0
- package/src/scene/init3D.js +30 -0
- package/src/scene/initializeLayer.js +16 -0
- package/src/scene/initializerFor.js +14 -0
- package/src/scene/layerInitialize.js +38 -0
- package/src/scene/layerLayerAdd.js +21 -0
- package/src/scene/onAdd3DLayer.js +35 -0
- package/src/scene/onMapChange.js +16 -0
- package/src/scene/onRemove3DLayer.js +69 -0
- package/src/scene/onZoomAnim.js +16 -0
- package/src/scene/placeEntry.js +11 -0
- package/src/scene/placeUnderEntry.js +8 -0
- package/src/scene/ready3D.js +25 -0
- package/src/scene/releaseRenderer.js +14 -0
- package/src/scene/removeEntry.js +6 -0
- package/src/scene/renderPendingMapChange.js +11 -0
- package/src/scene/renderPendingUpdates.js +19 -0
- package/src/scene/renderPendingZoomAnimation.js +7 -0
- package/src/scene/rendererDeviceError.js +10 -0
- package/src/scene/rendererDeviceLost.js +11 -0
- package/src/scene/replaceEntry.js +7 -0
- package/src/scene/reportError.js +3 -0
- package/src/scene/requestAdapter.js +12 -0
- package/src/scene/requestDevice.js +9 -0
- package/src/scene/resolveNextInitialization.js +12 -0
- package/src/scene/restoreObject.js +71 -0
- package/src/scene/runPlacements.js +7 -0
- package/src/scene/setParent.js +7 -0
- package/src/scene/showWebGPUWarning.js +16 -0
- package/src/scene/startZoom.js +5 -0
- package/src/scene/traverse.js +7 -0
- package/src/scene/underEntry.js +17 -0
- package/src/scene/update.js +19 -0
- package/src/scene/updateCamera.js +34 -0
- package/src/scene/updateWorldMatrix.js +48 -0
- package/src/{utils/shaders.js → shaders/materialShaders.js} +246 -237
- package/src/shadows/bindSunlight.js +12 -0
- package/src/shadows/drawShadowMeshes.js +48 -0
- package/src/shadows/ensureShadowPipeline.js +53 -0
- package/src/shadows/renderSunlight.js +46 -0
- package/src/shadows/resizeSunlight.js +15 -0
- package/src/shadows/shadowBounds.js +32 -0
- package/src/shadows/shadowCacheMatches.js +23 -0
- package/src/shadows/shadowMatrix.js +39 -0
- package/src/sources/addGeneratedTriangle.js +6 -0
- package/src/sources/addTriangle.js +17 -0
- package/src/sources/attachAreaMesh.js +58 -0
- package/src/sources/buildArea.js +42 -0
- package/src/sources/buildAreaFeature.js +41 -0
- package/src/sources/buildAreaPoint.js +25 -0
- package/src/sources/buildAreaPolygon.js +29 -0
- package/src/sources/compareAreaDistance.js +4 -0
- package/src/sources/generateTreeGeometry.js +11 -0
- package/src/sources/groundOffset.js +3 -0
- package/src/sources/initializeGeoJSON.js +8 -0
- package/src/sources/instanceAreaGeometry.js +29 -0
- package/src/sources/projectRing.js +20 -0
- package/src/sources/projectedTree.js +13 -0
- package/src/sources/pump.js +54 -0
- package/src/sources/releaseArea.js +22 -0
- package/src/sources/setGeoJSONData.js +12 -0
- package/src/sources/setGeoJSONLayerData.js +5 -0
- package/src/sources/sourceAreaContext.js +9 -0
- package/src/sources/updateArea.js +45 -0
- package/src/sources/updateStatus.js +12 -0
- package/src/sunlight/addTimeLayer.js +3 -0
- package/src/sunlight/addTo.js +10 -0
- package/src/sunlight/atmosphere.js +28 -0
- package/src/sunlight/horizontalPosition.js +16 -0
- package/src/sunlight/initSunlight.js +14 -0
- package/src/sunlight/initialize.js +11 -0
- package/src/sunlight/mix.js +6 -0
- package/src/sunlight/moonPosition.js +17 -0
- package/src/sunlight/onAdd.js +5 -0
- package/src/sunlight/onAddSun.js +66 -0
- package/src/sunlight/projectCelestialBody.js +13 -0
- package/src/sunlight/remove.js +7 -0
- package/src/sunlight/removeSun.js +15 -0
- package/src/sunlight/removeTimeLayer.js +3 -0
- package/src/sunlight/render.js +7 -0
- package/src/sunlight/rgb.js +6 -0
- package/src/sunlight/solarPosition.js +17 -0
- package/src/sunlight/styleTimeControl.js +7 -0
- package/src/sunlight/tickSun.js +5 -0
- package/src/sunlight/updateSky.js +20 -0
- package/src/sunlight/updateSun.js +34 -0
- package/src/sunlight/useLiveTime.js +6 -0
- package/src/sunlight/useSelectedTime.js +20 -0
- package/src/terrain/clearLayerTerrain.js +5 -0
- package/src/terrain/getElevation.js +10 -0
- package/src/terrain/initTerrain.js +20 -0
- package/src/terrain/loadReadyTerrain.js +5 -0
- package/src/terrain/loadTerrain.js +63 -0
- package/src/terrain/loadTerrainTiles.js +13 -0
- package/src/terrain/onTerrainAdd.js +21 -0
- package/src/terrain/onTerrainChange.js +14 -0
- package/src/terrain/onTerrainRemove.js +41 -0
- package/src/terrain/readBridges.js +4 -0
- package/src/terrain/sample.js +7 -0
- package/src/terrain/setLayerTerrain.js +5 -0
- package/src/terrain/setTerrainHeight.js +10 -0
- package/src/terrain/terrainAtlas.js +23 -0
- package/src/terrain/terrainElevation.js +20 -0
- package/src/terrain/terrainGrid.js +24 -0
- package/src/traffic/addTraffic.js +7 -0
- package/src/traffic/along.js +14 -0
- package/src/traffic/clockMinutes.js +6 -0
- package/src/traffic/compareDepartures.js +5 -0
- package/src/traffic/createTrafficMesh.js +7 -0
- package/src/traffic/destroyTrafficGpu.js +5 -0
- package/src/traffic/disposeTrafficObject.js +13 -0
- package/src/traffic/drawTrafficRoute.js +6 -0
- package/src/traffic/failTraffic.js +6 -0
- package/src/traffic/failedTrafficLoad.js +5 -0
- package/src/traffic/fetchTrafficLanes.js +10 -0
- package/src/traffic/groundTraffic.js +15 -0
- package/src/traffic/initTraffic.js +54 -0
- package/src/traffic/loadTraffic.js +15 -0
- package/src/traffic/loadedTrafficLanes.js +16 -0
- package/src/traffic/locateTraffic.js +9 -0
- package/src/traffic/moveTraffic.js +15 -0
- package/src/traffic/placeTraffic.js +21 -0
- package/src/traffic/prepareTraffic.js +25 -0
- package/src/traffic/readyTraffic.js +6 -0
- package/src/traffic/rebaseTraffic.js +58 -0
- package/src/traffic/rebuildTrafficMesh.js +28 -0
- package/src/traffic/removeTraffic.js +17 -0
- package/src/traffic/routeColor.js +6 -0
- package/src/traffic/routeGeometry.js +31 -0
- package/src/traffic/scheduledTrips.js +40 -0
- package/src/traffic/startTraffic.js +8 -0
- package/src/traffic/tickTraffic.js +57 -0
- package/src/traffic/toLanes.js +16 -0
- package/src/traffic/tooltip.js +11 -0
- package/src/traffic/trafficBounds.js +17 -0
- package/src/traffic/trafficNow.js +4 -0
- package/src/traffic/trafficStorage.js +5 -0
- package/src/traffic/tripsAt.js +27 -0
- package/src/traffic/updateTraffic.js +8 -0
- package/src/traffic/updateTrafficTerrain.js +12 -0
- package/src/traffic/vehicleOffsets.js +11 -0
- package/src/triangulation/area.js +9 -0
- package/src/triangulation/clean.js +18 -0
- package/src/triangulation/containsVertex.js +11 -0
- package/src/triangulation/cross.js +3 -0
- package/src/triangulation/crossesBoundary.js +8 -0
- package/src/triangulation/crossesRing.js +9 -0
- package/src/triangulation/equal.js +3 -0
- package/src/triangulation/inside.js +10 -0
- package/src/triangulation/insideHole.js +7 -0
- package/src/triangulation/intersects.js +11 -0
- package/src/triangulation/isClockWise.js +13 -0
- package/src/triangulation/minimumX.js +6 -0
- package/src/triangulation/on.js +4 -0
- package/src/triangulation/sortHoles.js +26 -0
- package/src/triangulation/triangulate.js +86 -0
- package/src/utils/channel.js +4 -0
- package/src/utils/compareDistance.js +3 -0
- package/src/utils/noOperation.js +1 -0
- package/src/utils/parseColor.js +42 -0
- package/src/utils/toSRGB.js +3 -0
- package/src/utils/wrap.js +3 -0
- package/src/vehicles/bicycleModel.js +23 -0
- package/src/vehicles/boatBenches.js +8 -0
- package/src/vehicles/boatModel.js +27 -0
- package/src/vehicles/busModel.js +6 -0
- package/src/vehicles/carModel.js +22 -0
- package/src/vehicles/carriage.js +19 -0
- package/src/vehicles/metroModel.js +9 -0
- package/src/vehicles/mirror.js +8 -0
- package/src/vehicles/pedestrianModel.js +17 -0
- package/src/vehicles/tramModel.js +9 -0
- package/src/walk/blocked.js +6 -0
- package/src/walk/createWalk.js +60 -0
- package/src/walk/initWalk.js +18 -0
- package/src/walk/initialize.js +6 -0
- package/src/walk/local.js +10 -0
- package/src/walk/onAdd.js +4 -0
- package/src/walk/onBlur.js +3 -0
- package/src/walk/onKey.js +12 -0
- package/src/walk/onPointer.js +13 -0
- package/src/walk/onRemove.js +4 -0
- package/src/walk/onTerrain.js +5 -0
- package/src/walk/place.js +18 -0
- package/src/walk/start.js +37 -0
- package/src/walk/step.js +53 -0
- package/src/walk/stop.js +27 -0
- package/src/walk/toggle.js +6 -0
- package/dist/scene/gpu.js +0 -3
- package/dist/scene/gpu.js.map +0 -7
- package/dist/scene/lighting.js +0 -9
- package/dist/scene/lighting.js.map +0 -7
- package/dist/scene/model.js +0 -2
- package/dist/scene/model.js.map +0 -7
- package/dist/scene/picking.js +0 -2
- package/dist/scene/picking.js.map +0 -7
- package/dist/scene/pmtiles.js +0 -2
- package/dist/scene/pmtiles.js.map +0 -7
- package/dist/scene/render.js +0 -15
- package/dist/scene/render.js.map +0 -7
- package/dist/scene/sources.js +0 -2
- package/dist/scene/sources.js.map +0 -7
- package/dist/types/3d.js +0 -2
- package/dist/types/3d.js.map +0 -7
- package/dist/types/geojson.js +0 -2
- package/dist/types/geojson.js.map +0 -7
- package/dist/types/pmtiles.js +0 -2
- package/dist/types/pmtiles.js.map +0 -7
- package/dist/types/sunlight.js +0 -2
- package/dist/types/sunlight.js.map +0 -7
- package/dist/types/terrain.js +0 -24
- package/dist/types/terrain.js.map +0 -7
- package/dist/types/traffic.js +0 -41
- package/dist/types/traffic.js.map +0 -7
- package/dist/types/walk.js +0 -2
- package/dist/types/walk.js.map +0 -7
- package/dist/utils/control.js +0 -2
- package/dist/utils/control.js.map +0 -7
- package/dist/utils/geometry.js +0 -2
- package/dist/utils/geometry.js.map +0 -7
- package/dist/utils/lighting.js +0 -2
- package/dist/utils/lighting.js.map +0 -7
- package/dist/utils/model.js +0 -2
- package/dist/utils/model.js.map +0 -7
- package/dist/utils/picking.js +0 -2
- package/dist/utils/picking.js.map +0 -7
- package/dist/utils/pmtiles.js +0 -2
- package/dist/utils/pmtiles.js.map +0 -7
- package/dist/utils/scene.js +0 -2
- package/dist/utils/scene.js.map +0 -7
- package/dist/utils/shaders.js +0 -203
- package/dist/utils/shaders.js.map +0 -7
- package/dist/utils/sun.js +0 -2
- package/dist/utils/sun.js.map +0 -7
- package/dist/utils/terrain.js +0 -2
- package/dist/utils/terrain.js.map +0 -7
- package/dist/utils/traffic.js +0 -2
- package/dist/utils/traffic.js.map +0 -7
- package/dist/utils/vehicles.js +0 -2
- package/dist/utils/vehicles.js.map +0 -7
- package/dist/utils/walk.js +0 -2
- package/dist/utils/walk.js.map +0 -7
- package/src/scene/gpu.js +0 -438
- package/src/scene/lighting.js +0 -193
- package/src/scene/model.js +0 -204
- package/src/scene/picking.js +0 -150
- package/src/scene/pmtiles.js +0 -94
- package/src/scene/render.js +0 -467
- package/src/scene/sources.js +0 -265
- package/src/types/3d.js +0 -337
- package/src/types/geojson.js +0 -42
- package/src/types/pmtiles.js +0 -143
- package/src/types/sunlight.js +0 -142
- package/src/types/terrain.js +0 -331
- package/src/types/traffic.js +0 -356
- package/src/types/walk.js +0 -219
- package/src/utils/control.js +0 -18
- package/src/utils/geometry.js +0 -256
- package/src/utils/lighting.js +0 -51
- package/src/utils/model.js +0 -178
- package/src/utils/picking.js +0 -119
- package/src/utils/pmtiles.js +0 -79
- package/src/utils/scene.js +0 -102
- package/src/utils/sun.js +0 -71
- package/src/utils/terrain.js +0 -78
- package/src/utils/traffic.js +0 -90
- package/src/utils/vehicles.js +0 -69
- package/src/utils/walk.js +0 -72
package/src/types/traffic.js
DELETED
|
@@ -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
|
-
});
|
package/src/utils/control.js
DELETED
|
@@ -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
|
-
}
|