@luothink/three-gis-kit
v1.0.0
Published
A utility library for three.js GIS, including CSG operations, coordinate transformation, geometry calculations and pipe modeling.
Maintainers
Readme
@luothink/three-gis-kit
A utility library for three.js GIS calculations.
Installation
npm install @luothink/three-gis-kitUsage
import { CSGUtils, GeometryUtils, GeoCoordUtils, GISUtils } from '@luothink/three-gis-kit';API
CSGUtils
提供 CSG (three-bvh-csg) 布尔运算功能。
performCSG(THREE, CSG, meshA, meshB, operation)
执行 CSG 布尔运算。
| 参数 | 类型 | 说明 | |------|------|------| | THREE | Object | THREE.js 库对象 | | CSG | Object | CSG 库对象 (three-bvh-csg) | | meshA | Mesh | 待运算的 Mesh 对象 A | | meshB | Mesh | 待运算的 Mesh 对象 B | | operation | String | 运算操作 |
operation 可选值:
union- 并集 (A ∪ B)subtract- 差集 (A - B)intersect- 交集 (A ∩ B)difference- 对称差集 (A ⊕ B)reverse_subtraction- 反向差集 (B - A)hollow_subtract- 空心差集hollow_intersection- 空心交集
import { CSGUtils } from '@luothink/three-gis-kit';
import * as THREE from 'three';
import * as CSG from 'three-bvh-csg';
const resultMesh = CSGUtils.performCSG(THREE, CSG, meshA, meshB, 'subtract');GeoCoordUtils
提供 GIS 坐标转换功能,包括经纬度、墨卡托、世界坐标的转换。
lonLatToMercator(lng, lat, alt?)
将经纬度转换为墨卡托投影坐标。
import { GeoCoordUtils } from '@luothink/three-gis-kit';
const mercator = GeoCoordUtils.lonLatToMercator(121.543793, 29.868336);
// { x: 13528332.56, y: 3503547.56, z: 0 }mercatorToLonLat(x, y, z?)
将墨卡托投影坐标转换为经纬度。
const lnglat = GeoCoordUtils.mercatorToLonLat(13528332.56, 3503547.56);
// { x: 121.543793, y: 29.868336, z: 0 }lonLatToWorld(lng, lat, alt?)
将经纬度转换为世界坐标 (Three.js 坐标系)。
const world = GeoCoordUtils.lonLatToWorld(121.543793, 29.868336, 100);
// { x: 13528332.56, y: 100, z: -3503547.56 }worldToLonLat(x, y, z)
将世界坐标转换为经纬度。
const lnglat = GeoCoordUtils.worldToLonLat(13528332.56, 100, -3503547.56);
// { x: 121.543793, y: 29.868336, z: 100 }mercatorToWorld(x, y, alt?)
将墨卡托投影坐标转换为世界坐标。
worldToMercator(x, y, z)
将世界坐标转换为墨卡托投影坐标。
GISUtils
提供 GIS 相关的实用工具函数。
calcDistance(start, end, ignoreAltitude?)
计算两点之间的距离(考虑海拔高度)。
| 参数 | 类型 | 说明 | |------|------|------| | start | {x, y, z} | 起点坐标 | | end | {x, y, z} | 终点坐标 | | ignoreAltitude | Boolean | 是否忽略海拔,默认 false |
import { GISUtils } from '@luothink/three-gis-kit';
const start = { x: 121.543793, y: 29.868336, z: 0 };
const end = { x: 121.553793, y: 29.878336, z: 50 };
const distance = GISUtils.calcDistance(start, end);
// 返回距离(米)calcPipeLength_ar(start, end, THREE)
计算 3D 管长(圆柱体高度)。
const length = GISUtils.calcPipeLength_ar(start, end, THREE);degreesToDMS(degrees, isLongitude?)
将十进制度数转换为度分秒 (DMS) 格式。
const result = GISUtils.degreesToDMS(121.543793, true);
console.log(result.toString()); // "121°32'37.6548\"E"toRadian(degrees)
角度转弧度。
toDegree(radians)
弧度转角度。
GeometryUtils
提供几何计算功能。
lineToCylinder(THREE, startingPoint, endPoint, radiusStart, radiusEnd, material, radiusIncrement?, pipeLength_ar)
将两点之间的线段转换为圆柱体(管道)模型。
import { GeometryUtils } from '@luothink/three-gis-kit';
import * as THREE from 'three';
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const start = { x: 0, y: 0, z: 0 };
const end = { x: 10, y: 10, z: 10 };
const pipeLength = 17.32;
const cylinder = GeometryUtils.lineToCylinder(
THREE, start, end, 0.5, 0.5, material, 0, pipeLength
);adjustLineLength(startPoint, endPoint, pipeLength, newLength, fixedPoint?)
调整管道长度(保持方向不变)。
| 参数 | 类型 | 说明 | |------|------|------| | startPoint | {x, y, z} | 起点坐标 | | endPoint | {x, y, z} | 终点坐标 | | pipeLength | Number | 当前管道长度 | | newLength | Number | 目标长度 | | fixedPoint | String | 固定点: "start" 或 "end" |
const result = GeometryUtils.adjustLineLength(
{ x: 0, y: 0, z: 0 },
{ x: 10, y: 0, z: 0 },
10,
20,
'start'
);
// { start: {x:0, y:0, z:0}, end: {x:20, y:0, z:0} }License
ISC# @luothink/three-gis-kit
A utility library for three.js GIS calculations.
Installation
npm install @luothink/three-gis-kitUsage
import { /* your exports */ } from '@luothink/three-gis-kit';
// 使用示例API
- CSGUtils
- GeometryUtils
- GeoCoordUtils
- GISUtils
License
ISC
