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/pmtiles.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import './3d.js';
|
|
2
|
-
import { read, getHeader, getZxy } from '../scene/pmtiles.js';
|
|
3
|
-
import { decompress } from '../utils/pmtiles.js';
|
|
4
|
-
|
|
5
|
-
/** A raster TileLayer backed by the shared PMTiles reader. */
|
|
6
|
-
L.Layer.types.pmtiles = L.TileLayer.extend({
|
|
7
|
-
_read(offset, length, signal) { return read(this, offset, length, signal); },
|
|
8
|
-
_decompress(data, compression) { return decompress(data, compression); },
|
|
9
|
-
getHeader() { return getHeader(this); },
|
|
10
|
-
getZxy(z, x, y, signal) { return getZxy(this, z, x, y, signal); },
|
|
11
|
-
|
|
12
|
-
initialize(options) {
|
|
13
|
-
L.TileLayer.prototype.initialize.call(this, options.url, options);
|
|
14
|
-
this.url = new URL(options.url, document.baseURI).href;
|
|
15
|
-
this._directories = new Map();
|
|
16
|
-
this.on('tileunload', this._releaseTile, this);
|
|
17
|
-
this.on('load tileunload', () => L.Layer.types['3d']._renderers.get(this._map)?.update());
|
|
18
|
-
this.ready = Promise.resolve(this.options.archive || this).then(async archive => {
|
|
19
|
-
const header = await archive.getHeader();
|
|
20
|
-
this.options.archive = archive;
|
|
21
|
-
this.header = header;
|
|
22
|
-
if (this.options.maxNativeZoom === undefined) this.options.maxNativeZoom = header.maxZoom;
|
|
23
|
-
this.fire('ready');
|
|
24
|
-
return this;
|
|
25
|
-
}).catch(error => {
|
|
26
|
-
this.fire('error', { error });
|
|
27
|
-
throw error;
|
|
28
|
-
});
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
onAdd(map) {
|
|
32
|
-
if (this.header) {
|
|
33
|
-
L.TileLayer.prototype.onAdd.call(this, map);
|
|
34
|
-
this._setTerrain3D(map._terrain3D);
|
|
35
|
-
} else {
|
|
36
|
-
this.ready = this.ready.then(layer => {
|
|
37
|
-
if (this._map === map && map.hasLayer(this) && !this._container) {
|
|
38
|
-
L.TileLayer.prototype.onAdd.call(this, map);
|
|
39
|
-
this._setTerrain3D(map._terrain3D);
|
|
40
|
-
}
|
|
41
|
-
return layer;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
onRemove(map) {
|
|
47
|
-
this._setTerrain3D(null);
|
|
48
|
-
if (this._container) L.TileLayer.prototype.onRemove.call(this, map);
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
setOpacity(opacity) {
|
|
52
|
-
L.TileLayer.prototype.setOpacity.call(this, opacity);
|
|
53
|
-
L.Layer.types['3d']._renderers.get(this._map)?.update();
|
|
54
|
-
return this;
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
setZIndex(zIndex) {
|
|
58
|
-
L.TileLayer.prototype.setZIndex.call(this, zIndex);
|
|
59
|
-
L.Layer.types['3d']._renderers.get(this._map)?.update();
|
|
60
|
-
return this;
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
createTile(coords, done) {
|
|
64
|
-
const tile = document.createElement('img');
|
|
65
|
-
tile.alt = '';
|
|
66
|
-
if (this.options.crossOrigin || this.options.crossOrigin === '') {
|
|
67
|
-
tile.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
|
|
68
|
-
}
|
|
69
|
-
if (typeof this.options.referrerPolicy === 'string') tile.referrerPolicy = this.options.referrerPolicy;
|
|
70
|
-
tile.request = new AbortController();
|
|
71
|
-
this.ready.then(() => {
|
|
72
|
-
if (tile.request.signal.aborted) return;
|
|
73
|
-
return this.options.archive.getZxy(coords.z, coords.x, coords.y, tile.request.signal);
|
|
74
|
-
}).then(async result => {
|
|
75
|
-
if (tile.request.signal.aborted) return;
|
|
76
|
-
if (!result) throw new Error(`Tile ${coords.z}/${coords.x}/${coords.y} is not in the offline archive`);
|
|
77
|
-
await new Promise((resolve, reject) => {
|
|
78
|
-
const finish = error => {
|
|
79
|
-
tile.request.signal.removeEventListener('abort', abort);
|
|
80
|
-
tile.onload = tile.onerror = null;
|
|
81
|
-
this._releaseURL(tile);
|
|
82
|
-
if (error) reject(error);
|
|
83
|
-
else resolve();
|
|
84
|
-
};
|
|
85
|
-
const abort = () => finish();
|
|
86
|
-
tile.request.signal.addEventListener('abort', abort, { once: true });
|
|
87
|
-
tile.objectURL = URL.createObjectURL(new Blob([result.data]));
|
|
88
|
-
tile.onload = () => finish();
|
|
89
|
-
tile.onerror = () => finish(new Error(`Unable to decode tile ${coords.z}/${coords.x}/${coords.y}`));
|
|
90
|
-
tile.src = tile.objectURL;
|
|
91
|
-
});
|
|
92
|
-
if (tile.request.signal.aborted) return;
|
|
93
|
-
tile.done = true;
|
|
94
|
-
this._registerTerrainTile(coords, tile);
|
|
95
|
-
done(null, tile);
|
|
96
|
-
}).catch(error => {
|
|
97
|
-
if (tile.request.signal.aborted) return;
|
|
98
|
-
tile.error = error.message;
|
|
99
|
-
this._tileOnError(done, tile, error);
|
|
100
|
-
});
|
|
101
|
-
return tile;
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
_abortLoading() {
|
|
105
|
-
// Requests can still be pending while an image with no src reports complete.
|
|
106
|
-
for (const { coords, el } of Object.values(this._tiles)) {
|
|
107
|
-
if (coords.z !== this._tileZoom) this._releaseTile({ tile: el });
|
|
108
|
-
}
|
|
109
|
-
L.TileLayer.prototype._abortLoading.call(this);
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
_setTerrain3D(terrain) {
|
|
113
|
-
if (this._terrain3D === terrain) return;
|
|
114
|
-
for (const { el } of Object.values(this._tiles || {})) this._terrain3D?.removeRasterTile(el);
|
|
115
|
-
this._terrain3D = terrain || null;
|
|
116
|
-
if (this._terrain3D) {
|
|
117
|
-
for (const { coords, el } of Object.values(this._tiles || {})) {
|
|
118
|
-
if (el.done) this._registerTerrainTile(coords, el);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
_registerTerrainTile(coords, tile) {
|
|
124
|
-
if (!this._terrain3D) return;
|
|
125
|
-
const terrain = this._terrain3D;
|
|
126
|
-
terrain.addRasterTile(this, coords, tile).catch(error => {
|
|
127
|
-
if (this._terrain3D === terrain && tile.isConnected) this.fire('tileerror', { tile, coords, error });
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
_releaseURL(tile) {
|
|
132
|
-
if (tile.objectURL) {
|
|
133
|
-
URL.revokeObjectURL(tile.objectURL);
|
|
134
|
-
tile.objectURL = null;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
_releaseTile({ tile }) {
|
|
139
|
-
this._terrain3D?.removeRasterTile(tile);
|
|
140
|
-
tile.request.abort();
|
|
141
|
-
this._releaseURL(tile);
|
|
142
|
-
},
|
|
143
|
-
});
|
package/src/types/sunlight.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { atmosphere, moonPosition, solarPosition, projectCelestialBody } from '../utils/sun.js';
|
|
2
|
-
import { underEntry } from '../utils/control.js';
|
|
3
|
-
|
|
4
|
-
function installSunlight(map) {
|
|
5
|
-
const L = globalThis.L;
|
|
6
|
-
const control = new L.Control({ position: 'bottomright' });
|
|
7
|
-
control.live = true;
|
|
8
|
-
let date, slider, output, status, timer;
|
|
9
|
-
const originalSky = map.getContainer().style.getPropertyValue('--leaflet-sky-background');
|
|
10
|
-
const disc = 'position:absolute;width:18px;height:18px;border-radius:50%;transform:translate(-50%,-50%);pointer-events:none;';
|
|
11
|
-
const sunDisc = L.DomUtil.create('div', 'sunlight-sun');
|
|
12
|
-
const moonDisc = L.DomUtil.create('div', 'sunlight-moon');
|
|
13
|
-
sunDisc.style.cssText = disc + 'background:#fff3bd;box-shadow:0 0 18px 7px #ffd27699;';
|
|
14
|
-
moonDisc.style.cssText = disc + 'background:#dce5f2;box-shadow:0 0 10px 2px #cbdcff55;';
|
|
15
|
-
sunDisc.setAttribute('role', 'img'); sunDisc.setAttribute('aria-label', 'Sun');
|
|
16
|
-
moonDisc.setAttribute('role', 'img'); moonDisc.setAttribute('aria-label', 'Moon');
|
|
17
|
-
const updateSky = () => {
|
|
18
|
-
const sun = map._sunlight, sky = map._pitchSky;
|
|
19
|
-
if (sun) map.getContainer().style.setProperty('--leaflet-sky-background', sun.background);
|
|
20
|
-
else if (originalSky) map.getContainer().style.setProperty('--leaflet-sky-background', originalSky);
|
|
21
|
-
else map.getContainer().style.removeProperty('--leaflet-sky-background');
|
|
22
|
-
const size = map.getSize(), pitch = map.getPitch() * Math.PI / 180, bearing = map.getBearing() * Math.PI / 180;
|
|
23
|
-
for (const [disc, body] of [[sunDisc, sun], [moonDisc, sun?.moon]]) {
|
|
24
|
-
disc.hidden = true;
|
|
25
|
-
if (!sky || !body || body.altitude <= 0 || !sun) continue;
|
|
26
|
-
if (disc.parentNode !== sky) sky.append(disc);
|
|
27
|
-
const point = projectCelestialBody(body.direction, size, pitch, bearing);
|
|
28
|
-
if (!point) continue;
|
|
29
|
-
const { left, top } = point;
|
|
30
|
-
disc.hidden = left < 0 || left > size.x || top < 0 || top > sky.clientHeight || sky.style.display === 'none';
|
|
31
|
-
disc.style.left = `${left}px`; disc.style.top = `${top}px`;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const render = () => L.Layer.types['3d']?._renderers.get(map)?.update();
|
|
35
|
-
const update = () => {
|
|
36
|
-
try {
|
|
37
|
-
if (control.live) control.time = new Date();
|
|
38
|
-
const time = control.time.toISOString();
|
|
39
|
-
date.value = time.slice(0, 10);
|
|
40
|
-
slider.value = String(control.time.getUTCHours() * 60 + control.time.getUTCMinutes());
|
|
41
|
-
output.textContent = `${time.slice(11, 16)} UTC${control.live ? ' · now' : ''}`;
|
|
42
|
-
const center = map.getCenter();
|
|
43
|
-
const sun = map._sunlight = solarPosition(control.time, center.lat, center.lng);
|
|
44
|
-
Object.assign(sun, atmosphere(sun.altitude));
|
|
45
|
-
sun.moon = moonPosition(control.time, center.lat, center.lng);
|
|
46
|
-
status.textContent = sun.altitude <= 0 ? 'Night · no direct sunlight' :
|
|
47
|
-
sun.altitude < 3 ? 'Low sun · shadows paused' : `Sun altitude ${sun.altitude.toFixed(1)}°`;
|
|
48
|
-
map.fire('simulationtimechange', { time: new Date(control.time), live: control.live });
|
|
49
|
-
updateSky(); render();
|
|
50
|
-
} catch (error) {
|
|
51
|
-
delete map._sunlight;
|
|
52
|
-
updateSky();
|
|
53
|
-
render();
|
|
54
|
-
status.textContent = `Error: ${error.message}`;
|
|
55
|
-
console.error('Solar simulation', error);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const selectTime = () => {
|
|
59
|
-
control.live = false;
|
|
60
|
-
if (!date.value || !date.validity.valid) {
|
|
61
|
-
control.time = new Date(NaN);
|
|
62
|
-
map.fire('simulationtimechange', { time: null, live: false });
|
|
63
|
-
delete map._sunlight;
|
|
64
|
-
updateSky();
|
|
65
|
-
render();
|
|
66
|
-
status.textContent = 'Error: choose a valid solar date';
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
control.time = new Date(`${date.value}T00:00:00Z`);
|
|
70
|
-
control.time.setUTCMinutes(Number(slider.value));
|
|
71
|
-
update();
|
|
72
|
-
};
|
|
73
|
-
control.onAdd = () => {
|
|
74
|
-
const container = L.DomUtil.create('div', 'sunlight-control');
|
|
75
|
-
container.style.cssText = 'color:#222;width:min(200px,calc(100vw - 60px));font:12px/1.4 sans-serif;';
|
|
76
|
-
date = document.createElement('input');
|
|
77
|
-
date.type = 'date';
|
|
78
|
-
date.style.cssText = 'width:100%;box-sizing:border-box;';
|
|
79
|
-
date.setAttribute('aria-label', 'Solar date (UTC)');
|
|
80
|
-
slider = document.createElement('input');
|
|
81
|
-
slider.type = 'range';
|
|
82
|
-
slider.style.cssText = 'width:100%;box-sizing:border-box;margin:10px 0 4px;cursor:pointer;';
|
|
83
|
-
slider.min = '0'; slider.max = '1439'; slider.step = '1';
|
|
84
|
-
slider.setAttribute('aria-label', 'Time of day (UTC)');
|
|
85
|
-
output = document.createElement('output');
|
|
86
|
-
output.style.cssText = 'font-weight:bold;font-variant-numeric:tabular-nums;';
|
|
87
|
-
output.setAttribute('aria-live', 'off');
|
|
88
|
-
const now = document.createElement('button');
|
|
89
|
-
now.type = 'button'; now.textContent = 'Now';
|
|
90
|
-
now.onclick = () => { control.live = true; update(); };
|
|
91
|
-
const timeRow = document.createElement('div');
|
|
92
|
-
timeRow.className = 'sunlight-time';
|
|
93
|
-
timeRow.style.cssText = 'display:flex;justify-content:space-between;align-items:center;';
|
|
94
|
-
timeRow.append(output, now);
|
|
95
|
-
status = document.createElement('div');
|
|
96
|
-
status.className = 'sunlight-status';
|
|
97
|
-
status.style.marginTop = '5px';
|
|
98
|
-
status.setAttribute('role', 'status');
|
|
99
|
-
const note = document.createElement('small');
|
|
100
|
-
note.style.color = '#555';
|
|
101
|
-
note.textContent = 'Indicative · loaded geometry only. Streetlight illumination is estimated, not measured lux.';
|
|
102
|
-
container.append(date, slider, timeRow, status, note);
|
|
103
|
-
slider.oninput = selectTime;
|
|
104
|
-
date.onchange = selectTime;
|
|
105
|
-
L.DomEvent.disableClickPropagation(container);
|
|
106
|
-
L.DomEvent.disableScrollPropagation(container);
|
|
107
|
-
update();
|
|
108
|
-
timer = setInterval(() => { if (control.live) update(); }, 60000);
|
|
109
|
-
map.on('moveend', update);
|
|
110
|
-
map.on('move rotate pitch resize', updateSky);
|
|
111
|
-
return container;
|
|
112
|
-
};
|
|
113
|
-
control.onRemove = () => {
|
|
114
|
-
clearInterval(timer);
|
|
115
|
-
map.fire('simulationtimechange', { time: null, live: false });
|
|
116
|
-
map.off('moveend', update);
|
|
117
|
-
map.off('move rotate pitch resize', updateSky);
|
|
118
|
-
delete map._sunlight;
|
|
119
|
-
updateSky();
|
|
120
|
-
sunDisc.remove(); moonDisc.remove();
|
|
121
|
-
render();
|
|
122
|
-
};
|
|
123
|
-
return control;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Sun/moon clock control and sky colours; the control is created on first add (`layer.control`).
|
|
127
|
-
L.Layer.types.sunlight = L.Layer.extend({
|
|
128
|
-
onAdd(map) {
|
|
129
|
-
this.control = this.control || installSunlight(map);
|
|
130
|
-
if (!this.control._map) this.control.addTo(map);
|
|
131
|
-
// Shown under this layer's entry in the layers control; a standalone control without one.
|
|
132
|
-
const container = this.control.getContainer(), nested = underEntry(this, container);
|
|
133
|
-
container.classList.toggle('leaflet-control', !nested);
|
|
134
|
-
container.classList.toggle('leaflet-bar', !nested);
|
|
135
|
-
Object.assign(container.style, nested
|
|
136
|
-
? { background: '', padding: '2px 0 6px 20px', margin: '0' }
|
|
137
|
-
: { background: '#fff', padding: '8px', margin: '' });
|
|
138
|
-
},
|
|
139
|
-
onRemove() {
|
|
140
|
-
this.control.remove();
|
|
141
|
-
},
|
|
142
|
-
});
|
package/src/types/terrain.js
DELETED
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { bridgeElevation, terrainElevation, terrainGrid, terrainAtlas } from '../utils/terrain.js';
|
|
2
|
-
import { triangulate } from '../utils/geometry.js';
|
|
3
|
-
import './3d.js';
|
|
4
|
-
import './pmtiles.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Renders IGN Float32 DEM tiles and PMTiles raster basemaps in the shared WebGPU scene.
|
|
8
|
-
* Source options: `url` (single-zoom Float32 PMTiles DEM); `bridges` (optional GeoJSON deck polygons with Z, see _addBridges).
|
|
9
|
-
*/
|
|
10
|
-
L.Layer.types.terrain = L.Layer.types['3d'].extend({
|
|
11
|
-
initialize(options = {}) {
|
|
12
|
-
const terrainSource = options.url;
|
|
13
|
-
const layerOptions = { ...options };
|
|
14
|
-
delete layerOptions.url;
|
|
15
|
-
L.Layer.types['3d'].prototype.initialize.call(this, layerOptions);
|
|
16
|
-
this.terrainSource = terrainSource;
|
|
17
|
-
this._terrainTiles = new Map();
|
|
18
|
-
this._rasterTiles = new Map();
|
|
19
|
-
this._terrainReady = false;
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
onAdd(map) {
|
|
23
|
-
if (map._terrain3D && map._terrain3D !== this) throw new Error('Only one terrain layer can be active per map');
|
|
24
|
-
map._terrain3D = this;
|
|
25
|
-
L.Layer.types['3d'].prototype.onAdd.call(this, map);
|
|
26
|
-
this._terrainPromise = this.root
|
|
27
|
-
? this._loadTerrain()
|
|
28
|
-
: new Promise(resolve => this.once('ready', () => this._loadTerrain().then(resolve), this));
|
|
29
|
-
map.eachLayer(layer => layer._setTerrain3D?.(this));
|
|
30
|
-
map.fire('terrainchange');
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
onRemove(map) {
|
|
34
|
-
this._terrainController?.abort();
|
|
35
|
-
this._terrainLoading = false;
|
|
36
|
-
this._terrainReady = false;
|
|
37
|
-
map.eachLayer(layer => layer._setTerrain3D?.(null));
|
|
38
|
-
for (const tile of this._rasterTiles.keys()) this.removeRasterTile(tile);
|
|
39
|
-
if (map._terrain3D === this) delete map._terrain3D;
|
|
40
|
-
for (const layer of Object.values(map._layers)) layer._setTerrainHeight?.();
|
|
41
|
-
map.fire('terrainchange');
|
|
42
|
-
this._terrainTiles.clear();
|
|
43
|
-
this._terrainOriginElevation = 0;
|
|
44
|
-
this._terrainPromise = null;
|
|
45
|
-
if (this._rasterProgram) this._removeProgram(this._rasterProgram);
|
|
46
|
-
this._rasterProgram = null;
|
|
47
|
-
if (this._dem) this._destroyTexture(this._dem.texture);
|
|
48
|
-
this._dem = null;
|
|
49
|
-
for (const grid of this._terrainGrids?.values() || []) {
|
|
50
|
-
for (const attribute of Object.values(grid)) this._destroyTexture(attribute.buffer);
|
|
51
|
-
}
|
|
52
|
-
this._terrainGrids = null;
|
|
53
|
-
this._bridges = null;
|
|
54
|
-
this._disposeMesh(this._bridgeMesh);
|
|
55
|
-
this._bridgeMesh = null;
|
|
56
|
-
L.Layer.types['3d'].prototype.onRemove.call(this, map);
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
async _loadTerrain() {
|
|
60
|
-
if (this._terrainLoading || !this._map) return;
|
|
61
|
-
this._terrainLoading = true;
|
|
62
|
-
this._terrainReady = false;
|
|
63
|
-
const controller = this._terrainController = new AbortController();
|
|
64
|
-
try {
|
|
65
|
-
if (!this.terrainSource) throw new Error('Terrain layer requires a PMTiles elevation archive');
|
|
66
|
-
const archive = this._terrainArchive = new L.Layer({ source: { type: 'pmtiles', url: this.terrainSource } });
|
|
67
|
-
await archive.ready;
|
|
68
|
-
const header = archive.header;
|
|
69
|
-
if (header.tileType !== 0 || header.minZoom !== header.maxZoom) {
|
|
70
|
-
throw new Error('Expected a single-zoom Float32 PMTiles terrain archive');
|
|
71
|
-
}
|
|
72
|
-
this._terrainZoom = header.maxZoom;
|
|
73
|
-
const map = this._map;
|
|
74
|
-
const northwest = map.project([header.maxLat, header.minLon], this._terrainZoom).divideBy(256).floor();
|
|
75
|
-
const southeast = map.project([header.minLat, header.maxLon], this._terrainZoom).divideBy(256).floor();
|
|
76
|
-
this._terrainBounds = new L.Bounds(northwest, southeast);
|
|
77
|
-
const tiles = [];
|
|
78
|
-
for (let x = northwest.x; x <= southeast.x; x++) {
|
|
79
|
-
for (let y = northwest.y; y <= southeast.y; y++) tiles.push({ z: this._terrainZoom, x, y });
|
|
80
|
-
}
|
|
81
|
-
let next = 0;
|
|
82
|
-
await Promise.all(Array.from({ length: Math.min(4, tiles.length) }, async () => {
|
|
83
|
-
while (next < tiles.length) {
|
|
84
|
-
controller.signal.throwIfAborted();
|
|
85
|
-
const coords = tiles[next++];
|
|
86
|
-
const result = await archive.getZxy(coords.z, coords.x, coords.y, controller.signal);
|
|
87
|
-
if (!result || result.data.byteLength !== 256 * 256 * 4) {
|
|
88
|
-
throw new Error(`Missing or invalid Float32 terrain tile ${coords.z}/${coords.x}/${coords.y}`);
|
|
89
|
-
}
|
|
90
|
-
this._terrainTiles.set(`${coords.x}/${coords.y}`, new Float32Array(result.data));
|
|
91
|
-
}
|
|
92
|
-
}));
|
|
93
|
-
const bridges = this.options.bridges && await fetch(this.options.bridges, { signal: controller.signal })
|
|
94
|
-
.then(response => { if (!response.ok) throw new Error(`Bridges: HTTP ${response.status}`); return response.json(); });
|
|
95
|
-
if (controller.signal.aborted || this._map !== map) return;
|
|
96
|
-
this._terrainReady = true;
|
|
97
|
-
this._terrainOriginElevation = this._getElevation(this.location) ?? 0;
|
|
98
|
-
for (const layer of Object.values(map._layers)) layer._setTerrainHeight?.();
|
|
99
|
-
if (bridges) this._addBridges(bridges);
|
|
100
|
-
map.fire('terrainchange');
|
|
101
|
-
this.update();
|
|
102
|
-
this.fire('terrainready');
|
|
103
|
-
return true;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
if (!controller.signal.aborted) this.fire('error', { error });
|
|
106
|
-
return false;
|
|
107
|
-
} finally {
|
|
108
|
-
this._terrainLoading = false;
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
/** @param {L.LatLng|L.Point} location LatLng, or a pixel point at the terrain zoom. */
|
|
113
|
-
_getElevation(location) {
|
|
114
|
-
if (!this._map || !this._terrainReady) return null;
|
|
115
|
-
const point = location instanceof L.Point ? location : this._map.project(location, this._terrainZoom);
|
|
116
|
-
return bridgeElevation(point, this._bridges) ?? terrainElevation(point, this._terrainTiles);
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Bare-earth DEMs drop bridges: `_getElevation` returns the deck height inside these polygons (GeoJSON
|
|
121
|
-
* Polygon/MultiPolygon with Z, e.g. IGN BD TOPO), and one mesh draws the 1.2 m thick decks.
|
|
122
|
-
* ponytail: anything under a deck (quays, boats asking `_getElevation`) also gets the deck height.
|
|
123
|
-
*/
|
|
124
|
-
_addBridges(geojson) {
|
|
125
|
-
const map = this._map, crs = map.options.crs, zoom = this._terrainZoom;
|
|
126
|
-
const origin = crs.project(this.location), metres = Math.cos(this.location.lat * Math.PI / 180);
|
|
127
|
-
const base = this.root.position[1], position = [], normal = [], color = [];
|
|
128
|
-
const local = ([lng, lat, z]) => {
|
|
129
|
-
const p = crs.project(new L.LatLng(lat, lng));
|
|
130
|
-
return [(p.x - origin.x) * metres, z - base, -(p.y - origin.y) * metres];
|
|
131
|
-
};
|
|
132
|
-
const push = (p, n) => { position.push(...p); normal.push(...n); color.push(0.6, 0.58, 0.54); };
|
|
133
|
-
this._bridges = new Map();
|
|
134
|
-
for (const { geometry } of geojson.features) {
|
|
135
|
-
const polygons = geometry.type === 'Polygon' ? [geometry.coordinates] : geometry.type === 'MultiPolygon' ? geometry.coordinates : [];
|
|
136
|
-
for (const polygon of polygons) {
|
|
137
|
-
const rings = polygon.map(ring => ring.slice(0, -1)).filter(ring => ring.length >= 3);
|
|
138
|
-
if (!rings.length) continue;
|
|
139
|
-
const pixels = rings.flat().map(([lng, lat, z]) => { const p = map.project([lat, lng], zoom); return [p.x, p.y, z]; });
|
|
140
|
-
const points = rings.flat().map(local);
|
|
141
|
-
let triangles;
|
|
142
|
-
try {
|
|
143
|
-
const starts = rings.map((ring, r) => rings.slice(0, r).reduce((sum, previous) => sum + previous.length, 0));
|
|
144
|
-
const [contour, ...holes] = rings.map((ring, r) => ring.map((c, i) => ({ x: pixels[starts[r] + i][0], y: pixels[starts[r] + i][1] })));
|
|
145
|
-
triangles = triangulate(contour, holes);
|
|
146
|
-
} catch { continue; }
|
|
147
|
-
const bridge = {
|
|
148
|
-
triangles: triangles.map(t => t.map(i => pixels[i])),
|
|
149
|
-
min: [Math.min(...pixels.map(p => p[0])), Math.min(...pixels.map(p => p[1]))],
|
|
150
|
-
max: [Math.max(...pixels.map(p => p[0])), Math.max(...pixels.map(p => p[1]))],
|
|
151
|
-
};
|
|
152
|
-
for (let x = Math.floor(bridge.min[0] / 64); x <= Math.floor(bridge.max[0] / 64); x++) {
|
|
153
|
-
for (let y = Math.floor(bridge.min[1] / 64); y <= Math.floor(bridge.max[1] / 64); y++) {
|
|
154
|
-
const key = `${x}/${y}`;
|
|
155
|
-
this._bridges.set(key, [...this._bridges.get(key) || [], bridge]);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const below = p => [p[0], p[1] - 1.2, p[2]];
|
|
159
|
-
for (let [a, b, c] of triangles) {
|
|
160
|
-
// Counter-clockwise seen from above, so double-sided shading keeps the top lit.
|
|
161
|
-
const [pa, pb, pc] = [points[a], points[b], points[c]];
|
|
162
|
-
if ((pb[2] - pa[2]) * (pc[0] - pa[0]) - (pb[0] - pa[0]) * (pc[2] - pa[2]) < 0) [b, c] = [c, b];
|
|
163
|
-
for (const i of [a, b, c]) push(points[i], [0, 1, 0]);
|
|
164
|
-
for (const i of [a, c, b]) push(below(points[i]), [0, -1, 0]);
|
|
165
|
-
}
|
|
166
|
-
let start = 0;
|
|
167
|
-
for (const ring of rings) {
|
|
168
|
-
for (let i = 0; i < ring.length; i++) {
|
|
169
|
-
const p = points[start + i], q = points[start + (i + 1) % ring.length];
|
|
170
|
-
const length = Math.hypot(q[0] - p[0], q[2] - p[2]) || 1, n = [(q[2] - p[2]) / length, 0, -(q[0] - p[0]) / length];
|
|
171
|
-
for (const corner of [p, q, below(q), p, below(q), below(p)]) push(corner, n);
|
|
172
|
-
}
|
|
173
|
-
start += ring.length;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (position.length) this._bridgeMesh = this._createMesh({ position, normal, color });
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
async addRasterTile(layer, coords, tile) {
|
|
181
|
-
const [ready, bitmap] = await Promise.all([this._terrainPromise, createImageBitmap(tile)]);
|
|
182
|
-
if (!ready || !this._map || this._map._terrain3D !== this || layer._terrain3D !== this ||
|
|
183
|
-
tile.request.signal.aborted || !tile.isConnected || this._rasterTiles.has(tile)) {
|
|
184
|
-
bitmap.close();
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
// Match DEM pixel spacing, capped at 64 subdivisions per tile.
|
|
188
|
-
const divisions = Math.max(1, Math.min(64, 256 / 2 ** (coords.z - this._terrainZoom)));
|
|
189
|
-
const map = this._map, crs = map.options.crs;
|
|
190
|
-
const origin = crs.project(this.location), metres = Math.cos(this.location.lat * Math.PI / 180);
|
|
191
|
-
// Tile pixels map linearly to projected metres: one scaled unit grid per tile, elevation in the vertex shader.
|
|
192
|
-
const scale = crs.scale(coords.z), terrainScale = 2 ** (this._terrainZoom - coords.z);
|
|
193
|
-
const corner = crs.transformation.untransform(new L.Point(coords.x * 256, coords.y * 256), scale);
|
|
194
|
-
const opposite = crs.transformation.untransform(new L.Point((coords.x + 1) * 256, (coords.y + 1) * 256), scale);
|
|
195
|
-
const device = this.renderer.device;
|
|
196
|
-
const texture = {
|
|
197
|
-
device,
|
|
198
|
-
texture: device.createTexture({
|
|
199
|
-
size: [tile.width, tile.height],
|
|
200
|
-
format: 'rgba8unorm',
|
|
201
|
-
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
|
|
202
|
-
}),
|
|
203
|
-
sampler: device.createSampler({ addressModeU: 'clamp-to-edge', addressModeV: 'clamp-to-edge' }),
|
|
204
|
-
samplerOptions: { addressModeU: 'clamp-to-edge', addressModeV: 'clamp-to-edge' },
|
|
205
|
-
image: tile, format: 'rgba8unorm', srgb: false, flipY: false, uploaded: tile,
|
|
206
|
-
};
|
|
207
|
-
device.queue.copyExternalImageToTexture({ source: bitmap }, { texture: texture.texture }, [tile.width, tile.height]);
|
|
208
|
-
bitmap.close();
|
|
209
|
-
if (!this._rasterProgram || this._rasterProgram.device !== device) {
|
|
210
|
-
// DEM atlas over the archive's tile grid; invalid or missing samples become -1e9 (the shader's no-data).
|
|
211
|
-
// ponytail: one texture, capped by maxTextureDimension2D (32×32 DEM tiles at 8192 px); split it for larger archives.
|
|
212
|
-
const bounds = this._terrainBounds, columns = bounds.max.x - bounds.min.x + 1, rows = bounds.max.y - bounds.min.y + 1;
|
|
213
|
-
const { elevations, low, high } = terrainAtlas(this._terrainTiles, bounds);
|
|
214
|
-
if (this._dem) this._destroyTexture(this._dem.texture);
|
|
215
|
-
this._dem = {
|
|
216
|
-
texture: device.createTexture({
|
|
217
|
-
size: [columns * 256, rows * 256],
|
|
218
|
-
format: 'r32float',
|
|
219
|
-
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST,
|
|
220
|
-
}),
|
|
221
|
-
low: Number.isFinite(low) ? low : this._terrainOriginElevation,
|
|
222
|
-
high: Number.isFinite(high) ? high : this._terrainOriginElevation,
|
|
223
|
-
};
|
|
224
|
-
device.queue.writeTexture({ texture: this._dem.texture }, elevations,
|
|
225
|
-
{ bytesPerRow: columns * 1024 }, [columns * 256, rows * 256]);
|
|
226
|
-
this._terrainGrids = new Map();
|
|
227
|
-
this._rasterProgram = this._createProgram({
|
|
228
|
-
baseTexture: texture,
|
|
229
|
-
unlit: true,
|
|
230
|
-
alphaMode: 'BLEND',
|
|
231
|
-
terrain: this._dem,
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
let attributes = this._terrainGrids.get(divisions);
|
|
235
|
-
if (!attributes) {
|
|
236
|
-
attributes = terrainGrid(divisions);
|
|
237
|
-
for (const [name, attribute] of Object.entries(attributes)) {
|
|
238
|
-
attribute.size ||= 1;
|
|
239
|
-
attribute.count = attribute.data.length / attribute.size;
|
|
240
|
-
attribute.indexFormat = 'uint16';
|
|
241
|
-
attribute.buffer = device.createBuffer({
|
|
242
|
-
size: Math.max(4, attribute.data.byteLength),
|
|
243
|
-
usage: name === 'index'
|
|
244
|
-
? GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST
|
|
245
|
-
: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
246
|
-
});
|
|
247
|
-
device.queue.writeBuffer(attribute.buffer, 0, attribute.data);
|
|
248
|
-
}
|
|
249
|
-
this._terrainGrids.set(divisions, attributes);
|
|
250
|
-
}
|
|
251
|
-
const base = this._terrainOriginElevation;
|
|
252
|
-
const bottom = Math.min(this._dem.low, base) - base, top = Math.max(this._dem.high, base) - base;
|
|
253
|
-
const sizeX = (opposite.x - corner.x) * metres, sizeZ = -(opposite.y - corner.y) * metres;
|
|
254
|
-
// ponytail: ray picking sees the flat unit grid; read the DEM back if terrain must be pickable.
|
|
255
|
-
const geometry = {
|
|
256
|
-
device,
|
|
257
|
-
attributes,
|
|
258
|
-
drawRange: { start: 0, count: attributes.index.count },
|
|
259
|
-
// Local bounds whose radius, scaled by the largest axis, still covers the displaced tile.
|
|
260
|
-
bounds: {
|
|
261
|
-
min: [0, bottom, 0], max: [1, top, 1], center: [0.5, (bottom + top) / 2, 0.5],
|
|
262
|
-
radius: Math.hypot(sizeX, top - bottom, sizeZ) / 2 / Math.max(sizeX, 1, sizeZ),
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
const mesh = {
|
|
266
|
-
position: [(corner.x - origin.x) * metres, 0, -(corner.y - origin.y) * metres],
|
|
267
|
-
rotation: [0, 0, 0],
|
|
268
|
-
scale: [sizeX, 1, sizeZ],
|
|
269
|
-
worldMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
|
|
270
|
-
children: [],
|
|
271
|
-
visible: true,
|
|
272
|
-
device,
|
|
273
|
-
geometry,
|
|
274
|
-
program: this._rasterProgram,
|
|
275
|
-
texture,
|
|
276
|
-
// DEM pixel of the tile's corner, DEM pixels per tile, and the elevation at the layer origin.
|
|
277
|
-
terrain: [
|
|
278
|
-
coords.x * 256 * terrainScale - this._terrainBounds.min.x * 256,
|
|
279
|
-
coords.y * 256 * terrainScale - this._terrainBounds.min.y * 256,
|
|
280
|
-
256 * terrainScale,
|
|
281
|
-
base,
|
|
282
|
-
],
|
|
283
|
-
tile,
|
|
284
|
-
opacity: layer.options.opacity ?? 1,
|
|
285
|
-
id: L.Layer.types['3d']._nextId++,
|
|
286
|
-
renderOrder: -1,
|
|
287
|
-
};
|
|
288
|
-
this.add(mesh);
|
|
289
|
-
this._rasterTiles.set(tile, mesh);
|
|
290
|
-
tile._terrainVisibility = tile.style.visibility;
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
removeRasterTile(tile) {
|
|
294
|
-
tile._terrainRequest?.abort();
|
|
295
|
-
const mesh = this._rasterTiles.get(tile);
|
|
296
|
-
if (!mesh) return;
|
|
297
|
-
this.remove(mesh);
|
|
298
|
-
this._destroyTexture(mesh.texture.texture);
|
|
299
|
-
this._rasterTiles.delete(tile);
|
|
300
|
-
tile.style.visibility = tile._terrainVisibility;
|
|
301
|
-
delete tile._terrainVisibility;
|
|
302
|
-
},
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* WGSL twin of _getElevation for the vertex shader: bilinear DEM pixels, or the first valid
|
|
307
|
-
* neighbour near no-data (stored as -1e9), else `base`. Expects `dem: texture_2d<f32>`.
|
|
308
|
-
*/
|
|
309
|
-
L.Layer.types.terrain.elevationWGSL = `
|
|
310
|
-
fn demSample(pixel: vec2<i32>) -> f32 {
|
|
311
|
-
if (any(pixel < vec2<i32>(0)) || any(pixel >= vec2<i32>(textureDimensions(dem)))) { return -1e9; }
|
|
312
|
-
return textureLoad(dem, pixel, 0).r;
|
|
313
|
-
}
|
|
314
|
-
fn elevation(pixel: vec2<f32>, base: f32) -> f32 {
|
|
315
|
-
let p = pixel - vec2<f32>(0.5);
|
|
316
|
-
let f = fract(p);
|
|
317
|
-
let i = vec2<i32>(floor(p));
|
|
318
|
-
let v00 = demSample(i);
|
|
319
|
-
let v10 = demSample(i + vec2<i32>(1, 0));
|
|
320
|
-
let v01 = demSample(i + vec2<i32>(0, 1));
|
|
321
|
-
let v11 = demSample(i + vec2<i32>(1, 1));
|
|
322
|
-
if (v00 > -1000.0 && v10 > -1000.0 && v01 > -1000.0 && v11 > -1000.0) {
|
|
323
|
-
return mix(mix(v00, v10, f.x), mix(v01, v11, f.x), f.y);
|
|
324
|
-
}
|
|
325
|
-
if (v00 > -1000.0) { return v00; }
|
|
326
|
-
if (v10 > -1000.0) { return v10; }
|
|
327
|
-
if (v01 > -1000.0) { return v01; }
|
|
328
|
-
if (v11 > -1000.0) { return v11; }
|
|
329
|
-
return base;
|
|
330
|
-
}
|
|
331
|
-
`;
|