cesium-pocket 0.7.0-alpha → 0.7.2-alpha

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.
@@ -0,0 +1,204 @@
1
+ import { Cartesian3, Color, Viewer } from 'cesium';
2
+ import { PathPoint } from './pathHeightMath';
3
+ export type { PathPoint };
4
+ /** 编辑器可配置项,所有字段都有默认值 */
5
+ export interface PathHeightEditorOptions {
6
+ /** 高度下限(米),默认 0 */
7
+ minHeight?: number;
8
+ /** 高度上限(米),默认不限 */
9
+ maxHeight?: number;
10
+ /** 空中折线颜色,默认青色 */
11
+ lineColor?: Color;
12
+ /** 地面投影虚线颜色 */
13
+ groundLineColor?: Color;
14
+ /** 节点圆点颜色 */
15
+ pointColor?: Color;
16
+ /** 拖拽中的节点颜色 */
17
+ activeColor?: Color;
18
+ /** 垂线颜色 */
19
+ stickColor?: Color;
20
+ /** 是否显示地面投影虚线与垂线,默认显示 */
21
+ showProjection?: boolean;
22
+ /** 是否允许拖拽,默认允许 */
23
+ editable?: boolean;
24
+ /** 每个节点下方的地面参考高度(米),不传则取初始节点的高度 */
25
+ groundHeights?: number[];
26
+ /** 高度变化回调,拖拽过程中会持续触发,index 为 -1 表示批量修改 */
27
+ onChange?: (points: PathPoint[], index: number) => void;
28
+ /** 开始拖拽某个节点 */
29
+ onDragStart?: (index: number) => void;
30
+ /** 结束拖拽 */
31
+ onDragEnd?: (index: number) => void;
32
+ }
33
+ /**
34
+ * 折线节点高程编辑器。
35
+ *
36
+ * - 每个节点是一个可拖拽的圆点,拖拽时只改变高程,经纬度保持不变;
37
+ * - 也可以通过 {@link setHeight} / {@link setHeights} 直接改指定节点的高度;
38
+ * - 节点高度变化会实时反映到折线、垂线和标签上。
39
+ *
40
+ * 纯几何计算(坐标转换、钳制、射线求高度)见 `pathHeightMath.ts`。
41
+ *
42
+ * ```ts
43
+ * // 直接传绘制得到的 Cartesian3[]
44
+ * const editor = new PathHeightEditor(viewer, positions);
45
+ * editor.setHeight(0, 1500);
46
+ * ```
47
+ */
48
+ export declare class PathHeightEditor {
49
+ /** 所属三维场景 */
50
+ private readonly viewer;
51
+ /** 创建时传入的配置,构造后不再变化 */
52
+ private readonly options;
53
+ /** 拖拽所需的鼠标事件句柄 */
54
+ private readonly handler;
55
+ /** 编辑器所有实体都放这个数据源里,销毁时统一移除 */
56
+ private readonly dataSource;
57
+ /** 节点实体 → 序号,拖拽拾取时用,避免解析字符串 */
58
+ private readonly nodeEntities;
59
+ /** 节点数据,索引与 nodeEntities 中的序号一致 */
60
+ private points;
61
+ /** 每个节点下方的地面参考高度,用于绘制垂线 */
62
+ private groundHeights;
63
+ /** 是否允许拖拽,可在运行时切换 */
64
+ private editable;
65
+ /** 正在拖拽的节点序号,未拖拽为 -1 */
66
+ private activeIndex;
67
+ /** 上一帧鼠标位置,射线求解退化时按像素差换算高度 */
68
+ private lastScreen;
69
+ /** 是否已销毁,销毁后所有公共方法变为空操作 */
70
+ private destroyed;
71
+ /**
72
+ * 创建编辑器:转换节点数据、注册数据源、生成实体并绑定鼠标事件。
73
+ *
74
+ * @param viewer 三维场景
75
+ * @param positions 折线节点,通常来自绘制工具,直接传 Cartesian3[]
76
+ * @param options 可选配置
77
+ */
78
+ constructor(viewer: Viewer, positions: Cartesian3[], options?: PathHeightEditorOptions);
79
+ /**
80
+ * 读取当前所有节点。返回的是副本,修改不会影响编辑器内部数据。
81
+ * @returns 节点数组,经纬度为度、高度为米
82
+ */
83
+ getPoints(): PathPoint[];
84
+ /**
85
+ * 读取当前所有节点的世界坐标,可直接用于绘制折线或生成 CZML。
86
+ * @returns 每个节点当前空中位置
87
+ */
88
+ getPositions(): Cartesian3[];
89
+ /**
90
+ * 读取当前所有节点的高度。
91
+ * @returns 与节点顺序一致的高度数组(米)
92
+ */
93
+ getHeights(): number[];
94
+ /**
95
+ * 查询当前正在拖拽的节点。
96
+ * @returns 节点序号,未在拖拽时返回 -1
97
+ */
98
+ getActiveIndex(): number;
99
+ /**
100
+ * 运行时开关拖拽。关闭时会立即结束正在进行的拖拽,并恢复相机操作。
101
+ * @param editable 是否允许拖拽
102
+ */
103
+ setEditable(editable: boolean): void;
104
+ /**
105
+ * 修改单个节点的高度,用于输入框等外部入口。
106
+ * 高度会按 `minHeight` / `maxHeight` 钳制,值未变化时不触发回调。
107
+ * @param index 节点序号
108
+ * @param height 目标高度(米)
109
+ */
110
+ setHeight(index: number, height: number): void;
111
+ /**
112
+ * 批量修改高度,按数组顺序对应节点;多出的高度或非有限值会被忽略。
113
+ * 有实际变化时以 index = -1 触发一次 `onChange`。
114
+ * @param heights 高度数组(米)
115
+ */
116
+ setHeights(heights: number[]): void;
117
+ /**
118
+ * 用新的折线整体替换当前节点,重建全部实体。
119
+ * 会先结束正在进行的拖拽。
120
+ * @param positions 新的折线节点(世界坐标)
121
+ */
122
+ setPoints(positions: Cartesian3[]): void;
123
+ /**
124
+ * 销毁编辑器:结束拖拽、移除事件句柄、移除数据源及全部实体。
125
+ * 重复调用安全。
126
+ */
127
+ destroy(): void;
128
+ /**
129
+ * 按当前节点数据重建全部实体:地面投影、空中折线、节点与垂线。
130
+ * 节点位置/高度都通过 CallbackProperty 实时读取,改动数据后无需重建即可刷新。
131
+ */
132
+ private build;
133
+ /**
134
+ * 创建单个节点的圆点、标签,以及(可选)垂直投影线。
135
+ * @param index 节点序号
136
+ * @param showProjection 是否同时创建垂线
137
+ */
138
+ private addNode;
139
+ /** 绑定鼠标按下、移动、抬起三个事件 */
140
+ private bindEvents;
141
+ /**
142
+ * 左键按下:命中节点则进入拖拽状态。
143
+ * 拖拽期间关闭相机操作,否则视角会和节点一起被拖动。
144
+ * @param screenPosition 鼠标位置(画布坐标)
145
+ */
146
+ private onLeftDown;
147
+ /**
148
+ * 鼠标移动:拖拽中则更新高度;未拖拽时只切换悬停光标。
149
+ * @param screenPosition 鼠标位置(画布坐标)
150
+ */
151
+ private onMouseMove;
152
+ /** 结束拖拽:复位状态、恢复相机操作与光标,并触发 `onDragEnd` */
153
+ private endDrag;
154
+ /**
155
+ * 在鼠标位置拾取节点。
156
+ * 先用 Map 命中,失败再退化为解析实体 id,兼容拾取结果的包装差异。
157
+ * @param screenPosition 鼠标位置(画布坐标)
158
+ * @returns 节点序号,未命中返回 -1
159
+ */
160
+ private pickNode;
161
+ /** 各节点当前高度位置,用于空中折线 */
162
+ private airPositions;
163
+ /** 各节点在地面参考高度上的投影,用于地面虚线 */
164
+ private groundPositions;
165
+ /**
166
+ * 单个节点垂线的两个端点。
167
+ * @param index 节点序号
168
+ */
169
+ private stickPositions;
170
+ /**
171
+ * 节点当前位置。
172
+ * @param index 节点序号
173
+ */
174
+ private nodePosition;
175
+ /**
176
+ * 节点对应的地面参考高度,越界或非法值按 0 处理。
177
+ * @param index 节点序号
178
+ */
179
+ private groundHeightAt;
180
+ /**
181
+ * 节点颜色:拖拽中高亮,否则用配置色(默认橙色)。
182
+ * @param index 节点序号
183
+ */
184
+ private nodeColor;
185
+ /**
186
+ * 批量计算地面参考高度,结果与节点顺序一一对应。
187
+ * @param points 节点数组
188
+ */
189
+ private buildGroundHeights;
190
+ /**
191
+ * 按配置的上下限钳制高度。
192
+ * @param height 原始高度(米)
193
+ */
194
+ private clampHeight;
195
+ /**
196
+ * 单节点变化:请求重绘并通知调用方。
197
+ * @param index 变化节点的序号
198
+ */
199
+ private notify;
200
+ /** 整体变化:请求重绘并以 index = -1 通知调用方 */
201
+ private refresh;
202
+ /** 请求一次重绘,兼容 requestRenderMode 与已销毁的场景 */
203
+ private requestRender;
204
+ }
@@ -0,0 +1,89 @@
1
+ import { Cartesian2, Cartesian3, Viewer } from 'cesium';
2
+ /** 折线节点:经度、纬度(度)与高度(米) */
3
+ export type PathPoint = {
4
+ /** 经度(度,WGS84) */
5
+ lon: number;
6
+ /** 纬度(度,WGS84) */
7
+ lat: number;
8
+ /** 高度(米),绝对高程 */
9
+ height: number;
10
+ };
11
+ /** 节点实体 id 前缀,拾取时用于反查节点序号 */
12
+ export declare const NODE_ID_PREFIX = "pathHeightNode";
13
+ /**
14
+ * 拼接节点实体 id。
15
+ * @param index 节点序号
16
+ */
17
+ export declare const nodeId: (index: number) => string;
18
+ /**
19
+ * 复制一个节点,避免把内部对象直接暴露给调用者。
20
+ * @param point 源节点
21
+ * @returns 新的节点对象
22
+ */
23
+ export declare const clonePoint: (point: PathPoint) => PathPoint;
24
+ /**
25
+ * 世界坐标转经纬度 + 高度。
26
+ * 绘制工具给出的坐标是笛卡尔坐标,编辑器内部统一用经纬度 + 高度存储,
27
+ * 这样拖拽计算时不必反复做反投影。
28
+ * @param cartesian 世界坐标
29
+ * @returns 节点(经度、纬度单位为度)
30
+ */
31
+ export declare const toPathPoint: (cartesian: Cartesian3) => PathPoint;
32
+ /**
33
+ * 节点转世界坐标,高度取节点自身高度(空中位置)。
34
+ * @param point 节点
35
+ */
36
+ export declare const toCartesian3: (point: PathPoint) => Cartesian3;
37
+ /**
38
+ * 节点投影到指定地面高度上的世界坐标,用于垂线起点和地面投影虚线。
39
+ * @param point 节点
40
+ * @param groundHeight 地面参考高度(米)
41
+ */
42
+ export declare const toGroundCartesian3: (point: PathPoint, groundHeight: number) => Cartesian3;
43
+ /**
44
+ * 把高度限制在 [min, max] 区间内。
45
+ * 拖拽和输入数字两条路径都经过这里,保证行为一致。
46
+ * @param height 原始高度
47
+ * @param min 下限,默认 0
48
+ * @param max 上限,默认不限
49
+ */
50
+ export declare const clampHeight: (height: number, min?: number, max?: number) => number;
51
+ /**
52
+ * 确定垂线的地面起点高度。
53
+ * 优先使用调用方显式给的 `groundHeights`;没给时退回节点初始高度,
54
+ * 这样从绘制结果创建时,垂线起点就是绘制点落在地形上的位置。
55
+ * @param point 节点
56
+ * @param index 节点序号
57
+ * @param groundHeights 调用方指定的地面高度数组(可选)
58
+ */
59
+ export declare const resolveGroundHeight: (point: PathPoint, index: number, groundHeights?: number[]) => number;
60
+ /**
61
+ * 生成节点标签文本,形如 `P1 · 3800 m`。
62
+ * @param index 节点序号(从 0 开始,展示时 +1)
63
+ * @param height 当前高度(米)
64
+ */
65
+ export declare const formatNodeLabel: (index: number, height: number) => string;
66
+ /**
67
+ * 从实体 id 反解节点序号。
68
+ * 拾取到的实体可能是任意类型,这里对非 `pathHeightNode{n}` 形式的 id 返回 -1。
69
+ * @param id 实体 id(未知类型)
70
+ * @returns 节点序号,非本编辑器的实体返回 -1
71
+ */
72
+ export declare const parseNodeIndex: (id: unknown) => number;
73
+ /**
74
+ * 计算拖拽后节点的新高度,经纬度保持不变。
75
+ *
76
+ * 做法:取屏幕点对应的相机射线,求该射线与“过节点、沿地表法线方向”的
77
+ * 竖直线的最近点,最近点在竖直线上的位置即为新高度。这样鼠标上下移动
78
+ * 时节点只会沿竖直线升降,不会平移。
79
+ *
80
+ * 相机近乎垂直俯视时射线与竖直线接近平行,公式分母趋近 0,此时退化为
81
+ * 按“上一帧鼠标位置”的纵向像素差换算成米数。
82
+ *
83
+ * @param viewer 三维场景
84
+ * @param point 当前被拖拽的节点(用于取其经纬度和当前高度)
85
+ * @param screenPosition 当前鼠标位置(画布坐标)
86
+ * @param lastScreen 上一帧鼠标位置,仅像素换算兜底时使用
87
+ * @returns 新的绝对高度(米),未做上下限钳制
88
+ */
89
+ export declare const screenHeightOnVerticalLine: (viewer: Viewer, point: PathPoint, screenPosition: Cartesian2, lastScreen: Cartesian2) => number;
@@ -0,0 +1,6 @@
1
+ import { Cartesian3, Entity } from 'cesium';
2
+ import { PullColumn } from './pullColumn';
3
+ /** 正圆底面拉成圆柱,体积 = πr²h。 */
4
+ export declare class CircleSolid extends PullColumn {
5
+ add(entity: Entity, center: Cartesian3, radius: number): void;
6
+ }
@@ -0,0 +1,43 @@
1
+ import { Cartesian3, Viewer } from 'cesium';
2
+ export type HeightPoleOptions = {
3
+ /** 放好一个圆面后通知页面,用来更新提示。 */
4
+ onPlace?: () => void;
5
+ };
6
+ /**
7
+ * 地面上的水平小圆面,拉高时圆面跟着上升,圆面始终与当地水平面平行。
8
+ * 圆面用 Primitive 只建一次,拉高时改 modelMatrix,避免 Entity 椭圆每帧重建导致闪烁。
9
+ * 放置与拖拽都在类内用 ScreenSpaceEventHandler 处理。
10
+ */
11
+ export declare class HeightPole {
12
+ private readonly viewer;
13
+ private readonly onPlace;
14
+ private readonly records;
15
+ private readonly handler;
16
+ private drag;
17
+ private placing;
18
+ /** 拖完圆面后会冒泡出 LEFT_CLICK,用来挡住误放置。 */
19
+ private suppressClick;
20
+ private cameraHeld;
21
+ private destroyed;
22
+ private lastPosition;
23
+ constructor(viewer: Viewer, options?: HeightPoleOptions);
24
+ /** 开始在地图上放置圆面。放置会保持开启,以便连续测量。 */
25
+ start(): void;
26
+ add(position: Cartesian3): void;
27
+ hits(windowPosition: {
28
+ x: number;
29
+ y: number;
30
+ }): boolean;
31
+ destroy(): void;
32
+ private readonly applyExtrude;
33
+ private readonly metersPerPixel;
34
+ private readonly find;
35
+ private readonly hover;
36
+ private readonly onClick;
37
+ private readonly onDown;
38
+ private readonly onMove;
39
+ private readonly onUp;
40
+ private readonly canvasPosition;
41
+ private readonly stopCamera;
42
+ private readonly restoreCamera;
43
+ }
@@ -0,0 +1,6 @@
1
+ import { Cartesian3, Entity } from 'cesium';
2
+ import { PullColumn } from './pullColumn';
3
+ /** 多边形底面拉成棱柱,体积 = 底面积 × 高度。 */
4
+ export declare class PolygonSolid extends PullColumn {
5
+ add(entity: Entity, positions: Cartesian3[]): void;
6
+ }
@@ -0,0 +1,37 @@
1
+ import { Cartesian3, EllipseGraphics, Entity, PolygonGraphics, Viewer } from 'cesium';
2
+ type HeightGraphic = EllipseGraphics | PolygonGraphics;
3
+ export declare const centroid: (positions: Cartesian3[]) => Cartesian3;
4
+ export declare const averageHeight: (positions: Cartesian3[]) => number;
5
+ export declare const planarArea: (positions: Cartesian3[]) => number;
6
+ /**
7
+ * 把已经画好的贴地底面向上拉成柱体,并在柱顶标注体积。
8
+ * 鼠标移到底面上时显示上下拖动光标。
9
+ */
10
+ export declare class PullColumn {
11
+ private readonly viewer;
12
+ private readonly records;
13
+ private readonly handler;
14
+ private drag;
15
+ private cameraHeld;
16
+ private paused;
17
+ private destroyed;
18
+ private lastPosition;
19
+ constructor(viewer: Viewer);
20
+ /** 贴地绘制过程中暂停上拉,避免和绘制抢鼠标。 */
21
+ setPause(paused: boolean): void;
22
+ destroy(): void;
23
+ protected mount(entity: Entity, graphic: HeightGraphic, center: Cartesian3, baseHeight: number, area: number): void;
24
+ private readonly currentExtrude;
25
+ private readonly applyExtrude;
26
+ private readonly metersPerPixel;
27
+ private readonly createLabel;
28
+ private readonly canvasPosition;
29
+ private readonly findVolume;
30
+ private readonly hover;
31
+ private readonly onExtrudeDown;
32
+ private readonly onExtrudeMove;
33
+ private readonly onExtrudeUp;
34
+ private readonly stopCameraOnVolume;
35
+ private readonly restoreCamera;
36
+ }
37
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Cartesian3, Entity } from 'cesium';
2
+ import { PullColumn } from './pullColumn';
3
+ /** 矩形底面拉成四棱柱。corners 为贴地四个顶点,第 1、3 个点是鼠标点下的对角点。 */
4
+ export declare class RectSolid extends PullColumn {
5
+ add(entity: Entity, corners: Cartesian3[]): void;
6
+ }
@@ -8,10 +8,17 @@ export declare const getDistanceLabel: (distance: number) => string;
8
8
  * @returns
9
9
  */
10
10
  export declare const getCentroid: (positions: Cartesian3[]) => Cartesian3 | null;
11
+ /** 顶点高程的平均值,单位米。 */
12
+ export declare const averageHeight: (positions: Cartesian3[]) => number;
13
+ /**
14
+ * 计算平面多边形面积,单位平方米。
15
+ * 以点集包围球中心建立东北天局部坐标系,再用鞋带公式求面积。
16
+ */
17
+ export declare const getPlanarArea: (positions: Cartesian3[]) => number;
18
+ export declare const getAreaText: (area: number) => string;
11
19
  /**
12
20
  * 计算面积
13
21
  * @param positions
14
22
  * @returns
15
23
  */
16
24
  export declare const calculatePlanarArea: (positions: Cartesian3[]) => string;
17
- export declare const getAreaText: (area: number) => string;