leaflet-city-mapper 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -13
- package/cucumber.mjs +4 -0
- package/dist/leaflet-city-mapper.js +1 -1
- package/dist/leaflet-city-mapper.js.map +4 -4
- package/dist/utils/CELL.js +2 -0
- package/dist/utils/CELL.js.map +7 -0
- package/dist/utils/addBridges.js +2 -0
- package/dist/utils/addBridges.js.map +7 -0
- package/dist/utils/addRasterTile.js +2 -0
- package/dist/utils/addRasterTile.js.map +7 -0
- package/dist/utils/along.js +2 -0
- package/dist/utils/along.js.map +7 -0
- package/dist/utils/atmosphere.js +2 -0
- package/dist/utils/atmosphere.js.map +7 -0
- package/dist/utils/attach.js +2 -0
- package/dist/utils/attach.js.map +7 -0
- package/dist/utils/bindSunlight.js +2 -0
- package/dist/utils/bindSunlight.js.map +7 -0
- package/dist/utils/box.js +2 -0
- package/dist/utils/box.js.map +7 -0
- package/dist/utils/bridgeElevation.js +2 -0
- package/dist/utils/bridgeElevation.js.map +7 -0
- package/dist/utils/build.js +2 -0
- package/dist/utils/build.js.map +7 -0
- package/dist/utils/cameraControls.js +2 -0
- package/dist/utils/cameraControls.js.map +7 -0
- package/dist/utils/channel.js +2 -0
- package/dist/utils/channel.js.map +7 -0
- package/dist/utils/collider.js +2 -0
- package/dist/utils/collider.js.map +7 -0
- package/dist/utils/colliders.js +2 -0
- package/dist/utils/colliders.js.map +7 -0
- package/dist/utils/computeBounds.js +2 -0
- package/dist/utils/computeBounds.js.map +7 -0
- package/dist/utils/conformModelToTerrain.js +2 -0
- package/dist/utils/conformModelToTerrain.js.map +7 -0
- package/dist/utils/createMesh.js +2 -0
- package/dist/utils/createMesh.js.map +7 -0
- package/dist/utils/createProgram.js +3 -0
- package/dist/utils/createProgram.js.map +7 -0
- package/dist/utils/decodeDirectory.js +2 -0
- package/dist/utils/decodeDirectory.js.map +7 -0
- package/dist/utils/decodeHeader.js +2 -0
- package/dist/utils/decodeHeader.js.map +7 -0
- package/dist/utils/decodeModel.js +2 -0
- package/dist/utils/decodeModel.js.map +7 -0
- package/dist/utils/decompress.js +2 -0
- package/dist/utils/decompress.js.map +7 -0
- package/dist/utils/destroyTexture.js +2 -0
- package/dist/utils/destroyTexture.js.map +7 -0
- package/dist/utils/disposeMesh.js +2 -0
- package/dist/utils/disposeMesh.js.map +7 -0
- package/dist/utils/drawGeometry.js +2 -0
- package/dist/utils/drawGeometry.js.map +7 -0
- package/dist/utils/elevationWGSL.js +24 -0
- package/dist/utils/elevationWGSL.js.map +7 -0
- package/dist/utils/emptyNode.js +2 -0
- package/dist/utils/emptyNode.js.map +7 -0
- package/dist/utils/endZoom.js +2 -0
- package/dist/utils/endZoom.js.map +7 -0
- package/dist/utils/findFeature.js +2 -0
- package/dist/utils/findFeature.js.map +7 -0
- package/dist/utils/geometry.js +0 -1
- package/dist/utils/geometry.js.map +4 -4
- package/dist/utils/getElevation.js +2 -0
- package/dist/utils/getElevation.js.map +7 -0
- package/dist/utils/getHeader.js +2 -0
- package/dist/utils/getHeader.js.map +7 -0
- package/dist/utils/getZxy.js +2 -0
- package/dist/utils/getZxy.js.map +7 -0
- package/dist/utils/glass.js +2 -0
- package/dist/utils/glass.js.map +7 -0
- package/dist/utils/headlight.js +2 -0
- package/dist/utils/headlight.js.map +7 -0
- package/dist/utils/hit.js +2 -0
- package/dist/utils/hit.js.map +7 -0
- package/dist/utils/horizontalPosition.js +2 -0
- package/dist/utils/horizontalPosition.js.map +7 -0
- package/dist/utils/horizontalRay.js +2 -0
- package/dist/utils/horizontalRay.js.map +7 -0
- package/dist/utils/hull.js +2 -0
- package/dist/utils/hull.js.map +7 -0
- package/dist/utils/initSunlight.js +2 -0
- package/dist/utils/initSunlight.js.map +7 -0
- package/dist/utils/initTerrain.js +2 -0
- package/dist/utils/initTerrain.js.map +7 -0
- package/dist/utils/initTraffic.js +40 -0
- package/dist/utils/initTraffic.js.map +7 -0
- package/dist/utils/initWalk.js +2 -0
- package/dist/utils/initWalk.js.map +7 -0
- package/dist/utils/intersectMeshes.js +2 -0
- package/dist/utils/intersectMeshes.js.map +7 -0
- package/dist/utils/isClockWise.js +2 -0
- package/dist/utils/isClockWise.js.map +7 -0
- package/dist/utils/lampPostGeometry.js +2 -0
- package/dist/utils/lampPostGeometry.js.map +7 -0
- package/dist/utils/lightGeometry.js +2 -0
- package/dist/utils/lightGeometry.js.map +7 -0
- package/dist/utils/lightGrid.js +2 -0
- package/dist/utils/lightGrid.js.map +7 -0
- package/dist/utils/limbs.js +2 -0
- package/dist/utils/limbs.js.map +7 -0
- package/dist/utils/loadModel.js +2 -0
- package/dist/utils/loadModel.js.map +7 -0
- package/dist/utils/loadSource.js +2 -0
- package/dist/utils/loadSource.js.map +7 -0
- package/dist/utils/loadTerrain.js +2 -0
- package/dist/utils/loadTerrain.js.map +7 -0
- package/dist/utils/mapCamera.js +2 -0
- package/dist/utils/mapCamera.js.map +7 -0
- package/dist/utils/{shaders.js → materialShaders.js} +16 -8
- package/dist/utils/materialShaders.js.map +7 -0
- package/dist/utils/mirror.js +2 -0
- package/dist/utils/mirror.js.map +7 -0
- package/dist/utils/moonPosition.js +2 -0
- package/dist/utils/moonPosition.js.map +7 -0
- package/dist/utils/moves.js +2 -0
- package/dist/utils/moves.js.map +7 -0
- package/dist/utils/nativeEvents.js +2 -0
- package/dist/utils/nativeEvents.js.map +7 -0
- package/dist/utils/nativeGeometry.js +2 -0
- package/dist/utils/nativeGeometry.js.map +7 -0
- package/dist/utils/nativeLayer.js +2 -0
- package/dist/utils/nativeLayer.js.map +7 -0
- package/dist/utils/nodeMatrix.js +2 -0
- package/dist/utils/nodeMatrix.js.map +7 -0
- package/dist/utils/onAdd3DLayer.js +2 -0
- package/dist/utils/onAdd3DLayer.js.map +7 -0
- package/dist/utils/onAddSun.js +2 -0
- package/dist/utils/onAddSun.js.map +7 -0
- package/dist/utils/onClick.js +2 -0
- package/dist/utils/onClick.js.map +7 -0
- package/dist/utils/onMapChange.js +2 -0
- package/dist/utils/onMapChange.js.map +7 -0
- package/dist/utils/onPMTileAdd.js +2 -0
- package/dist/utils/onPMTileAdd.js.map +7 -0
- package/dist/utils/onPMTileRemove.js +2 -0
- package/dist/utils/onPMTileRemove.js.map +7 -0
- package/dist/utils/onPointerLeave.js +2 -0
- package/dist/utils/onPointerLeave.js.map +7 -0
- package/dist/utils/onPointerMove.js +2 -0
- package/dist/utils/onPointerMove.js.map +7 -0
- package/dist/utils/onRemove3DLayer.js +2 -0
- package/dist/utils/onRemove3DLayer.js.map +7 -0
- package/dist/utils/onRemoveSun.js +2 -0
- package/dist/utils/onRemoveSun.js.map +7 -0
- package/dist/utils/onTerrainAdd.js +2 -0
- package/dist/utils/onTerrainAdd.js.map +7 -0
- package/dist/utils/onTerrainChange.js +2 -0
- package/dist/utils/onTerrainChange.js.map +7 -0
- package/dist/utils/onTerrainRemove.js +2 -0
- package/dist/utils/onTerrainRemove.js.map +7 -0
- package/dist/utils/onZoomAnim.js +2 -0
- package/dist/utils/onZoomAnim.js.map +7 -0
- package/dist/utils/paints.js +2 -0
- package/dist/utils/paints.js.map +7 -0
- package/dist/utils/parseColor.js +2 -0
- package/dist/utils/parseColor.js.map +7 -0
- package/dist/utils/parts.js +2 -0
- package/dist/utils/parts.js.map +7 -0
- package/dist/utils/projectCelestialBody.js +2 -0
- package/dist/utils/projectCelestialBody.js.map +7 -0
- package/dist/utils/pump.js +2 -0
- package/dist/utils/pump.js.map +7 -0
- package/dist/utils/rasterTiles.js +2 -0
- package/dist/utils/rasterTiles.js.map +7 -0
- package/dist/utils/raycast.js +2 -0
- package/dist/utils/raycast.js.map +7 -0
- package/dist/utils/read.js +2 -0
- package/dist/utils/read.js.map +7 -0
- package/dist/utils/readAccessor.js +2 -0
- package/dist/utils/readAccessor.js.map +7 -0
- package/dist/utils/releaseArea.js +2 -0
- package/dist/utils/releaseArea.js.map +7 -0
- package/dist/utils/removeRasterTile.js +2 -0
- package/dist/utils/removeRasterTile.js.map +7 -0
- package/dist/utils/render.js +15 -0
- package/dist/utils/render.js.map +7 -0
- package/dist/utils/renderSunlight.js +13 -0
- package/dist/utils/renderSunlight.js.map +7 -0
- package/dist/utils/renderers.js +2 -0
- package/dist/utils/renderers.js.map +7 -0
- package/dist/utils/resizeSunlight.js +2 -0
- package/dist/utils/resizeSunlight.js.map +7 -0
- package/dist/utils/roofCoverage.js +2 -0
- package/dist/utils/roofCoverage.js.map +7 -0
- package/dist/utils/routeGeometry.js +2 -0
- package/dist/utils/routeGeometry.js.map +7 -0
- package/dist/utils/scheduledTrips.js +2 -0
- package/dist/utils/scheduledTrips.js.map +7 -0
- package/dist/utils/setGeoJSONData.js +2 -0
- package/dist/utils/setGeoJSONData.js.map +7 -0
- package/dist/utils/setHighlight.js +2 -0
- package/dist/utils/setHighlight.js.map +7 -0
- package/dist/utils/setPMTileOpacity.js +2 -0
- package/dist/utils/setPMTileOpacity.js.map +7 -0
- package/dist/utils/setPMTileZIndex.js +2 -0
- package/dist/utils/setPMTileZIndex.js.map +7 -0
- package/dist/utils/setParent.js +2 -0
- package/dist/utils/setParent.js.map +7 -0
- package/dist/utils/setTerrainHeight.js +2 -0
- package/dist/utils/setTerrainHeight.js.map +7 -0
- package/dist/utils/setVertexColor.js +2 -0
- package/dist/utils/setVertexColor.js.map +7 -0
- package/dist/utils/showFeature.js +2 -0
- package/dist/utils/showFeature.js.map +7 -0
- package/dist/utils/sizes.js +2 -0
- package/dist/utils/sizes.js.map +7 -0
- package/dist/utils/skin.js +2 -0
- package/dist/utils/skin.js.map +7 -0
- package/dist/utils/solarPosition.js +2 -0
- package/dist/utils/solarPosition.js.map +7 -0
- package/dist/utils/sortMeshes.js +2 -0
- package/dist/utils/sortMeshes.js.map +7 -0
- package/dist/utils/speed.js +2 -0
- package/dist/utils/speed.js.map +7 -0
- package/dist/utils/startZoom.js +2 -0
- package/dist/utils/startZoom.js.map +7 -0
- package/dist/utils/taillight.js +2 -0
- package/dist/utils/taillight.js.map +7 -0
- package/dist/utils/terrainAtlas.js +2 -0
- package/dist/utils/terrainAtlas.js.map +7 -0
- package/dist/utils/terrainElevation.js +2 -0
- package/dist/utils/terrainElevation.js.map +7 -0
- package/dist/utils/terrainGrid.js +2 -0
- package/dist/utils/terrainGrid.js.map +7 -0
- package/dist/utils/textureSampler.js +2 -0
- package/dist/utils/textureSampler.js.map +7 -0
- package/dist/utils/tileId.js +2 -0
- package/dist/utils/tileId.js.map +7 -0
- package/dist/utils/toLanes.js +2 -0
- package/dist/utils/toLanes.js.map +7 -0
- package/dist/utils/toSRGB.js +2 -0
- package/dist/utils/toSRGB.js.map +7 -0
- package/dist/utils/tooltip.js +3 -0
- package/dist/utils/tooltip.js.map +7 -0
- package/dist/utils/traffic.js +1 -1
- package/dist/utils/traffic.js.map +3 -3
- package/dist/utils/traverse.js +2 -0
- package/dist/utils/traverse.js.map +7 -0
- package/dist/utils/treeGeometry.js +2 -0
- package/dist/utils/treeGeometry.js.map +7 -0
- package/dist/utils/triangulate.js +2 -0
- package/dist/utils/triangulate.js.map +7 -0
- package/dist/utils/tripsAt.js +2 -0
- package/dist/utils/tripsAt.js.map +7 -0
- package/dist/utils/types.js +2 -0
- package/dist/utils/types.js.map +7 -0
- package/dist/utils/underEntry.js +2 -0
- package/dist/utils/underEntry.js.map +7 -0
- package/dist/utils/update.js +2 -0
- package/dist/utils/update.js.map +7 -0
- package/dist/utils/updateArea.js +2 -0
- package/dist/utils/updateArea.js.map +7 -0
- package/dist/utils/updateCamera.js +2 -0
- package/dist/utils/updateCamera.js.map +7 -0
- package/dist/utils/updatePointLights.js +2 -0
- package/dist/utils/updatePointLights.js.map +7 -0
- package/dist/utils/updateWorldMatrix.js +2 -0
- package/dist/utils/updateWorldMatrix.js.map +7 -0
- package/dist/utils/vehicleOffsets.js +2 -0
- package/dist/utils/vehicleOffsets.js.map +7 -0
- package/dist/utils/vehicles.js +1 -1
- package/dist/utils/vehicles.js.map +3 -3
- package/dist/utils/vertexNormals.js +2 -0
- package/dist/utils/vertexNormals.js.map +7 -0
- package/dist/utils/walk.js +1 -1
- package/dist/utils/walk.js.map +3 -3
- package/dist/utils/white.js +2 -0
- package/dist/utils/white.js.map +7 -0
- package/dist/utils/worldLights.js +2 -0
- package/dist/utils/worldLights.js.map +7 -0
- package/dist/utils/wrap.js +2 -0
- package/dist/utils/wrap.js.map +7 -0
- package/package.json +2 -4
- package/src/index.js +365 -50
- package/src/utils/CELL.js +4 -0
- package/src/utils/addBridges.js +66 -0
- package/src/utils/addRasterTile.js +112 -0
- package/src/utils/along.js +9 -0
- package/src/utils/atmosphere.js +20 -0
- package/src/utils/attach.js +255 -0
- package/src/utils/bindSunlight.js +12 -0
- package/src/utils/box.js +1 -0
- package/src/utils/bridgeElevation.js +18 -0
- package/src/utils/build.js +20 -0
- package/src/utils/cameraControls.js +287 -0
- package/src/utils/channel.js +4 -0
- package/src/utils/collider.js +62 -0
- package/src/utils/colliders.js +2 -0
- package/src/utils/computeBounds.js +17 -0
- package/src/utils/conformModelToTerrain.js +69 -0
- package/src/utils/createMesh.js +31 -0
- package/src/utils/createProgram.js +92 -0
- package/src/utils/decodeDirectory.js +40 -0
- package/src/utils/decodeHeader.js +15 -0
- package/src/utils/decodeModel.js +43 -0
- package/src/utils/decompress.js +5 -0
- package/src/utils/destroyTexture.js +7 -0
- package/src/utils/disposeMesh.js +13 -0
- package/src/utils/drawGeometry.js +122 -0
- package/src/utils/elevationWGSL.js +27 -0
- package/src/utils/emptyNode.js +9 -0
- package/src/utils/endZoom.js +15 -0
- package/src/utils/findFeature.js +49 -0
- package/src/utils/geometry.js +0 -254
- package/src/utils/getElevation.js +10 -0
- package/src/utils/getHeader.js +9 -0
- package/src/utils/getZxy.js +76 -0
- package/src/utils/glass.js +1 -0
- package/src/utils/headlight.js +1 -0
- package/src/utils/hit.js +41 -0
- package/src/utils/horizontalPosition.js +16 -0
- package/src/utils/horizontalRay.js +12 -0
- package/src/utils/hull.js +1 -0
- package/src/utils/initSunlight.js +9 -0
- package/src/utils/initTerrain.js +19 -0
- package/src/utils/initTraffic.js +93 -0
- package/src/utils/initWalk.js +72 -0
- package/src/utils/{picking.js → intersectMeshes.js} +121 -119
- package/src/utils/isClockWise.js +12 -0
- package/src/utils/lampPostGeometry.js +26 -0
- package/src/utils/lightGeometry.js +22 -0
- package/src/utils/{lighting.js → lightGrid.js} +50 -51
- package/src/utils/limbs.js +9 -0
- package/src/{scene/model.js → utils/loadModel.js} +37 -24
- package/src/utils/loadSource.js +17 -0
- package/src/utils/loadTerrain.js +65 -0
- package/src/utils/mapCamera.js +432 -0
- package/src/utils/{shaders.js → materialShaders.js} +243 -237
- package/src/utils/mirror.js +6 -0
- package/src/utils/moonPosition.js +17 -0
- package/src/utils/moves.js +11 -0
- package/src/utils/nativeEvents.js +77 -0
- package/src/utils/nativeGeometry.js +131 -0
- package/src/utils/nativeLayer.js +317 -0
- package/src/utils/nodeMatrix.js +22 -0
- package/src/utils/onAdd3DLayer.js +31 -0
- package/src/utils/onAddSun.js +147 -0
- package/src/utils/onClick.js +13 -0
- package/src/utils/onMapChange.js +16 -0
- package/src/utils/onPMTileAdd.js +15 -0
- package/src/utils/onPMTileRemove.js +8 -0
- package/src/utils/onPointerLeave.js +11 -0
- package/src/utils/onPointerMove.js +15 -0
- package/src/utils/onRemove3DLayer.js +78 -0
- package/src/utils/onRemoveSun.js +3 -0
- package/src/utils/onTerrainAdd.js +18 -0
- package/src/utils/onTerrainChange.js +13 -0
- package/src/utils/onTerrainRemove.js +40 -0
- package/src/utils/onZoomAnim.js +14 -0
- package/src/utils/paints.js +10 -0
- package/src/utils/parseColor.js +42 -0
- package/src/utils/parts.js +16 -0
- package/src/utils/projectCelestialBody.js +13 -0
- package/src/{scene/sources.js → utils/pump.js} +59 -98
- package/src/utils/rasterTiles.js +285 -0
- package/src/utils/raycast.js +60 -0
- package/src/utils/read.js +29 -0
- package/src/utils/readAccessor.js +68 -0
- package/src/utils/releaseArea.js +34 -0
- package/src/utils/removeRasterTile.js +13 -0
- package/src/{scene → utils}/render.js +112 -173
- package/src/utils/renderSunlight.js +170 -0
- package/src/utils/renderers.js +2 -0
- package/src/utils/resizeSunlight.js +15 -0
- package/src/utils/roofCoverage.js +47 -0
- package/src/utils/routeGeometry.js +22 -0
- package/src/utils/scheduledTrips.js +29 -0
- package/src/utils/setGeoJSONData.js +11 -0
- package/src/utils/setHighlight.js +13 -0
- package/src/utils/setPMTileOpacity.js +7 -0
- package/src/utils/setPMTileZIndex.js +7 -0
- package/src/utils/setParent.js +7 -0
- package/src/utils/setTerrainHeight.js +10 -0
- package/src/utils/setVertexColor.js +14 -0
- package/src/utils/showFeature.js +27 -0
- package/src/utils/sizes.js +1 -0
- package/src/utils/skin.js +2 -0
- package/src/utils/solarPosition.js +17 -0
- package/src/utils/sortMeshes.js +12 -0
- package/src/utils/speed.js +3 -0
- package/src/utils/startZoom.js +5 -0
- package/src/utils/taillight.js +1 -0
- package/src/utils/terrainAtlas.js +21 -0
- package/src/utils/terrainElevation.js +20 -0
- package/src/utils/terrainGrid.js +23 -0
- package/src/utils/textureSampler.js +10 -0
- package/src/utils/tileId.js +18 -0
- package/src/utils/toLanes.js +7 -0
- package/src/utils/toSRGB.js +1 -0
- package/src/utils/tooltip.js +6 -0
- package/src/utils/traffic.js +310 -85
- package/src/utils/traverse.js +6 -0
- package/src/utils/treeGeometry.js +45 -0
- package/src/utils/triangulate.js +100 -0
- package/src/utils/tripsAt.js +16 -0
- package/src/utils/types.js +8 -0
- package/src/utils/{control.js → underEntry.js} +1 -2
- package/src/utils/update.js +18 -0
- package/src/utils/updateArea.js +40 -0
- package/src/utils/updateCamera.js +32 -0
- package/src/utils/updatePointLights.js +38 -0
- package/src/utils/updateWorldMatrix.js +47 -0
- package/src/utils/vehicleOffsets.js +8 -0
- package/src/utils/vehicles.js +65 -69
- package/src/utils/vertexNormals.js +30 -0
- package/src/utils/walk.js +181 -66
- package/src/utils/white.js +1 -0
- package/src/utils/worldLights.js +25 -0
- package/src/utils/wrap.js +1 -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/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.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/src/scene/gpu.js +0 -438
- package/src/scene/lighting.js +0 -193
- package/src/scene/picking.js +0 -150
- package/src/scene/pmtiles.js +0 -94
- 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/model.js +0 -178
- 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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { addBridges } from './addBridges.js';
|
|
2
|
+
import { conformModelToTerrain } from './conformModelToTerrain.js';
|
|
3
|
+
import { getElevation } from './getElevation.js';
|
|
4
|
+
import { setTerrainHeight } from './setTerrainHeight.js';
|
|
5
|
+
import { update } from './update.js';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export async function loadTerrain(backend) {
|
|
9
|
+
if (backend._terrainLoading || !backend._map) return;
|
|
10
|
+
backend._terrainLoading = true;
|
|
11
|
+
backend._terrainReady = false;
|
|
12
|
+
const controller = backend._terrainController = new AbortController();
|
|
13
|
+
try {
|
|
14
|
+
if (!backend.terrainSource) throw new Error('Terrain layer requires a PMTiles elevation archive');
|
|
15
|
+
const archive = backend._terrainArchive = new L.Layer({ source: { type: 'pmtiles', url: backend.terrainSource } });
|
|
16
|
+
await archive.ready;
|
|
17
|
+
const header = archive.header;
|
|
18
|
+
if (header.tileType !== 0 || header.minZoom !== header.maxZoom) {
|
|
19
|
+
throw new Error('Expected a single-zoom Float32 PMTiles terrain archive');
|
|
20
|
+
}
|
|
21
|
+
backend._terrainZoom = header.maxZoom;
|
|
22
|
+
const map = backend._map;
|
|
23
|
+
const northwest = map.project([header.maxLat, header.minLon], backend._terrainZoom).divideBy(256).floor();
|
|
24
|
+
const southeast = map.project([header.minLat, header.maxLon], backend._terrainZoom).divideBy(256).floor();
|
|
25
|
+
backend._terrainBounds = new L.Bounds(northwest, southeast);
|
|
26
|
+
const tiles = [];
|
|
27
|
+
for (let x = northwest.x; x <= southeast.x; x++) {
|
|
28
|
+
for (let y = northwest.y; y <= southeast.y; y++) tiles.push({ z: backend._terrainZoom, x, y });
|
|
29
|
+
}
|
|
30
|
+
const center = map.project(map.getCenter(), backend._terrainZoom).divideBy(256);
|
|
31
|
+
tiles.sort((a, b) => Math.hypot(a.x + 0.5 - center.x, a.y + 0.5 - center.y) -
|
|
32
|
+
Math.hypot(b.x + 0.5 - center.x, b.y + 0.5 - center.y));
|
|
33
|
+
let next = 0;
|
|
34
|
+
await Promise.all(Array.from({ length: Math.min(4, tiles.length) }, async () => {
|
|
35
|
+
while (next < tiles.length) {
|
|
36
|
+
controller.signal.throwIfAborted();
|
|
37
|
+
const coords = tiles[next++];
|
|
38
|
+
const result = await archive.getZxy(coords.z, coords.x, coords.y, controller.signal);
|
|
39
|
+
if (!result || result.data.byteLength !== 256 * 256 * 4) {
|
|
40
|
+
throw new Error(`Missing or invalid Float32 terrain tile ${coords.z}/${coords.x}/${coords.y}`);
|
|
41
|
+
}
|
|
42
|
+
backend._terrainTiles.set(`${coords.x}/${coords.y}`, new Float32Array(result.data));
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
const bridges = backend.options.bridges && await fetch(backend.options.bridges, { signal: controller.signal })
|
|
46
|
+
.then(response => { if (!response.ok) throw new Error(`Bridges: HTTP ${response.status}`); return response.json(); });
|
|
47
|
+
if (controller.signal.aborted || backend._map !== map) return;
|
|
48
|
+
backend._terrainReady = true;
|
|
49
|
+
backend._terrainOriginElevation = getElevation(backend, backend.location) ?? 0;
|
|
50
|
+
for (const layer of Object.values(map._layers)) {
|
|
51
|
+
setTerrainHeight(layer);
|
|
52
|
+
conformModelToTerrain(layer, backend);
|
|
53
|
+
}
|
|
54
|
+
if (bridges) addBridges(backend, bridges);
|
|
55
|
+
map.fire('terrainchange');
|
|
56
|
+
update(backend);
|
|
57
|
+
backend.fire('terrainready');
|
|
58
|
+
return true;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (!controller.signal.aborted) backend.fire('error', { error });
|
|
61
|
+
return false;
|
|
62
|
+
} finally {
|
|
63
|
+
backend._terrainLoading = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
const mapMethods = Object.defineProperties({}, Object.getOwnPropertyDescriptors(L.Map.prototype));
|
|
2
|
+
const radians = Math.PI / 180;
|
|
3
|
+
const pointOf = point => Array.isArray(point) ? new L.Point(point[0], point[1]) : new L.Point(point.x, point.y);
|
|
4
|
+
|
|
5
|
+
L.Map.mergeOptions({
|
|
6
|
+
rotate: true, bearing: 0, pitch: 0, pitchMaxDistance: 3,
|
|
7
|
+
rotateControl: true, shiftKeyRotate: true, pitchDrag: true,
|
|
8
|
+
touchRotate: false, touchPitch: false, compassBearing: false,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
function angles(map) {
|
|
12
|
+
const bearing = map.getBearing() * radians, pitch = map.getPitch() * radians;
|
|
13
|
+
return [Math.cos(bearing), Math.sin(bearing), Math.cos(pitch), Math.sin(pitch)];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Ground coordinates only: the GPU camera handles elevated geometry, never CSS transforms.
|
|
17
|
+
function project(map, point, inverse = false, limit = false) {
|
|
18
|
+
const half = map.getSize().divideBy(2), distance = map.getSize().y * 1.5;
|
|
19
|
+
if (!distance) return pointOf(point);
|
|
20
|
+
const [cos, sin, tilt, rise] = angles(map);
|
|
21
|
+
const p = pointOf(point).subtract(half);
|
|
22
|
+
if (inverse) {
|
|
23
|
+
const far = map.getSize().y * map.options.pitchMaxDistance;
|
|
24
|
+
const denominator = tilt * distance + rise * p.y;
|
|
25
|
+
let v = denominator > 0 ? p.y * distance / denominator : -far;
|
|
26
|
+
if (limit) v = Math.max(-far, Math.min(far, v));
|
|
27
|
+
const u = p.x * (distance - rise * v) / distance;
|
|
28
|
+
return new L.Point(cos * u + sin * v, -sin * u + cos * v).add(half);
|
|
29
|
+
}
|
|
30
|
+
const u = cos * p.x - sin * p.y, v = sin * p.x + cos * p.y;
|
|
31
|
+
const scale = distance / (distance - rise * v);
|
|
32
|
+
return new L.Point(u * scale, tilt * v * scale).add(half);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function displayPoint(map, point) {
|
|
36
|
+
return map.layerPointToContainerPoint(point).subtract(map._getMapPanePos());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function animationPoint(map, point, inverse = false) {
|
|
40
|
+
const view = map._cameraView;
|
|
41
|
+
if (!view) return point;
|
|
42
|
+
const half = map.getSize().divideBy(2), scale = map.getZoomScale(view.zoom);
|
|
43
|
+
const shift = map.project(map.getCenter(), view.zoom).subtract(map.project(view.center, view.zoom));
|
|
44
|
+
return inverse ? point.subtract(half).subtract(shift).divideBy(scale).add(half) :
|
|
45
|
+
point.subtract(half).multiplyBy(scale).add(shift).add(half);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function groundBounds(map, padding = [0, 0]) {
|
|
49
|
+
const min = pointOf(padding).divideBy(2), max = map.getSize().subtract(min);
|
|
50
|
+
return new L.Bounds([[min.x, min.y], [max.x, min.y], [min.x, max.y], [max.x, max.y]]
|
|
51
|
+
.map(point => project(map, point, true, true)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function fitCameraBounds(map, bounds, options = {}) {
|
|
55
|
+
bounds = bounds.getBounds ? bounds.getBounds() : bounds instanceof L.LatLngBounds ? bounds : new L.LatLngBounds(bounds);
|
|
56
|
+
const zoom = map.getZoom() ?? 0, half = map.getSize().divideBy(2), distance = map.getSize().y * 1.5;
|
|
57
|
+
const min = pointOf(options.paddingTopLeft || options.padding || [0, 0]).subtract(half);
|
|
58
|
+
const max = half.subtract(pointOf(options.paddingBottomRight || options.padding || [0, 0]));
|
|
59
|
+
const [cos, sin, tilt, rise] = angles(map);
|
|
60
|
+
const far = map.getSize().y * map.options.pitchMaxDistance;
|
|
61
|
+
const vertical = y => tilt * distance + rise * y > 0
|
|
62
|
+
? Math.max(-far, Math.min(far, y * distance / (tilt * distance + rise * y))) : -far;
|
|
63
|
+
const top = vertical(min.y), bottom = vertical(max.y);
|
|
64
|
+
const origin = map.project(bounds.getNorthWest(), zoom).add(map.project(bounds.getSouthEast(), zoom)).divideBy(2);
|
|
65
|
+
const points = [bounds.getNorthWest(), bounds.getNorthEast(), bounds.getSouthWest(), bounds.getSouthEast()]
|
|
66
|
+
.map(latlng => {
|
|
67
|
+
const p = map.project(latlng, zoom).subtract(origin);
|
|
68
|
+
return new L.Point(cos * p.x - sin * p.y, sin * p.x + cos * p.y);
|
|
69
|
+
});
|
|
70
|
+
const low = Math.min(...points.map(p => p.y)), high = Math.max(...points.map(p => p.y));
|
|
71
|
+
const leftSlope = min.x * rise / distance, rightSlope = max.x * rise / distance;
|
|
72
|
+
const slope = rightSlope - leftSlope;
|
|
73
|
+
const left = Math.min(...points.map(p => p.x + leftSlope * p.y));
|
|
74
|
+
const right = Math.max(...points.map(p => p.x + rightSlope * p.y));
|
|
75
|
+
// Perspective viewport edges are straight lines on the ground: fit all four corners, not their screen midpoint.
|
|
76
|
+
const scale = Math.min((bottom - top) / (high - low),
|
|
77
|
+
(max.x - min.x - slope * top) / (right - left - slope * low));
|
|
78
|
+
let target = map.getScaleZoom(scale, zoom);
|
|
79
|
+
const snap = map.options.zoomSnap;
|
|
80
|
+
if (snap) target = Math.floor(Math.round(target / (snap / 100)) / 100) * snap;
|
|
81
|
+
target = Math.max(map.getMinZoom(), Math.min(map.getMaxZoom(), options.maxZoom ?? Infinity, target));
|
|
82
|
+
if (!Number.isFinite(target)) return { center: bounds.getCenter(), zoom: target };
|
|
83
|
+
const actual = map.getZoomScale(target, zoom);
|
|
84
|
+
const vMin = high * actual - bottom, vMax = low * actual - top;
|
|
85
|
+
const v = Math.max(vMin, slope ? (actual * (right - left) - max.x + min.x) / slope : vMin);
|
|
86
|
+
const centerY = (Math.min(vMax, v) + vMax) / 2;
|
|
87
|
+
const centerX = (actual * (left + right) - min.x - max.x - (leftSlope + rightSlope) * centerY) / 2;
|
|
88
|
+
const center = origin.add(new L.Point(cos * centerX + sin * centerY, -sin * centerX + cos * centerY).divideBy(actual));
|
|
89
|
+
return { center: map.unproject(center, zoom), zoom: target };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function updateSky() {
|
|
93
|
+
const height = this.getSize().y, pitch = this.getPitch() * radians;
|
|
94
|
+
const far = height * this.options.pitchMaxDistance, distance = height * 1.5;
|
|
95
|
+
const top = height / 2 - far * Math.cos(pitch) * distance / (distance + Math.sin(pitch) * far);
|
|
96
|
+
if (top > 0 && !this._pitchSky) {
|
|
97
|
+
this._pitchSky = L.DomUtil.create('div', 'leaflet-pitch-sky', this.getContainer());
|
|
98
|
+
this._pitchSky.setAttribute('aria-hidden', 'true');
|
|
99
|
+
this._pitchSky.style.cssText = 'position:absolute;inset:0 0 auto;height:0;z-index:0;pointer-events:none;background:var(--leaflet-sky-background,linear-gradient(#9ec5e8,#dfe9f0))';
|
|
100
|
+
}
|
|
101
|
+
if (this._pitchSky) {
|
|
102
|
+
this._pitchSky.style.height = `${Math.max(0, Math.ceil(top))}px`;
|
|
103
|
+
this._pitchSky.style.display = top > 0 ? '' : 'none';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
L.Map.include({
|
|
108
|
+
getBearing() { return this._cameraBearing ?? 0; },
|
|
109
|
+
getPitch() { return this._cameraPitch ?? 0; },
|
|
110
|
+
_stopPitchBearingAnimation() {
|
|
111
|
+
cancelAnimationFrame(this._cameraFrame);
|
|
112
|
+
this._cameraFrame = null;
|
|
113
|
+
return this;
|
|
114
|
+
},
|
|
115
|
+
_setPitchAndBearing(pitch, bearing) {
|
|
116
|
+
if (!Number.isFinite(pitch) || !Number.isFinite(bearing)) throw new TypeError('Camera angles must be finite numbers');
|
|
117
|
+
const previousPitch = this.getPitch(), previousBearing = this.getBearing();
|
|
118
|
+
this._cameraPitch = Math.max(0, Math.min(85, pitch));
|
|
119
|
+
this._cameraBearing = ((bearing % 360) + 360) % 360;
|
|
120
|
+
if (this._loaded) {
|
|
121
|
+
updateSky.call(this);
|
|
122
|
+
if (previousBearing !== this.getBearing()) this.fire('rotate', { bearing: this.getBearing() });
|
|
123
|
+
if (previousPitch !== this.getPitch()) this.fire('pitch', { pitch: this.getPitch() });
|
|
124
|
+
}
|
|
125
|
+
return this;
|
|
126
|
+
},
|
|
127
|
+
_animateCamera(pitch, bearing, options = {}) {
|
|
128
|
+
cancelAnimationFrame(this._cameraFrame);
|
|
129
|
+
if (!Number.isFinite(pitch) || !Number.isFinite(bearing)) throw new TypeError('Camera angles must be finite numbers');
|
|
130
|
+
if (!options.animate || matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
131
|
+
return this._setPitchAndBearing(pitch, bearing);
|
|
132
|
+
}
|
|
133
|
+
const duration = options.duration ?? 0.3;
|
|
134
|
+
if (!Number.isFinite(duration) || duration < 0) throw new TypeError('Camera duration must be nonnegative');
|
|
135
|
+
const start = performance.now(), fromPitch = this.getPitch(), fromBearing = this.getBearing();
|
|
136
|
+
const delta = ((bearing - fromBearing) % 360 + 540) % 360 - 180;
|
|
137
|
+
const frame = now => {
|
|
138
|
+
const progress = duration ? Math.min(1, (now - start) / (duration * 1000)) : 1;
|
|
139
|
+
const eased = 1 - (1 - progress) ** 3;
|
|
140
|
+
this._setPitchAndBearing(fromPitch + (Math.max(0, Math.min(85, pitch)) - fromPitch) * eased,
|
|
141
|
+
fromBearing + delta * eased);
|
|
142
|
+
if (progress < 1) this._cameraFrame = requestAnimationFrame(frame);
|
|
143
|
+
};
|
|
144
|
+
this._cameraFrame = requestAnimationFrame(frame);
|
|
145
|
+
return this;
|
|
146
|
+
},
|
|
147
|
+
setBearing(bearing, options) { return this._animateCamera(this.getPitch(), bearing, options); },
|
|
148
|
+
setPitch(pitch, options) { return this._animateCamera(pitch, this.getBearing(), options); },
|
|
149
|
+
resetNorth(options = { animate: true }) { return this.setBearing(0, options); },
|
|
150
|
+
resetNorthPitch(options = { animate: true }) { return this._animateCamera(0, 0, options); },
|
|
151
|
+
layerPointToContainerPoint(point) {
|
|
152
|
+
return project(this, animationPoint(this, mapMethods.layerPointToContainerPoint.call(this, point)));
|
|
153
|
+
},
|
|
154
|
+
containerPointToLayerPoint(point) {
|
|
155
|
+
return mapMethods.containerPointToLayerPoint.call(this, animationPoint(this, project(this, point, true), true));
|
|
156
|
+
},
|
|
157
|
+
_getCenterLayerPoint() {
|
|
158
|
+
return mapMethods.containerPointToLayerPoint.call(this, this.getSize().divideBy(2));
|
|
159
|
+
},
|
|
160
|
+
_updateCameraOverlays() {
|
|
161
|
+
for (const layer of Object.values(this._layers)) {
|
|
162
|
+
if (layer instanceof L.Marker) layer.update();
|
|
163
|
+
else if (layer instanceof L.Popup || layer instanceof L.Tooltip) layer._updatePosition();
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
panBy(offset, options) {
|
|
167
|
+
const half = this.getSize().divideBy(2);
|
|
168
|
+
const ground = half.subtract(project(this, half.subtract(pointOf(offset)), true));
|
|
169
|
+
return mapMethods.panBy.call(this, ground, options);
|
|
170
|
+
},
|
|
171
|
+
setZoomAround(latlng, zoom, options) {
|
|
172
|
+
if (!this.getPitch() && !this.getBearing()) return mapMethods.setZoomAround.call(this, latlng, zoom, options);
|
|
173
|
+
zoom = this._limitZoom(zoom);
|
|
174
|
+
const scale = this.getZoomScale(zoom), half = this.getSize().divideBy(2);
|
|
175
|
+
const screen = latlng instanceof L.Point ? latlng : this.latLngToContainerPoint(latlng);
|
|
176
|
+
const center = this.containerPointToLayerPoint(half), anchor = this.containerPointToLayerPoint(screen);
|
|
177
|
+
const next = center.add(anchor.subtract(center).multiplyBy(1 - 1 / scale));
|
|
178
|
+
return this.setView(this.layerPointToLatLng(next), zoom, { zoom: options });
|
|
179
|
+
},
|
|
180
|
+
panInside(latlng, options = {}) {
|
|
181
|
+
if (!this.getPitch() && !this.getBearing()) return mapMethods.panInside.call(this, latlng, options);
|
|
182
|
+
const min = pointOf(options.paddingTopLeft || options.padding || [0, 0]);
|
|
183
|
+
const max = this.getSize().subtract(pointOf(options.paddingBottomRight || options.padding || [0, 0]));
|
|
184
|
+
const screen = this.latLngToContainerPoint(latlng);
|
|
185
|
+
const safe = new L.Point(Math.max(min.x, Math.min(max.x, screen.x)),
|
|
186
|
+
Math.max(min.y, Math.min(max.y, screen.y)));
|
|
187
|
+
if (safe.equals(screen)) return this;
|
|
188
|
+
const delta = this.latLngToLayerPoint(latlng).subtract(this.containerPointToLayerPoint(safe));
|
|
189
|
+
return this.panTo(this.unproject(this.project(this.getCenter()).add(delta)), options);
|
|
190
|
+
},
|
|
191
|
+
_limitCenter(center, zoom, bounds) {
|
|
192
|
+
if (!bounds || !this._loaded || !this.getPitch() && !this.getBearing()) {
|
|
193
|
+
return mapMethods._limitCenter.call(this, center, zoom, bounds);
|
|
194
|
+
}
|
|
195
|
+
const half = this.getSize().divideBy(2), footprint = groundBounds(this), point = this.project(center, zoom);
|
|
196
|
+
const view = new L.Bounds(point.add(footprint.min.subtract(half)), point.add(footprint.max.subtract(half)));
|
|
197
|
+
const offset = this._getBoundsOffset(view, bounds, zoom);
|
|
198
|
+
return Math.abs(offset.x) <= 1 && Math.abs(offset.y) <= 1 ? center : this.unproject(point.add(offset), zoom);
|
|
199
|
+
},
|
|
200
|
+
_limitOffset(offset, bounds) {
|
|
201
|
+
if (!bounds || !this.getPitch() && !this.getBearing()) return mapMethods._limitOffset.call(this, offset, bounds);
|
|
202
|
+
const half = this.getSize().divideBy(2), ground = half.subtract(project(this, half.subtract(offset), true));
|
|
203
|
+
const center = this.project(this.getCenter());
|
|
204
|
+
const limited = this.project(this._limitCenter(this.unproject(center.add(ground)), this.getZoom(), bounds));
|
|
205
|
+
return half.subtract(project(this, half.subtract(limited.subtract(center))));
|
|
206
|
+
},
|
|
207
|
+
_getBoundsCenterZoom(bounds, options) {
|
|
208
|
+
return this.getPitch() || this.getBearing() ? fitCameraBounds(this, bounds, options) :
|
|
209
|
+
mapMethods._getBoundsCenterZoom.call(this, bounds, options);
|
|
210
|
+
},
|
|
211
|
+
getBoundsZoom(bounds, inside, padding) {
|
|
212
|
+
if (!this.getPitch() && !this.getBearing()) return mapMethods.getBoundsZoom.call(this, bounds, inside, padding);
|
|
213
|
+
if (!inside) return fitCameraBounds(this, bounds, { padding: pointOf(padding || [0, 0]).divideBy(2) }).zoom;
|
|
214
|
+
bounds = bounds instanceof L.LatLngBounds ? bounds : new L.LatLngBounds(bounds);
|
|
215
|
+
const footprint = groundBounds(this, padding).getSize(), size = this.project(bounds.getSouthEast()).subtract(this.project(bounds.getNorthWest()));
|
|
216
|
+
const zoom = this.getScaleZoom(Math.max(footprint.x / size.x, footprint.y / size.y));
|
|
217
|
+
const snap = this.options.zoomSnap;
|
|
218
|
+
return Math.max(this.getMinZoom(), Math.min(this.getMaxZoom(), snap ? Math.ceil(zoom / snap) * snap : zoom));
|
|
219
|
+
},
|
|
220
|
+
_tryAnimatedPan(center, options) {
|
|
221
|
+
// Leaflet's geographic recentering already supplies ground pixels, not screen pixels.
|
|
222
|
+
const offset = this._getCenterOffset(center)._trunc();
|
|
223
|
+
if (options?.animate !== true && !this.getSize().contains(offset)) return false;
|
|
224
|
+
mapMethods.panBy.call(this, offset, options);
|
|
225
|
+
return true;
|
|
226
|
+
},
|
|
227
|
+
getBounds() {
|
|
228
|
+
if (!this.getPitch() && !this.getBearing()) return mapMethods.getBounds.call(this);
|
|
229
|
+
const footprint = groundBounds(this), bounds = new L.LatLngBounds();
|
|
230
|
+
for (const point of [footprint.min, footprint.max]) {
|
|
231
|
+
const raw = mapMethods.containerPointToLayerPoint.call(this, animationPoint(this, point, true));
|
|
232
|
+
bounds.extend(this.layerPointToLatLng(raw));
|
|
233
|
+
}
|
|
234
|
+
return bounds;
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
L.Map.addInitHook(function () {
|
|
239
|
+
if (!document.getElementById('leaflet-camera-zoom-style')) {
|
|
240
|
+
const style = document.createElement('style');
|
|
241
|
+
style.id = 'leaflet-camera-zoom-style';
|
|
242
|
+
style.textContent = ['.leaflet-marker-icon', '.leaflet-marker-shadow', '.leaflet-popup', '.leaflet-tooltip']
|
|
243
|
+
.map(selector => `.leaflet-camera-zoom ${selector}`).join(',') + '{transition:none!important}';
|
|
244
|
+
document.head.append(style);
|
|
245
|
+
}
|
|
246
|
+
this._setPitchAndBearing(this.options.pitch, this.options.bearing);
|
|
247
|
+
this.on('load resize pitch', updateSky);
|
|
248
|
+
this.on('rotate pitch', () => {
|
|
249
|
+
if (this.options.maxBounds) this._panInsideMaxBounds();
|
|
250
|
+
});
|
|
251
|
+
this.once('unload', () => {
|
|
252
|
+
cancelAnimationFrame(this._cameraFrame);
|
|
253
|
+
this._pitchSky?.remove();
|
|
254
|
+
});
|
|
255
|
+
this.whenReady(() => {
|
|
256
|
+
const draggable = this.dragging?._draggable;
|
|
257
|
+
if (!draggable) return;
|
|
258
|
+
const pan = () => {
|
|
259
|
+
if (!this.getPitch() && !this.getBearing()) return;
|
|
260
|
+
const half = this.getSize().divideBy(2), delta = draggable._newPos.subtract(draggable._startPos);
|
|
261
|
+
const ground = half.subtract(project(this, half.subtract(delta), true));
|
|
262
|
+
draggable._newPos = draggable._startPos.add(ground);
|
|
263
|
+
};
|
|
264
|
+
draggable.on('predrag', pan);
|
|
265
|
+
this.once('unload', () => draggable.off('predrag', pan));
|
|
266
|
+
});
|
|
267
|
+
if (this.options.rotate || this.options.trackContainerMutation) {
|
|
268
|
+
this.cameraReady = import('./cameraControls.js').then(({ cameraControls }) => {
|
|
269
|
+
if (!this._container?._leaflet_id) return;
|
|
270
|
+
cameraControls(this);
|
|
271
|
+
});
|
|
272
|
+
this.cameraReady.catch(error => this.fire('error', { error }));
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const markerMethods = Object.defineProperties({}, Object.getOwnPropertyDescriptors(L.Marker.prototype));
|
|
277
|
+
L.Marker.mergeOptions({ rotation: 0, rotateWithView: false, keepUpright: false, scale: 1 });
|
|
278
|
+
L.Marker.include({
|
|
279
|
+
setIcon(icon) {
|
|
280
|
+
if (!(icon instanceof L.DivIcon)) icon.options.crossOrigin ||= true;
|
|
281
|
+
const result = markerMethods.setIcon.call(this, icon);
|
|
282
|
+
if (this._map && !(icon instanceof L.DivIcon)) this._initNativeGPU(this._map);
|
|
283
|
+
return result;
|
|
284
|
+
},
|
|
285
|
+
setRotation(rotation) {
|
|
286
|
+
if (!Number.isFinite(rotation)) throw new TypeError('Marker rotation must be finite');
|
|
287
|
+
this.options.rotation = rotation;
|
|
288
|
+
this.update();
|
|
289
|
+
this._nativeGPU?.refresh?.();
|
|
290
|
+
return this;
|
|
291
|
+
},
|
|
292
|
+
_cameraIconPoint(x, y) {
|
|
293
|
+
let rotation = this.options.rotation + (this.options.rotateWithView ? this._map.getBearing() * radians : 0);
|
|
294
|
+
if (this.options.keepUpright && Math.cos(rotation) < 0) rotation += Math.PI;
|
|
295
|
+
const scale = this.options.scale;
|
|
296
|
+
return new L.Point((x * Math.cos(rotation) - y * Math.sin(rotation)) * scale,
|
|
297
|
+
(x * Math.sin(rotation) + y * Math.cos(rotation)) * scale);
|
|
298
|
+
},
|
|
299
|
+
getEvents() {
|
|
300
|
+
return { ...markerMethods.getEvents.call(this), rotate: this.update, pitch: this.update, move: this.update };
|
|
301
|
+
},
|
|
302
|
+
_setPos(point) {
|
|
303
|
+
markerMethods._setPos.call(this, displayPoint(this._map, point));
|
|
304
|
+
for (const [element, key] of [[this._icon, 'iconAnchor'], [this._shadow, 'shadowAnchor']]) {
|
|
305
|
+
if (!element) continue;
|
|
306
|
+
const direction = this._cameraIconPoint(1, 0), options = this.options.icon.options;
|
|
307
|
+
const anchor = options[key] || options.iconAnchor;
|
|
308
|
+
element.style.transformOrigin = anchor ? `${anchor.x ?? anchor[0]}px ${anchor.y ?? anchor[1]}px` : 'center';
|
|
309
|
+
element.style.transform += ` rotate(${Math.atan2(direction.y, direction.x)}rad) scale(${this.options.scale})`;
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
_updateZIndex(offset) {
|
|
313
|
+
markerMethods._updateZIndex.call(this, offset);
|
|
314
|
+
const changed = this._cameraZIndexOffset !== offset;
|
|
315
|
+
this._cameraZIndexOffset = offset;
|
|
316
|
+
if (changed) this._nativeGPU?.refresh?.();
|
|
317
|
+
},
|
|
318
|
+
_initInteraction() {
|
|
319
|
+
const result = markerMethods._initInteraction.call(this);
|
|
320
|
+
cameraMarkerDrag.call(this);
|
|
321
|
+
return result;
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// Keep Leaflet's focusable marker and its drag events; only translate its screen position back to ground.
|
|
326
|
+
function cameraMarkerDrag() {
|
|
327
|
+
if (!this.dragging || this.dragging._cameraDrag) return;
|
|
328
|
+
const drag = this.dragging, original = drag._onDrag, adjustPan = drag._adjustPan;
|
|
329
|
+
drag._onDrag = function (event) {
|
|
330
|
+
const map = this._marker._map;
|
|
331
|
+
const screen = L.DomUtil.getPosition(this._marker._icon).add(map._getMapPanePos());
|
|
332
|
+
const point = map.containerPointToLayerPoint(screen);
|
|
333
|
+
const icon = this._marker._icon;
|
|
334
|
+
L.DomUtil.setPosition(icon, point);
|
|
335
|
+
original.call(this, event);
|
|
336
|
+
this._marker._setPos(point);
|
|
337
|
+
};
|
|
338
|
+
drag._adjustPan = function (event) {
|
|
339
|
+
const marker = this._marker, map = marker._map;
|
|
340
|
+
if (!map.getPitch() && !map.getBearing()) return adjustPan.call(this, event);
|
|
341
|
+
const screen = L.DomUtil.getPosition(marker._icon).add(map._getMapPanePos());
|
|
342
|
+
const size = map.getSize(), padding = pointOf(marker.options.autoPanPadding);
|
|
343
|
+
const speed = marker.options.autoPanSpeed;
|
|
344
|
+
const movement = new L.Point(
|
|
345
|
+
(Math.max(0, screen.x - size.x + padding.x) - Math.max(0, padding.x - screen.x)) / Math.max(1, padding.x) * speed,
|
|
346
|
+
(Math.max(0, screen.y - size.y + padding.y) - Math.max(0, padding.y - screen.y)) / Math.max(1, padding.y) * speed);
|
|
347
|
+
if (!movement.x && !movement.y) return;
|
|
348
|
+
const pane = map._getMapPanePos();
|
|
349
|
+
map.panBy(movement, { animate: false });
|
|
350
|
+
const shift = pane.subtract(map._getMapPanePos());
|
|
351
|
+
this._draggable._newPos._add(shift);
|
|
352
|
+
this._draggable._startPos._add(shift);
|
|
353
|
+
L.DomUtil.setPosition(marker._icon, this._draggable._newPos);
|
|
354
|
+
this._onDrag(event);
|
|
355
|
+
this._panRequest = requestAnimationFrame(() => this._adjustPan(event));
|
|
356
|
+
};
|
|
357
|
+
// The handler may already be enabled and listening with its original method.
|
|
358
|
+
const enabled = drag.enabled();
|
|
359
|
+
if (enabled) {
|
|
360
|
+
drag._draggable.off('drag', original, drag);
|
|
361
|
+
drag._draggable.on('drag', drag._onDrag, drag);
|
|
362
|
+
}
|
|
363
|
+
drag._cameraDrag = true;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
for (const Class of [L.Popup, L.Tooltip]) {
|
|
367
|
+
const events = Class.prototype.getEvents;
|
|
368
|
+
Class.include({
|
|
369
|
+
getEvents() {
|
|
370
|
+
return { ...events.call(this), rotate: this._updatePosition, pitch: this._updatePosition, move: this._updatePosition };
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const popupPosition = L.Popup.prototype._updatePosition;
|
|
375
|
+
const popupPan = L.Popup.prototype._adjustPan;
|
|
376
|
+
L.Popup.include({
|
|
377
|
+
_adjustPan() {
|
|
378
|
+
const map = this._map;
|
|
379
|
+
if (!map.getPitch() && !map.getBearing()) return popupPan.call(this);
|
|
380
|
+
if (!this.options.autoPan) return;
|
|
381
|
+
if (map._panAnim) map._panAnim.stop();
|
|
382
|
+
if (this._autopanning) { this._autopanning = false; return; }
|
|
383
|
+
const rect = this._container.getBoundingClientRect(), container = map.getContainer().getBoundingClientRect();
|
|
384
|
+
const min = pointOf(this.options.autoPanPaddingTopLeft || this.options.autoPanPadding);
|
|
385
|
+
const max = map.getSize().subtract(pointOf(this.options.autoPanPaddingBottomRight || this.options.autoPanPadding));
|
|
386
|
+
const left = rect.left - container.left, top = rect.top - container.top;
|
|
387
|
+
const right = rect.right - container.left, bottom = rect.bottom - container.top;
|
|
388
|
+
const dx = Math.min(0, left - min.x) || Math.max(0, right - max.x);
|
|
389
|
+
const dy = Math.min(0, top - min.y) || Math.max(0, bottom - max.y);
|
|
390
|
+
if (!dx && !dy) return;
|
|
391
|
+
if (this.options.keepInView) this._autopanning = true;
|
|
392
|
+
const screen = map.latLngToContainerPoint(this._latlng).subtract(new L.Point(dx, dy));
|
|
393
|
+
const delta = map.latLngToLayerPoint(this._latlng).subtract(map.containerPointToLayerPoint(screen));
|
|
394
|
+
map.fire('autopanstart');
|
|
395
|
+
map.panTo(map.unproject(map.project(map.getCenter()).add(delta)));
|
|
396
|
+
},
|
|
397
|
+
_updatePosition() {
|
|
398
|
+
popupPosition.call(this);
|
|
399
|
+
if (!this._map) return;
|
|
400
|
+
const point = this._map.latLngToLayerPoint(this._latlng), delta = displayPoint(this._map, point).subtract(point);
|
|
401
|
+
if (this._zoomAnimated) {
|
|
402
|
+
L.DomUtil.setPosition(this._container, L.DomUtil.getPosition(this._container).add(delta));
|
|
403
|
+
} else {
|
|
404
|
+
this._container.style.left = `${this._containerLeft + delta.x}px`;
|
|
405
|
+
this._container.style.bottom = `${this._containerBottom - delta.y}px`;
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
const tooltipPosition = L.Tooltip.prototype._setPosition;
|
|
410
|
+
L.Tooltip.include({
|
|
411
|
+
_setPosition(point) {
|
|
412
|
+
tooltipPosition.call(this, point);
|
|
413
|
+
const delta = displayPoint(this._map, point).subtract(point);
|
|
414
|
+
L.DomUtil.setPosition(this._container, L.DomUtil.getPosition(this._container).add(delta));
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
const tiledBounds = L.GridLayer.prototype._getTiledPixelBounds;
|
|
419
|
+
const gridEvents = L.GridLayer.prototype.getEvents;
|
|
420
|
+
L.GridLayer.include({
|
|
421
|
+
getEvents() {
|
|
422
|
+
const events = gridEvents.call(this);
|
|
423
|
+
this._cameraGridUpdate ||= L.Util.throttle(this._onMoveEnd, this.options.updateInterval, this);
|
|
424
|
+
return { ...events, rotate: this._cameraGridUpdate, pitch: this._cameraGridUpdate };
|
|
425
|
+
},
|
|
426
|
+
_getTiledPixelBounds(center) {
|
|
427
|
+
if (!this._map.getBearing() && !this._map.getPitch()) return tiledBounds.call(this, center);
|
|
428
|
+
const bounds = this._map.getBounds();
|
|
429
|
+
return new L.Bounds(this._map.project(bounds.getNorthWest(), this._tileZoom),
|
|
430
|
+
this._map.project(bounds.getSouthEast(), this._tileZoom));
|
|
431
|
+
},
|
|
432
|
+
});
|