@vesium/plot 1.0.1-beta.50 → 1.0.1-beta.51

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/dist/index.mjs CHANGED
@@ -1,1477 +1,1481 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { JulianDate, Event, TimeInterval, Cartesian3, createGuid, Entity, PrimitiveCollection, CustomDataSource, ScreenSpaceEventType, Color, VerticalOrigin, HorizontalOrigin, Rectangle, CoplanarPolygonGeometry, VertexFormat, ClassificationType, CallbackProperty, ConstantPositionProperty, ConstantProperty, PolygonHierarchy, CallbackPositionProperty } from "cesium";
5
- import { assertError, useViewer, usePrimitive, useDataSource, useEntityScope, usePrimitiveScope, useScreenSpaceEventHandler, canvasCoordToCartesian, useCesiumEventListener, arrayDiff, isFunction, useGraphicEvent, pickHitGraphic, toCartographic, toCartesian3 } from "vesium";
6
- import { assert, watchArray, promiseTimeout, onKeyStroke } from "@vueuse/core";
7
- import { shallowRef, watch, computed, ref, watchEffect, toValue, nextTick, shallowReactive } from "vue";
8
- const _PlotScheme = class _PlotScheme {
9
- constructor(options) {
10
- /**
11
- * 标绘类型。应当是全局唯一的字符串,会作为键名缓存
12
- */
13
- __publicField(this, "type");
14
- /**
15
- * 判断是否立即完成标绘.
16
- * 每次控制点发生变变化时,执行该回调函数,返回`true`则完成标绘
17
- */
18
- __publicField(this, "complete");
19
- /**
20
- * 判断是否允许手动完成标绘。
21
- * 每次控制点发生变变化时,执行该回调函数,返回`true`则后续左键双击即完成标绘
22
- */
23
- __publicField(this, "allowManualComplete");
24
- /**
25
- * 处于定义态时鼠标的样式
26
- * @default 'crosshair'
27
- */
28
- __publicField(this, "definingCursor");
29
- /**
30
- * 当前标绘的框架点数据
31
- */
32
- __publicField(this, "skeletons");
33
- /**
34
- * 初始化时创建`Entity`的函数,创建后的`Entity`会作为配置项传入`render`中
35
- */
36
- __publicField(this, "initEntites");
37
- /**
38
- * 初始化时创建`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
39
- */
40
- __publicField(this, "initPrimitives");
41
- /**
42
- * 初始化时创建贴地`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
43
- */
44
- __publicField(this, "initGroundPrimitives");
45
- /**
46
- * 当标绘数据变化时,会触发`render`回调,返回的数据会被添加到cesium中
47
- */
48
- __publicField(this, "render");
49
- var _a;
50
- this.type = options.type;
51
- this.complete = options.complete;
52
- this.allowManualComplete = options.allowManualComplete;
53
- this.definingCursor = options.definingCursor ?? "crosshair";
54
- this.skeletons = ((_a = options.skeletons) == null ? void 0 : _a.map((item) => item())) ?? [];
55
- this.initEntites = options.initEntites;
56
- this.initPrimitives = options.initPrimitives;
57
- this.initGroundPrimitives = options.initGroundPrimitives;
58
- this.render = options.render;
59
- }
60
- /**
61
- * 标绘方案缓存。
62
- * 每次标绘时都会将`PlotScheme.type`作为键名缓存,
63
- * 后续可用过`PlotScheme.getCache(type)`获取完整的`PlotScheme`配置。
64
- */
65
- static getCacheTypes() {
66
- return [...this._record.keys()];
67
- }
68
- /**
69
- * 通过`PlotScheme.type`获取缓存中的`PlotScheme`配置。
70
- */
71
- static getCache(type) {
72
- return _PlotScheme._record.get(type);
73
- }
74
- /**
75
- * 缓存标绘方案。
76
- */
77
- static setCache(scheme) {
78
- assertError(!scheme.type, "`scheme.type` is required");
79
- _PlotScheme._record.set(scheme.type, scheme);
80
- }
81
- /**
82
- * 解析传入的maybeScheme,maybeScheme可能是一个完整的PlotScheme,也可能是缓存中的`PlotScheme.type`,并返回 PlotScheme 实例。
83
- * 若传入的是`PlotScheme.type`字符串,并且缓存中不存在该标绘方案,则抛出错误。
84
- */
85
- static resolve(maybeScheme) {
86
- if (typeof maybeScheme === "string") {
87
- const _scheme = _PlotScheme.getCache(maybeScheme);
88
- assert(!!_scheme, `scheme ${maybeScheme} not found`);
89
- return _scheme;
90
- } else if (!(maybeScheme instanceof _PlotScheme)) {
91
- return new _PlotScheme(maybeScheme);
92
- } else {
93
- return maybeScheme;
94
- }
95
- }
1
+ import { CallbackPositionProperty, CallbackProperty, Cartesian3, Cartographic, ClassificationType, Color, ConstantPositionProperty, ConstantProperty, CoplanarPolygonGeometry, CustomDataSource, Ellipsoid, Entity, Event, HorizontalOrigin, JulianDate, PerInstanceColorAppearance, PolygonGeometry, PolygonHierarchy, PrimitiveCollection, Rectangle, ScreenSpaceEventType, TimeInterval, VertexFormat, VerticalOrigin, createGuid, sampleTerrainMostDetailed } from "cesium";
2
+ import { arrayDiff, assertError, canvasCoordToCartesian, isFunction, pickHitGraphic, toCartesian3, toCartographic, useCesiumEventListener, useDataSource, useEntityScope, useGraphicEvent, usePrimitive, usePrimitiveScope, useScreenSpaceEventHandler, useViewer } from "vesium";
3
+ import { assert, onKeyStroke, promiseTimeout, watchArray } from "@vueuse/core";
4
+ import { computed, nextTick, ref, shallowReactive, shallowRef, toValue, watch, watchEffect } from "vue";
5
+
6
+ //#region usePlot/PlotScheme.ts
7
+ var PlotScheme = class PlotScheme {
8
+ constructor(options) {
9
+ this.type = options.type;
10
+ this.complete = options.complete;
11
+ this.allowManualComplete = options.allowManualComplete;
12
+ this.definingCursor = options.definingCursor ?? "crosshair";
13
+ this.skeletons = options.skeletons?.map((item) => item()) ?? [];
14
+ this.initEntites = options.initEntites;
15
+ this.initPrimitives = options.initPrimitives;
16
+ this.initGroundPrimitives = options.initGroundPrimitives;
17
+ this.render = options.render;
18
+ }
19
+ /**
20
+ * 标绘类型。应当是全局唯一的字符串,会作为键名缓存
21
+ */
22
+ type;
23
+ /**
24
+ * 判断是否立即完成标绘.
25
+ * 每次控制点发生变变化时,执行该回调函数,返回`true`则完成标绘
26
+ */
27
+ complete;
28
+ /**
29
+ * 判断是否允许手动完成标绘。
30
+ * 每次控制点发生变变化时,执行该回调函数,返回`true`则后续左键双击即完成标绘
31
+ */
32
+ allowManualComplete;
33
+ /**
34
+ * 处于定义态时鼠标的样式
35
+ * @default 'crosshair'
36
+ */
37
+ definingCursor;
38
+ /**
39
+ * 当前标绘的框架点数据
40
+ */
41
+ skeletons;
42
+ /**
43
+ * 初始化时创建`Entity`的函数,创建后的`Entity`会作为配置项传入`render`中
44
+ */
45
+ initEntites;
46
+ /**
47
+ * 初始化时创建`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
48
+ */
49
+ initPrimitives;
50
+ /**
51
+ * 初始化时创建贴地`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
52
+ */
53
+ initGroundPrimitives;
54
+ /**
55
+ * 当标绘数据变化时,会触发`render`回调,返回的数据会被添加到cesium中
56
+ */
57
+ render;
58
+ static _record = /* @__PURE__ */ new Map();
59
+ /**
60
+ * 标绘方案缓存。
61
+ * 每次标绘时都会将`PlotScheme.type`作为键名缓存,
62
+ * 后续可用过`PlotScheme.getCache(type)`获取完整的`PlotScheme`配置。
63
+ */
64
+ static getCacheTypes() {
65
+ return [...this._record.keys()];
66
+ }
67
+ /**
68
+ * 通过`PlotScheme.type`获取缓存中的`PlotScheme`配置。
69
+ */
70
+ static getCache(type) {
71
+ return PlotScheme._record.get(type);
72
+ }
73
+ /**
74
+ * 缓存标绘方案。
75
+ */
76
+ static setCache(scheme) {
77
+ assertError(!scheme.type, "`scheme.type` is required");
78
+ PlotScheme._record.set(scheme.type, scheme);
79
+ }
80
+ /**
81
+ * 解析传入的maybeScheme,maybeScheme可能是一个完整的PlotScheme,也可能是缓存中的`PlotScheme.type`,并返回 PlotScheme 实例。
82
+ * 若传入的是`PlotScheme.type`字符串,并且缓存中不存在该标绘方案,则抛出错误。
83
+ */
84
+ static resolve(maybeScheme) {
85
+ if (typeof maybeScheme === "string") {
86
+ const _scheme = PlotScheme.getCache(maybeScheme);
87
+ assert(!!_scheme, `scheme ${maybeScheme} not found`);
88
+ return _scheme;
89
+ } else if (!(maybeScheme instanceof PlotScheme)) return new PlotScheme(maybeScheme);
90
+ else return maybeScheme;
91
+ }
96
92
  };
97
- __publicField(_PlotScheme, "_record", /* @__PURE__ */ new Map());
98
- let PlotScheme = _PlotScheme;
99
- var SampledPlotStrategy = /* @__PURE__ */ ((SampledPlotStrategy2) => {
100
- SampledPlotStrategy2[SampledPlotStrategy2["NEAR"] = 0] = "NEAR";
101
- SampledPlotStrategy2[SampledPlotStrategy2["CYCLE"] = 1] = "CYCLE";
102
- SampledPlotStrategy2[SampledPlotStrategy2["STRICT"] = 2] = "STRICT";
103
- return SampledPlotStrategy2;
104
- })(SampledPlotStrategy || {});
93
+
94
+ //#endregion
95
+ //#region usePlot/SampledPlotProperty.ts
96
+ let SampledPlotStrategy = /* @__PURE__ */ function(SampledPlotStrategy$1) {
97
+ SampledPlotStrategy$1[SampledPlotStrategy$1["NEAR"] = 0] = "NEAR";
98
+ SampledPlotStrategy$1[SampledPlotStrategy$1["CYCLE"] = 1] = "CYCLE";
99
+ SampledPlotStrategy$1[SampledPlotStrategy$1["STRICT"] = 2] = "STRICT";
100
+ return SampledPlotStrategy$1;
101
+ }({});
102
+ /**
103
+ * 默认插值算法
104
+ *
105
+ * @param time 时间
106
+ * @param previous 前一个数据点
107
+ * @param next 后一个数据点
108
+ * @param proportion 比例
109
+ * @returns 插值结果
110
+ */
105
111
  const defaultInterpolationAlgorithm = (time, previous, next, proportion) => {
106
- var _a, _b, _c;
107
- if (proportion === 0) {
108
- return {
109
- time,
110
- positions: (_a = previous.positions) == null ? void 0 : _a.map((item) => item.clone()),
111
- derivative: previous.derivative
112
- };
113
- } else if (proportion === 1) {
114
- return {
115
- time,
116
- positions: (_b = next.positions) == null ? void 0 : _b.map((item) => item.clone()),
117
- derivative: previous.derivative
118
- };
119
- }
120
- return {
121
- time,
122
- positions: (_c = next.positions) == null ? void 0 : _c.map((right, index) => {
123
- var _a2;
124
- const left = (_a2 = previous.positions) == null ? void 0 : _a2[index];
125
- return !left ? right : Cartesian3.lerp(left, right, proportion, new Cartesian3());
126
- }),
127
- derivative: previous.derivative
128
- };
112
+ if (proportion === 0) return {
113
+ time,
114
+ positions: previous.positions?.map((item) => item.clone()),
115
+ derivative: previous.derivative
116
+ };
117
+ else if (proportion === 1) return {
118
+ time,
119
+ positions: next.positions?.map((item) => item.clone()),
120
+ derivative: previous.derivative
121
+ };
122
+ return {
123
+ time,
124
+ positions: next.positions?.map((right, index) => {
125
+ const left = previous.positions?.[index];
126
+ return !left ? right : Cartesian3.lerp(left, right, proportion, new Cartesian3());
127
+ }),
128
+ derivative: previous.derivative
129
+ };
129
130
  };
130
- const _SampledPlotProperty = class _SampledPlotProperty {
131
- constructor(options) {
132
- __publicField(this, "strategy");
133
- __publicField(this, "interpolationAlgorithm");
134
- /**
135
- * @internal
136
- */
137
- __publicField(this, "_times", []);
138
- /**
139
- * @internal
140
- */
141
- __publicField(this, "_sampleds", []);
142
- /**
143
- * @internal
144
- */
145
- __publicField(this, "_derivatives", []);
146
- /**
147
- * @internal
148
- */
149
- __publicField(this, "_definitionChanged", new Event());
150
- var _a;
151
- this.interpolationAlgorithm = options == null ? void 0 : options.interpolationAlgorithm;
152
- this.strategy = (options == null ? void 0 : options.strategy) ?? 0;
153
- (_a = options == null ? void 0 : options.packables) == null ? void 0 : _a.forEach((packable) => this.setSample(packable));
154
- if (!this._times.length) {
155
- this.setSample({
156
- time: new JulianDate(0, 0),
157
- positions: [],
158
- derivative: void 0
159
- });
160
- }
161
- }
162
- get isConstant() {
163
- return this._times.length === 0;
164
- }
165
- get definitionChanged() {
166
- return this._definitionChanged;
167
- }
168
- /**
169
- * 获取时间数组
170
- *
171
- * @returns 返回包含所有时间的 JulianDate 数组
172
- */
173
- getTimes() {
174
- return this._times.map((t) => t.clone());
175
- }
176
- /**
177
- * 根据给定的儒略日期获取时间索引范围及比例
178
- *
179
- * @param time 给定的儒略日期
180
- * @returns 返回包含前一个索引、后一个索引及时间比例的对象,若不符合条件则返回undefined
181
- * @internal
182
- */
183
- getIndexScope(time) {
184
- if (!this._times.length) {
185
- return;
186
- }
187
- const start = this._times[0];
188
- const end = this._times[this._times.length - 1];
189
- if (JulianDate.lessThan(time, start) || JulianDate.greaterThan(time, end)) {
190
- switch (this.strategy) {
191
- case 2: {
192
- return;
193
- }
194
- case 0: {
195
- time = JulianDate.lessThan(time, this._times[0]) ? this._times[0].clone() : this._times[this._times.length - 1].clone();
196
- break;
197
- }
198
- case 1: {
199
- const startMS = JulianDate.toDate(this._times[0]).getTime();
200
- const endMS = JulianDate.toDate(this._times[this._times.length - 1]).getTime();
201
- const duration = endMS - startMS;
202
- const timeMS = JulianDate.toDate(time).getTime();
203
- const diff = (timeMS - startMS) % duration;
204
- const dete = new Date(startMS + diff);
205
- time = JulianDate.fromDate(dete);
206
- break;
207
- }
208
- }
209
- }
210
- const prevIndex = this._times.findIndex((t) => JulianDate.lessThanOrEquals(time, t));
211
- const nextIndex = Math.min(prevIndex, this._times.length - 1);
212
- const prevMs = JulianDate.toDate(this._times[prevIndex]).getTime();
213
- const nextMs = JulianDate.toDate(this._times[nextIndex]).getTime();
214
- const ms = JulianDate.toDate(time).getTime();
215
- return {
216
- prevIndex,
217
- nextIndex,
218
- proportion: (ms - prevMs) / (nextMs - prevMs) || 0
219
- };
220
- }
221
- /**
222
- * 根据给定的儒略日期(JulianDate)获取插值后的样本点数据。
223
- *
224
- * @param time 指定的儒略日期(JulianDate)。
225
- * @param result 可选参数,用于存储结果的容器。如果未提供,则创建一个新的容器。
226
- * @returns 插值后的样本点数据,存储在提供的或新创建的result容器中。
227
- * @template D 数据类型。
228
- */
229
- getValue(time, result) {
230
- var _a;
231
- result ?? (result = { time });
232
- Object.assign(result, {
233
- time: time == null ? void 0 : time.clone(),
234
- positions: void 0,
235
- derivative: void 0
236
- });
237
- if (!time) {
238
- result.time = this._times[0].clone();
239
- result.positions = (_a = this._sampleds[0]) == null ? void 0 : _a.map((c) => c.clone(c));
240
- result.derivative = this._derivatives[0];
241
- return result;
242
- }
243
- const scope = this.getIndexScope(time);
244
- if (!scope) {
245
- return result;
246
- }
247
- result.time = time;
248
- const { prevIndex, nextIndex, proportion } = scope;
249
- const previous = {
250
- time: this._times[prevIndex],
251
- positions: this._sampleds[prevIndex],
252
- derivative: this._derivatives[prevIndex]
253
- };
254
- const next = {
255
- time: this._times[nextIndex],
256
- positions: this._sampleds[nextIndex],
257
- derivative: this._derivatives[nextIndex]
258
- };
259
- const packable = (this.interpolationAlgorithm || _SampledPlotProperty.defaultInterpolationAlgorithm)(time, previous, next, proportion);
260
- Object.assign(result, packable);
261
- return result;
262
- }
263
- /**
264
- * 设置样本数据,如果传入的数据不含时间,则会存入时间最早的集合中
265
- * @param value 样本数据对象,包含时间、位置和导数信息
266
- */
267
- setSample(value) {
268
- var _a, _b;
269
- const time = ((_a = value.time) == null ? void 0 : _a.clone()) ?? this._times[0].clone();
270
- const positions = ((_b = value.positions) == null ? void 0 : _b.map((item) => item.clone())) ?? [];
271
- const derivative = value.derivative;
272
- const index = this._times.findIndex((t) => JulianDate.equals(time, t));
273
- if (index !== -1) {
274
- this._times[index] = time;
275
- this._sampleds[index] = positions;
276
- this._derivatives[index] = value.derivative;
277
- } else if (this._times.length === 0) {
278
- this._times[0] = time;
279
- this._sampleds[0] = positions;
280
- this._derivatives[0] = value.derivative;
281
- } else if (JulianDate.lessThan(time, this._times[0])) {
282
- this._times.splice(0, 0, time);
283
- this._sampleds.splice(0, 0, positions);
284
- this._derivatives.splice(0, 0, derivative);
285
- } else if (JulianDate.greaterThan(time, this._times[this._times.length - 1])) {
286
- this._times.push(time);
287
- this._sampleds.push(positions);
288
- this._derivatives.push(derivative);
289
- }
290
- this.definitionChanged.raiseEvent(this);
291
- }
292
- /**
293
- * 设置样本数据
294
- *
295
- * @param values 样本数据数组,每个元素都是类型为SampledPlotPackable<D>的对象
296
- */
297
- setSamples(values) {
298
- values.forEach((value) => this.setSample(value));
299
- }
300
- /**
301
- * 从样本中移除指定时间点的数据
302
- *
303
- * @param time 需要移除的时间点,使用儒略日期表示
304
- * @returns 如果成功移除,则返回 true;否则返回 false
305
- */
306
- removeSample(time) {
307
- const index = this._times.findIndex((t) => t.equals(time));
308
- if (index !== -1) {
309
- this._sampleds.splice(index, 1);
310
- this._derivatives.splice(index, 1);
311
- const removed = this._times.splice(index, 1);
312
- if (removed.length) {
313
- this._definitionChanged.raiseEvent(this);
314
- return true;
315
- }
316
- }
317
- return false;
318
- }
319
- /**
320
- * 从样本中移除指定时间间隔内的样本。
321
- *
322
- * @param interval 要移除样本的时间间隔
323
- */
324
- removeSamples(interval2) {
325
- for (let i = 0; i < this._times.length; i++) {
326
- const time = this._times[i];
327
- TimeInterval.contains(interval2, time) && this.removeSample(time);
328
- }
329
- }
330
- /**
331
- * 判断两个property是否相等
332
- */
333
- equals(other) {
334
- return other === this;
335
- }
131
+ /**
132
+ * 标绘采样点数据。
133
+ * 标绘采样点数据是一个时间序列数据,包含时间、位置和附带的额外数据。
134
+ * 具体用法可参考 [Cesium.SampledProperty](https://cesium.com/learn/cesiumjs/ref-doc/SampledProperty.html)
135
+ */
136
+ var SampledPlotProperty = class SampledPlotProperty {
137
+ constructor(options) {
138
+ this.interpolationAlgorithm = options?.interpolationAlgorithm;
139
+ this.strategy = options?.strategy ?? SampledPlotStrategy.NEAR;
140
+ options?.packables?.forEach((packable) => this.setSample(packable));
141
+ if (!this._times.length) this.setSample({
142
+ time: new JulianDate(0, 0),
143
+ positions: [],
144
+ derivative: void 0
145
+ });
146
+ }
147
+ static defaultInterpolationAlgorithm = defaultInterpolationAlgorithm;
148
+ strategy;
149
+ interpolationAlgorithm;
150
+ /**
151
+ * @internal
152
+ */
153
+ _times = [];
154
+ /**
155
+ * @internal
156
+ */
157
+ _sampleds = [];
158
+ /**
159
+ * @internal
160
+ */
161
+ _derivatives = [];
162
+ get isConstant() {
163
+ return this._times.length === 0;
164
+ }
165
+ /**
166
+ * @internal
167
+ */
168
+ _definitionChanged = new Event();
169
+ get definitionChanged() {
170
+ return this._definitionChanged;
171
+ }
172
+ /**
173
+ * 获取时间数组
174
+ *
175
+ * @returns 返回包含所有时间的 JulianDate 数组
176
+ */
177
+ getTimes() {
178
+ return this._times.map((t) => t.clone());
179
+ }
180
+ /**
181
+ * 根据给定的儒略日期获取时间索引范围及比例
182
+ *
183
+ * @param time 给定的儒略日期
184
+ * @returns 返回包含前一个索引、后一个索引及时间比例的对象,若不符合条件则返回undefined
185
+ * @internal
186
+ */
187
+ getIndexScope(time) {
188
+ if (!this._times.length) return;
189
+ const start = this._times[0];
190
+ const end = this._times[this._times.length - 1];
191
+ if (JulianDate.lessThan(time, start) || JulianDate.greaterThan(time, end)) switch (this.strategy) {
192
+ case SampledPlotStrategy.STRICT: return;
193
+ case SampledPlotStrategy.NEAR: {
194
+ time = JulianDate.lessThan(time, this._times[0]) ? this._times[0].clone() : this._times[this._times.length - 1].clone();
195
+ break;
196
+ }
197
+ case SampledPlotStrategy.CYCLE: {
198
+ const startMS = JulianDate.toDate(this._times[0]).getTime();
199
+ const endMS = JulianDate.toDate(this._times[this._times.length - 1]).getTime();
200
+ const duration = endMS - startMS;
201
+ const timeMS = JulianDate.toDate(time).getTime();
202
+ const diff = (timeMS - startMS) % duration;
203
+ const dete = new Date(startMS + diff);
204
+ time = JulianDate.fromDate(dete);
205
+ break;
206
+ }
207
+ }
208
+ const prevIndex = this._times.findIndex((t) => JulianDate.lessThanOrEquals(time, t));
209
+ const nextIndex = Math.min(prevIndex, this._times.length - 1);
210
+ const prevMs = JulianDate.toDate(this._times[prevIndex]).getTime();
211
+ const nextMs = JulianDate.toDate(this._times[nextIndex]).getTime();
212
+ const ms = JulianDate.toDate(time).getTime();
213
+ return {
214
+ prevIndex,
215
+ nextIndex,
216
+ proportion: (ms - prevMs) / (nextMs - prevMs) || 0
217
+ };
218
+ }
219
+ /**
220
+ * 根据给定的儒略日期(JulianDate)获取插值后的样本点数据。
221
+ *
222
+ * @param time 指定的儒略日期(JulianDate)。
223
+ * @param result 可选参数,用于存储结果的容器。如果未提供,则创建一个新的容器。
224
+ * @returns 插值后的样本点数据,存储在提供的或新创建的result容器中。
225
+ * @template D 数据类型。
226
+ */
227
+ getValue(time, result) {
228
+ result ??= { time };
229
+ Object.assign(result, {
230
+ time: time?.clone(),
231
+ positions: void 0,
232
+ derivative: void 0
233
+ });
234
+ if (!time) {
235
+ result.time = this._times[0].clone();
236
+ result.positions = this._sampleds[0]?.map((c) => c.clone(c));
237
+ result.derivative = this._derivatives[0];
238
+ return result;
239
+ }
240
+ const scope = this.getIndexScope(time);
241
+ if (!scope) return result;
242
+ result.time = time;
243
+ const { prevIndex, nextIndex, proportion } = scope;
244
+ const previous = {
245
+ time: this._times[prevIndex],
246
+ positions: this._sampleds[prevIndex],
247
+ derivative: this._derivatives[prevIndex]
248
+ };
249
+ const next = {
250
+ time: this._times[nextIndex],
251
+ positions: this._sampleds[nextIndex],
252
+ derivative: this._derivatives[nextIndex]
253
+ };
254
+ const packable = (this.interpolationAlgorithm || SampledPlotProperty.defaultInterpolationAlgorithm)(time, previous, next, proportion);
255
+ Object.assign(result, packable);
256
+ return result;
257
+ }
258
+ /**
259
+ * 设置样本数据,如果传入的数据不含时间,则会存入时间最早的集合中
260
+ * @param value 样本数据对象,包含时间、位置和导数信息
261
+ */
262
+ setSample(value) {
263
+ const time = value.time?.clone() ?? this._times[0].clone();
264
+ const positions = value.positions?.map((item) => item.clone()) ?? [];
265
+ const derivative = value.derivative;
266
+ const index = this._times.findIndex((t) => JulianDate.equals(time, t));
267
+ if (index !== -1) {
268
+ this._times[index] = time;
269
+ this._sampleds[index] = positions;
270
+ this._derivatives[index] = value.derivative;
271
+ } else if (this._times.length === 0) {
272
+ this._times[0] = time;
273
+ this._sampleds[0] = positions;
274
+ this._derivatives[0] = value.derivative;
275
+ } else if (JulianDate.lessThan(time, this._times[0])) {
276
+ this._times.splice(0, 0, time);
277
+ this._sampleds.splice(0, 0, positions);
278
+ this._derivatives.splice(0, 0, derivative);
279
+ } else if (JulianDate.greaterThan(time, this._times[this._times.length - 1])) {
280
+ this._times.push(time);
281
+ this._sampleds.push(positions);
282
+ this._derivatives.push(derivative);
283
+ }
284
+ this.definitionChanged.raiseEvent(this);
285
+ }
286
+ /**
287
+ * 设置样本数据
288
+ *
289
+ * @param values 样本数据数组,每个元素都是类型为SampledPlotPackable<D>的对象
290
+ */
291
+ setSamples(values) {
292
+ values.forEach((value) => this.setSample(value));
293
+ }
294
+ /**
295
+ * 从样本中移除指定时间点的数据
296
+ *
297
+ * @param time 需要移除的时间点,使用儒略日期表示
298
+ * @returns 如果成功移除,则返回 true;否则返回 false
299
+ */
300
+ removeSample(time) {
301
+ const index = this._times.findIndex((t) => t.equals(time));
302
+ if (index !== -1) {
303
+ this._sampleds.splice(index, 1);
304
+ this._derivatives.splice(index, 1);
305
+ const removed = this._times.splice(index, 1);
306
+ if (removed.length) {
307
+ this._definitionChanged.raiseEvent(this);
308
+ return true;
309
+ }
310
+ }
311
+ return false;
312
+ }
313
+ /**
314
+ * 从样本中移除指定时间间隔内的样本。
315
+ *
316
+ * @param interval 要移除样本的时间间隔
317
+ */
318
+ removeSamples(interval$1) {
319
+ for (let i = 0; i < this._times.length; i++) {
320
+ const time = this._times[i];
321
+ TimeInterval.contains(interval$1, time) && this.removeSample(time);
322
+ }
323
+ }
324
+ /**
325
+ * 判断两个property是否相等
326
+ */
327
+ equals(other) {
328
+ return other === this;
329
+ }
336
330
  };
337
- __publicField(_SampledPlotProperty, "defaultInterpolationAlgorithm", defaultInterpolationAlgorithm);
338
- let SampledPlotProperty = _SampledPlotProperty;
339
- class PlotFeature {
340
- constructor(options) {
341
- /**
342
- * @internal
343
- */
344
- __publicField(this, "_id");
345
- /**
346
- * @internal
347
- */
348
- __publicField(this, "_scheme");
349
- /**
350
- * @internal
351
- */
352
- __publicField(this, "_definitionChanged");
353
- /**
354
- * @internal
355
- */
356
- __publicField(this, "_defining");
357
- /**
358
- * @internal
359
- */
360
- __publicField(this, "_disabled");
361
- /**
362
- * @internal
363
- */
364
- __publicField(this, "_sampled");
365
- /**
366
- * @internal
367
- */
368
- __publicField(this, "_entities");
369
- /**
370
- * @internal
371
- */
372
- __publicField(this, "_primitives");
373
- /**
374
- * @internal
375
- */
376
- __publicField(this, "_groundPrimitives");
377
- /**
378
- * @internal
379
- */
380
- __publicField(this, "_skeletons");
381
- var _a, _b, _c, _d, _e, _f;
382
- const { id, disabled = false, sampled } = options;
383
- this._id = id || createGuid();
384
- this._scheme = PlotScheme.resolve(options.scheme);
385
- this._definitionChanged = new Event();
386
- this._defining = true;
387
- this._disabled = disabled;
388
- this._sampled = sampled instanceof SampledPlotProperty ? sampled : new SampledPlotProperty(sampled);
389
- this._sampled.definitionChanged.addEventListener((property) => this._definitionChanged.raiseEvent(this, "sampled", property, property), this);
390
- this._entities = [...((_b = (_a = this._scheme).initEntites) == null ? void 0 : _b.call(_a)) ?? []];
391
- this._primitives = [...((_d = (_c = this._scheme).initPrimitives) == null ? void 0 : _d.call(_c)) ?? []];
392
- this._groundPrimitives = [...((_f = (_e = this._scheme).initGroundPrimitives) == null ? void 0 : _f.call(_e)) ?? []];
393
- this._skeletons = [];
394
- }
395
- get id() {
396
- return this._id;
397
- }
398
- get scheme() {
399
- return this._scheme;
400
- }
401
- get definitionChanged() {
402
- return this._definitionChanged;
403
- }
404
- get defining() {
405
- return this._defining;
406
- }
407
- /**
408
- * @internal
409
- */
410
- static setDefining(plot, value) {
411
- if (plot._defining !== value) {
412
- plot._definitionChanged.raiseEvent(plot, "defining", value, plot._defining);
413
- plot._defining = value;
414
- }
415
- }
416
- /**
417
- * 获取禁用状态
418
- *
419
- * 当为 `true` 时,标绘实例将停止响应交互和更新;
420
- * 为 `false` 时恢复正常功能。
421
- */
422
- get disabled() {
423
- return this._disabled;
424
- }
425
- set disabled(value) {
426
- this.disabled = value;
427
- }
428
- get sampled() {
429
- return this._sampled;
430
- }
431
- get entities() {
432
- return this._entities;
433
- }
434
- set entities(value) {
435
- this._definitionChanged.raiseEvent(this, "entities", value, this._entities);
436
- this._entities = value;
437
- }
438
- get primitives() {
439
- return this._primitives;
440
- }
441
- /**
442
- * @internal
443
- */
444
- set primitives(value) {
445
- this._definitionChanged.raiseEvent(this, "primitives", value, this._primitives);
446
- this._primitives = value;
447
- }
448
- get groundPrimitives() {
449
- return this._groundPrimitives;
450
- }
451
- /**
452
- * @internal
453
- */
454
- set groundPrimitives(value) {
455
- this._definitionChanged.raiseEvent(this, "groundPrimitives", value, this._groundPrimitives);
456
- this._groundPrimitives = value;
457
- }
458
- get skeletons() {
459
- return this._skeletons;
460
- }
461
- /**
462
- * @internal
463
- */
464
- set skeletons(value) {
465
- this._definitionChanged.raiseEvent(this, "skeletons", value, this._skeletons);
466
- this._skeletons = value;
467
- }
468
- }
469
- var PlotAction = /* @__PURE__ */ ((PlotAction2) => {
470
- PlotAction2[PlotAction2["IDLE"] = 0] = "IDLE";
471
- PlotAction2[PlotAction2["HOVER"] = 1] = "HOVER";
472
- PlotAction2[PlotAction2["ACTIVE"] = 2] = "ACTIVE";
473
- return PlotAction2;
474
- })(PlotAction || {});
475
- class PlotSkeletonEntity extends Entity {
476
- constructor(options) {
477
- super(options);
478
- }
479
- }
331
+
332
+ //#endregion
333
+ //#region usePlot/PlotFeature.ts
334
+ /**
335
+ * 标绘实例
336
+ */
337
+ var PlotFeature = class {
338
+ constructor(options) {
339
+ const { id, disabled = false, sampled } = options;
340
+ this._id = id || createGuid();
341
+ this._scheme = PlotScheme.resolve(options.scheme);
342
+ this._definitionChanged = new Event();
343
+ this._defining = true;
344
+ this._disabled = disabled;
345
+ this._sampled = sampled instanceof SampledPlotProperty ? sampled : new SampledPlotProperty(sampled);
346
+ this._sampled.definitionChanged.addEventListener((property) => this._definitionChanged.raiseEvent(this, "sampled", property, property), this);
347
+ this._entities = [...this._scheme.initEntites?.() ?? []];
348
+ this._primitives = [...this._scheme.initPrimitives?.() ?? []];
349
+ this._groundPrimitives = [...this._scheme.initGroundPrimitives?.() ?? []];
350
+ this._skeletons = [];
351
+ }
352
+ /**
353
+ * @internal
354
+ */
355
+ _id;
356
+ get id() {
357
+ return this._id;
358
+ }
359
+ /**
360
+ * @internal
361
+ */
362
+ _scheme;
363
+ get scheme() {
364
+ return this._scheme;
365
+ }
366
+ /**
367
+ * @internal
368
+ */
369
+ _definitionChanged;
370
+ get definitionChanged() {
371
+ return this._definitionChanged;
372
+ }
373
+ /**
374
+ * @internal
375
+ */
376
+ _defining;
377
+ get defining() {
378
+ return this._defining;
379
+ }
380
+ /**
381
+ * @internal
382
+ */
383
+ static setDefining(plot, value) {
384
+ if (plot._defining !== value) {
385
+ plot._definitionChanged.raiseEvent(plot, "defining", value, plot._defining);
386
+ plot._defining = value;
387
+ }
388
+ }
389
+ /**
390
+ * @internal
391
+ */
392
+ _disabled;
393
+ /**
394
+ * 获取禁用状态
395
+ *
396
+ * 当为 `true` 时,标绘实例将停止响应交互和更新;
397
+ * 为 `false` 时恢复正常功能。
398
+ */
399
+ get disabled() {
400
+ return this._disabled;
401
+ }
402
+ set disabled(value) {
403
+ this.disabled = value;
404
+ }
405
+ /**
406
+ * @internal
407
+ */
408
+ _sampled;
409
+ get sampled() {
410
+ return this._sampled;
411
+ }
412
+ /**
413
+ * @internal
414
+ */
415
+ _entities;
416
+ get entities() {
417
+ return this._entities;
418
+ }
419
+ set entities(value) {
420
+ this._definitionChanged.raiseEvent(this, "entities", value, this._entities);
421
+ this._entities = value;
422
+ }
423
+ /**
424
+ * @internal
425
+ */
426
+ _primitives;
427
+ get primitives() {
428
+ return this._primitives;
429
+ }
430
+ /**
431
+ * @internal
432
+ */
433
+ set primitives(value) {
434
+ this._definitionChanged.raiseEvent(this, "primitives", value, this._primitives);
435
+ this._primitives = value;
436
+ }
437
+ /**
438
+ * @internal
439
+ */
440
+ _groundPrimitives;
441
+ get groundPrimitives() {
442
+ return this._groundPrimitives;
443
+ }
444
+ /**
445
+ * @internal
446
+ */
447
+ set groundPrimitives(value) {
448
+ this._definitionChanged.raiseEvent(this, "groundPrimitives", value, this._groundPrimitives);
449
+ this._groundPrimitives = value;
450
+ }
451
+ /**
452
+ * @internal
453
+ */
454
+ _skeletons;
455
+ get skeletons() {
456
+ return this._skeletons;
457
+ }
458
+ /**
459
+ * @internal
460
+ */
461
+ set skeletons(value) {
462
+ this._definitionChanged.raiseEvent(this, "skeletons", value, this._skeletons);
463
+ this._skeletons = value;
464
+ }
465
+ };
466
+
467
+ //#endregion
468
+ //#region usePlot/PlotSkeleton.ts
469
+ /**
470
+ * 框架点执行状态枚举
471
+ * - IDLE 空闲状态
472
+ * - HOVER 悬停状态
473
+ * - ACTIVE 激活状态
474
+ */
475
+ let PlotAction = /* @__PURE__ */ function(PlotAction$1) {
476
+ PlotAction$1[PlotAction$1["IDLE"] = 0] = "IDLE";
477
+ PlotAction$1[PlotAction$1["HOVER"] = 1] = "HOVER";
478
+ PlotAction$1[PlotAction$1["ACTIVE"] = 2] = "ACTIVE";
479
+ return PlotAction$1;
480
+ }({});
481
+ /**
482
+ * 标绘框架点 Entity
483
+ */
484
+ var PlotSkeletonEntity = class extends Entity {
485
+ constructor(options) {
486
+ super(options);
487
+ }
488
+ };
489
+
490
+ //#endregion
491
+ //#region usePlot/useRender.ts
480
492
  function useRender(plots, current, getCurrentTime) {
481
- const viewer = useViewer();
482
- const primitiveCollection = usePrimitive(new PrimitiveCollection());
483
- const groundPrimitiveCollection = usePrimitive(new PrimitiveCollection(), { collection: "ground" });
484
- const dataSource = useDataSource(new CustomDataSource());
485
- const entityScope = useEntityScope({ collection: () => dataSource.value.entities });
486
- const primitiveScope = usePrimitiveScope({ collection: () => primitiveCollection.value });
487
- const groundPrimitiveScope = usePrimitiveScope({ collection: () => groundPrimitiveCollection.value });
488
- const mouseCartesian = shallowRef();
489
- useScreenSpaceEventHandler(
490
- ScreenSpaceEventType.MOUSE_MOVE,
491
- (event) => {
492
- mouseCartesian.value = canvasCoordToCartesian(event == null ? void 0 : event.endPosition, viewer.value.scene);
493
- }
494
- );
495
- watchArray(plots, (_value, _oldValue, added, removed = []) => {
496
- removed.forEach((plot) => {
497
- entityScope.removeWhere((item) => plot.entities.includes(item));
498
- primitiveScope.removeWhere((item) => plot.primitives.includes(item));
499
- groundPrimitiveScope.removeWhere((item) => plot.groundPrimitives.includes(item));
500
- });
501
- added.forEach((plot) => {
502
- plot.entities.forEach((item) => entityScope.add(item));
503
- plot.primitives.forEach((item) => primitiveScope.add(item));
504
- plot.groundPrimitives.forEach((item) => groundPrimitiveScope.add(item));
505
- });
506
- }, {
507
- immediate: true,
508
- flush: "post"
509
- });
510
- useCesiumEventListener(
511
- () => plots.value.map((item) => item.definitionChanged),
512
- (_scope, key, newValue, oldValue) => {
513
- if (key === "entities") {
514
- const { added, removed } = arrayDiff(newValue, oldValue);
515
- added.forEach((item) => entityScope.add(item));
516
- removed.forEach((item) => entityScope.remove(item));
517
- } else if (key === "primitives") {
518
- const { added, removed } = arrayDiff(newValue, oldValue);
519
- added.forEach((item) => primitiveScope.add(item));
520
- removed.forEach((item) => primitiveScope.remove(item));
521
- } else if (key === "groundPrimitives") {
522
- const { added, removed } = arrayDiff(newValue, oldValue);
523
- added.forEach((item) => groundPrimitiveScope.add(item));
524
- removed.forEach((item) => groundPrimitiveScope.remove(item));
525
- }
526
- }
527
- );
528
- const update = async (plot) => {
529
- var _a, _b;
530
- const reslut = await ((_b = (_a = plot.scheme).render) == null ? void 0 : _b.call(_a, {
531
- packable: plot.sampled.getValue(getCurrentTime()),
532
- mouse: plot.defining ? mouseCartesian.value : void 0,
533
- defining: plot.defining,
534
- previous: {
535
- entities: plot.entities,
536
- primitives: plot.primitives,
537
- groundPrimitives: plot.groundPrimitives
538
- }
539
- }));
540
- plot.entities = (reslut == null ? void 0 : reslut.entities) ?? [];
541
- plot.primitives = (reslut == null ? void 0 : reslut.primitives) ?? [];
542
- plot.groundPrimitives = (reslut == null ? void 0 : reslut.groundPrimitives) ?? [];
543
- };
544
- watch(current, (plot, previous) => {
545
- previous && update(previous);
546
- });
547
- useCesiumEventListener(
548
- () => plots.value.map((item) => item.definitionChanged),
549
- (plot, key) => {
550
- if (["disabled", "defining", "scheme", "sampled", "time"].includes(key)) {
551
- update(plot);
552
- }
553
- }
554
- );
555
- watch(mouseCartesian, () => {
556
- plots.value.forEach((plot) => plot.defining && update(plot));
557
- });
558
- return {
559
- primitives: computed(() => Array.from(primitiveScope.scope)),
560
- groundPrimitives: computed(() => Array.from(primitiveScope.scope)),
561
- entities: computed(() => Array.from(entityScope.scope))
562
- };
493
+ const viewer = useViewer();
494
+ const primitiveCollection = usePrimitive(new PrimitiveCollection());
495
+ const groundPrimitiveCollection = usePrimitive(new PrimitiveCollection(), { collection: "ground" });
496
+ const dataSource = useDataSource(new CustomDataSource());
497
+ const entityScope = useEntityScope({ collection: () => dataSource.value.entities });
498
+ const primitiveScope = usePrimitiveScope({ collection: () => primitiveCollection.value });
499
+ const groundPrimitiveScope = usePrimitiveScope({ collection: () => groundPrimitiveCollection.value });
500
+ const mouseCartesian = shallowRef();
501
+ useScreenSpaceEventHandler(ScreenSpaceEventType.MOUSE_MOVE, (event) => {
502
+ mouseCartesian.value = canvasCoordToCartesian(event?.endPosition, viewer.value.scene);
503
+ });
504
+ watchArray(plots, (_value, _oldValue, added, removed = []) => {
505
+ removed.forEach((plot) => {
506
+ entityScope.removeWhere((item) => plot.entities.includes(item));
507
+ primitiveScope.removeWhere((item) => plot.primitives.includes(item));
508
+ groundPrimitiveScope.removeWhere((item) => plot.groundPrimitives.includes(item));
509
+ });
510
+ added.forEach((plot) => {
511
+ plot.entities.forEach((item) => entityScope.add(item));
512
+ plot.primitives.forEach((item) => primitiveScope.add(item));
513
+ plot.groundPrimitives.forEach((item) => groundPrimitiveScope.add(item));
514
+ });
515
+ }, {
516
+ immediate: true,
517
+ flush: "post"
518
+ });
519
+ useCesiumEventListener(() => plots.value.map((item) => item.definitionChanged), (_scope, key, newValue, oldValue) => {
520
+ if (key === "entities") {
521
+ const { added, removed } = arrayDiff(newValue, oldValue);
522
+ added.forEach((item) => entityScope.add(item));
523
+ removed.forEach((item) => entityScope.remove(item));
524
+ } else if (key === "primitives") {
525
+ const { added, removed } = arrayDiff(newValue, oldValue);
526
+ added.forEach((item) => primitiveScope.add(item));
527
+ removed.forEach((item) => primitiveScope.remove(item));
528
+ } else if (key === "groundPrimitives") {
529
+ const { added, removed } = arrayDiff(newValue, oldValue);
530
+ added.forEach((item) => groundPrimitiveScope.add(item));
531
+ removed.forEach((item) => groundPrimitiveScope.remove(item));
532
+ }
533
+ });
534
+ const update = async (plot) => {
535
+ const reslut = await plot.scheme.render?.({
536
+ packable: plot.sampled.getValue(getCurrentTime()),
537
+ mouse: plot.defining ? mouseCartesian.value : void 0,
538
+ defining: plot.defining,
539
+ previous: {
540
+ entities: plot.entities,
541
+ primitives: plot.primitives,
542
+ groundPrimitives: plot.groundPrimitives
543
+ }
544
+ });
545
+ plot.entities = reslut?.entities ?? [];
546
+ plot.primitives = reslut?.primitives ?? [];
547
+ plot.groundPrimitives = reslut?.groundPrimitives ?? [];
548
+ };
549
+ watch(current, (plot, previous) => {
550
+ previous && update(previous);
551
+ });
552
+ useCesiumEventListener(() => plots.value.map((item) => item.definitionChanged), (plot, key) => {
553
+ if ([
554
+ "disabled",
555
+ "defining",
556
+ "scheme",
557
+ "sampled",
558
+ "time"
559
+ ].includes(key)) update(plot);
560
+ });
561
+ watch(mouseCartesian, () => {
562
+ plots.value.forEach((plot) => plot.defining && update(plot));
563
+ });
564
+ return {
565
+ primitives: computed(() => Array.from(primitiveScope.scope)),
566
+ groundPrimitives: computed(() => Array.from(primitiveScope.scope)),
567
+ entities: computed(() => Array.from(entityScope.scope))
568
+ };
563
569
  }
570
+
571
+ //#endregion
572
+ //#region usePlot/useSampled.ts
564
573
  function useSampled(current, getCurrentTime) {
565
- const viewer = useViewer();
566
- const doubleClicking = ref(false);
567
- const packable = computed(() => {
568
- var _a;
569
- return (_a = current.value) == null ? void 0 : _a.sampled.getValue(getCurrentTime());
570
- });
571
- useScreenSpaceEventHandler(
572
- ScreenSpaceEventType.LEFT_CLICK,
573
- async (ctx) => {
574
- var _a, _b;
575
- await promiseTimeout(1);
576
- if (!current.value || !packable.value) {
577
- return;
578
- }
579
- if (doubleClicking.value) {
580
- return;
581
- }
582
- const { scheme, defining, sampled } = current.value;
583
- if (!defining) {
584
- return;
585
- }
586
- const position = canvasCoordToCartesian(ctx.position, viewer.value.scene);
587
- if (!position) {
588
- return;
589
- }
590
- (_a = packable.value).positions ?? (_a.positions = []);
591
- packable.value.positions.push(position);
592
- sampled.setSample(packable.value);
593
- const completed = (_b = scheme.complete) == null ? void 0 : _b.call(scheme, packable.value);
594
- completed && PlotFeature.setDefining(current.value, false);
595
- }
596
- );
597
- useScreenSpaceEventHandler(
598
- ScreenSpaceEventType.LEFT_DOUBLE_CLICK,
599
- async (ctx) => {
600
- var _a;
601
- if (!current.value || !packable.value) {
602
- return;
603
- }
604
- doubleClicking.value = true;
605
- await promiseTimeout(2);
606
- doubleClicking.value = false;
607
- const { scheme, defining } = current.value;
608
- if (!defining) {
609
- return;
610
- }
611
- const position = canvasCoordToCartesian(ctx.position, viewer.value.scene);
612
- if (!position) {
613
- return;
614
- }
615
- const completed = (_a = scheme.allowManualComplete) == null ? void 0 : _a.call(scheme, packable.value);
616
- completed && PlotFeature.setDefining(current.value, false);
617
- }
618
- );
619
- useScreenSpaceEventHandler(
620
- ScreenSpaceEventType.RIGHT_CLICK,
621
- async () => {
622
- var _a;
623
- if (!current.value || !packable.value) {
624
- return;
625
- }
626
- const { defining, sampled } = current.value;
627
- if (!defining) {
628
- return;
629
- }
630
- (_a = packable.value).positions ?? (_a.positions = []);
631
- if (packable.value.positions.length === 0) {
632
- return;
633
- }
634
- packable.value.positions.splice(packable.value.positions.length - 1, 1);
635
- sampled.setSample(packable.value);
636
- }
637
- );
638
- const definingCursorCss = ref();
639
- const setDefiningCursorCss = () => {
640
- var _a, _b;
641
- if (!((_a = current.value) == null ? void 0 : _a.defining)) {
642
- if (definingCursorCss.value) {
643
- definingCursorCss.value = void 0;
644
- viewer.value.container.parentElement.style.removeProperty("cursor");
645
- }
646
- } else {
647
- const definingCursor = current.value.scheme.definingCursor;
648
- definingCursorCss.value = isFunction(definingCursor) ? definingCursor(packable.value) : definingCursor;
649
- if (definingCursorCss.value) {
650
- (_b = viewer.value) == null ? void 0 : _b.container.parentElement.style.setProperty("cursor", definingCursorCss.value);
651
- }
652
- }
653
- };
654
- useCesiumEventListener(() => {
655
- var _a;
656
- return (_a = current.value) == null ? void 0 : _a.definitionChanged;
657
- }, (plot, key) => {
658
- if (key === "defining" || key === "sampled") {
659
- setDefiningCursorCss();
660
- }
661
- });
662
- watch(current, () => setDefiningCursorCss());
574
+ const viewer = useViewer();
575
+ const doubleClicking = ref(false);
576
+ const packable = computed(() => {
577
+ return current.value?.sampled.getValue(getCurrentTime());
578
+ });
579
+ useScreenSpaceEventHandler(ScreenSpaceEventType.LEFT_CLICK, async (ctx) => {
580
+ await promiseTimeout(1);
581
+ if (!current.value || !packable.value) return;
582
+ if (doubleClicking.value) return;
583
+ const { scheme, defining, sampled } = current.value;
584
+ if (!defining) return;
585
+ const position = canvasCoordToCartesian(ctx.position, viewer.value.scene);
586
+ if (!position) return;
587
+ packable.value.positions ??= [];
588
+ packable.value.positions.push(position);
589
+ sampled.setSample(packable.value);
590
+ const completed = scheme.complete?.(packable.value);
591
+ completed && PlotFeature.setDefining(current.value, false);
592
+ });
593
+ useScreenSpaceEventHandler(ScreenSpaceEventType.LEFT_DOUBLE_CLICK, async (ctx) => {
594
+ if (!current.value || !packable.value) return;
595
+ doubleClicking.value = true;
596
+ await promiseTimeout(2);
597
+ doubleClicking.value = false;
598
+ const { scheme, defining } = current.value;
599
+ if (!defining) return;
600
+ const position = canvasCoordToCartesian(ctx.position, viewer.value.scene);
601
+ if (!position) return;
602
+ const completed = scheme.allowManualComplete?.(packable.value);
603
+ completed && PlotFeature.setDefining(current.value, false);
604
+ });
605
+ useScreenSpaceEventHandler(ScreenSpaceEventType.RIGHT_CLICK, async () => {
606
+ if (!current.value || !packable.value) return;
607
+ const { defining, sampled } = current.value;
608
+ if (!defining) return;
609
+ packable.value.positions ??= [];
610
+ if (packable.value.positions.length === 0) return;
611
+ packable.value.positions.splice(packable.value.positions.length - 1, 1);
612
+ sampled.setSample(packable.value);
613
+ });
614
+ const definingCursorCss = ref();
615
+ const setDefiningCursorCss = () => {
616
+ if (!current.value?.defining) {
617
+ if (definingCursorCss.value) {
618
+ definingCursorCss.value = void 0;
619
+ viewer.value.container.parentElement.style.removeProperty("cursor");
620
+ }
621
+ } else {
622
+ const definingCursor = current.value.scheme.definingCursor;
623
+ definingCursorCss.value = isFunction(definingCursor) ? definingCursor(packable.value) : definingCursor;
624
+ if (definingCursorCss.value) viewer.value?.container.parentElement.style.setProperty("cursor", definingCursorCss.value);
625
+ }
626
+ };
627
+ useCesiumEventListener(() => current.value?.definitionChanged, (plot, key) => {
628
+ if (key === "defining" || key === "sampled") setDefiningCursorCss();
629
+ });
630
+ watch(current, () => setDefiningCursorCss());
663
631
  }
632
+
633
+ //#endregion
634
+ //#region usePlot/useSkeleton.ts
664
635
  function useSkeleton(plots, current, getCurrentTime) {
665
- const viewer = useViewer();
666
- const dataSource = useDataSource(new CustomDataSource());
667
- const entityScope = useEntityScope({ collection: () => dataSource.value.entities });
668
- const hoverEntity = shallowRef();
669
- const activeEntity = shallowRef();
670
- const getPointAction = (entity) => {
671
- var _a, _b;
672
- if (!entity) {
673
- return PlotAction.IDLE;
674
- }
675
- return ((_a = activeEntity.value) == null ? void 0 : _a.id) === entity.id ? PlotAction.ACTIVE : ((_b = hoverEntity.value) == null ? void 0 : _b.id) === entity.id ? PlotAction.HOVER : PlotAction.IDLE;
676
- };
677
- const update = (plot, destroyed) => {
678
- const oldEntities = plot.skeletons;
679
- const entities = [];
680
- if (destroyed || plot.disabled) {
681
- plot.skeletons = [];
682
- } else {
683
- const packable = plot.sampled.getValue(getCurrentTime());
684
- const defining = plot.defining;
685
- const active = current.value === plot;
686
- const skeletons = plot.scheme.skeletons;
687
- skeletons.forEach((skeleton) => {
688
- var _a;
689
- const disabled = isFunction(skeleton.disabled) ? skeleton.disabled({ active, defining }) : skeleton.disabled;
690
- if (disabled) {
691
- return;
692
- }
693
- const positions = ((_a = skeleton.format) == null ? void 0 : _a.call(skeleton, packable)) ?? (packable == null ? void 0 : packable.positions) ?? [];
694
- positions.forEach((position, index) => {
695
- var _a2;
696
- let entity = oldEntities.find((item) => item.index === index && item.skeleton === skeleton);
697
- const options = (_a2 = skeleton.render) == null ? void 0 : _a2.call(skeleton, {
698
- defining,
699
- active,
700
- index,
701
- packable,
702
- positions,
703
- position,
704
- action: getPointAction(entity)
705
- });
706
- const merge = new PlotSkeletonEntity(options ?? {});
707
- if (entity) {
708
- merge.propertyNames.forEach((key) => {
709
- if (key !== "id") {
710
- entity[key] = merge[key];
711
- }
712
- });
713
- } else {
714
- entity = merge;
715
- }
716
- entity.plot = plot;
717
- entity.skeleton = skeleton;
718
- entity.index = index;
719
- entities.push(entity);
720
- });
721
- });
722
- }
723
- plot.skeletons = entities;
724
- };
725
- const { addGraphicEvent } = useGraphicEvent();
726
- watchEffect((onCleanup) => {
727
- const remove = addGraphicEvent("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
728
- var _a;
729
- if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
730
- const entity = pick.id;
731
- const plot = entity.plot;
732
- if (plot.defining) {
733
- return;
734
- }
735
- activeEntity.value = entity;
736
- const skeleton = entity.skeleton;
737
- const index = entity.index;
738
- const packable = plot.sampled.getValue(getCurrentTime());
739
- (_a = skeleton.onDrag) == null ? void 0 : _a.call(skeleton, {
740
- viewer: viewer.value,
741
- sampled: plot.sampled,
742
- packable,
743
- active: current.value === plot,
744
- index,
745
- event,
746
- dragging,
747
- lockCamera
748
- });
749
- } else {
750
- activeEntity.value = void 0;
751
- }
752
- }, {
753
- cursor: ({ pick }) => {
754
- var _a;
755
- if (!((_a = current.value) == null ? void 0 : _a.defining) && entityScope.scope.has(pick.id)) {
756
- const skeleton = pick.id.skeleton;
757
- return isFunction(skeleton == null ? void 0 : skeleton.cursor) ? skeleton.cursor(pick) : toValue(skeleton == null ? void 0 : skeleton.cursor);
758
- }
759
- },
760
- dragCursor: ({ pick }) => {
761
- var _a;
762
- if (!((_a = current.value) == null ? void 0 : _a.defining) && entityScope.scope.has(pick.id)) {
763
- const skeleton = pick.id.skeleton;
764
- return isFunction(skeleton == null ? void 0 : skeleton.dragCursor) ? skeleton.dragCursor(pick) : toValue(skeleton == null ? void 0 : skeleton.dragCursor);
765
- }
766
- }
767
- });
768
- onCleanup(remove);
769
- });
770
- onKeyStroke((keyEvent) => {
771
- var _a;
772
- if (activeEntity.value) {
773
- const entity = activeEntity.value;
774
- const plot = entity.plot;
775
- const skeleton = entity.skeleton;
776
- const index = entity.index;
777
- const packable = plot.sampled.getValue(getCurrentTime());
778
- (_a = skeleton.onKeyPressed) == null ? void 0 : _a.call(skeleton, {
779
- viewer: viewer.value,
780
- sampled: plot.sampled,
781
- packable,
782
- index,
783
- keyEvent
784
- });
785
- }
786
- });
787
- watchEffect((onCleanup) => {
788
- const remove = addGraphicEvent("global", "HOVER", ({ hovering, pick }) => {
789
- if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
790
- const entity = pick.id;
791
- hoverEntity.value = entity;
792
- } else {
793
- hoverEntity.value = void 0;
794
- }
795
- });
796
- onCleanup(remove);
797
- });
798
- watchEffect((onCleanup) => {
799
- const remove = addGraphicEvent("global", "LEFT_CLICK", ({ event, pick }) => {
800
- var _a;
801
- if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
802
- const entity = pick.id;
803
- activeEntity.value = entity;
804
- const plot = entity.plot;
805
- const skeleton = entity.skeleton;
806
- const index = entity.index;
807
- const packable = plot.sampled.getValue(getCurrentTime());
808
- (_a = skeleton.onLeftClick) == null ? void 0 : _a.call(skeleton, {
809
- viewer: viewer.value,
810
- sampled: plot.sampled,
811
- packable,
812
- active: current.value === plot,
813
- defining: plot.defining,
814
- index,
815
- event
816
- });
817
- } else {
818
- activeEntity.value = void 0;
819
- }
820
- });
821
- onCleanup(remove);
822
- });
823
- watchArray(plots, (value, oldValue, added, removed = []) => {
824
- added.forEach((plot) => update(plot));
825
- removed.forEach((plot) => update(plot, true));
826
- });
827
- useCesiumEventListener(
828
- () => plots.value.map((plot) => plot.definitionChanged),
829
- (plot, key, newValue, oldValue) => {
830
- if (["disabled", "defining", "scheme", "sampled", "time"].includes(key)) {
831
- nextTick(() => update(plot));
832
- } else if (key === "skeletons") {
833
- const { added, removed } = arrayDiff(newValue, oldValue);
834
- added.forEach((item) => entityScope.add(item));
835
- removed.forEach((item) => entityScope.remove(item));
836
- }
837
- }
838
- );
839
- watch(current, (plot, previous) => {
840
- plot && update(plot);
841
- previous && update(previous);
842
- });
843
- return {
844
- dataSource
845
- };
636
+ const viewer = useViewer();
637
+ const dataSource = useDataSource(new CustomDataSource());
638
+ const entityScope = useEntityScope({ collection: () => dataSource.value.entities });
639
+ const hoverEntity = shallowRef();
640
+ const activeEntity = shallowRef();
641
+ const getPointAction = (entity) => {
642
+ if (!entity) return PlotAction.IDLE;
643
+ return activeEntity.value?.id === entity.id ? PlotAction.ACTIVE : hoverEntity.value?.id === entity.id ? PlotAction.HOVER : PlotAction.IDLE;
644
+ };
645
+ const update = (plot, destroyed) => {
646
+ const oldEntities = plot.skeletons;
647
+ const entities = [];
648
+ if (destroyed || plot.disabled) plot.skeletons = [];
649
+ else {
650
+ const packable = plot.sampled.getValue(getCurrentTime());
651
+ const defining = plot.defining;
652
+ const active = current.value === plot;
653
+ const skeletons = plot.scheme.skeletons;
654
+ skeletons.forEach((skeleton) => {
655
+ const disabled = isFunction(skeleton.disabled) ? skeleton.disabled({
656
+ active,
657
+ defining
658
+ }) : skeleton.disabled;
659
+ if (disabled) return;
660
+ const positions = skeleton.format?.(packable) ?? packable?.positions ?? [];
661
+ positions.forEach((position, index) => {
662
+ let entity = oldEntities.find((item) => item.index === index && item.skeleton === skeleton);
663
+ const options = skeleton.render?.({
664
+ defining,
665
+ active,
666
+ index,
667
+ packable,
668
+ positions,
669
+ position,
670
+ action: getPointAction(entity)
671
+ });
672
+ const merge = new PlotSkeletonEntity(options ?? {});
673
+ if (entity) merge.propertyNames.forEach((key) => {
674
+ if (key !== "id") entity[key] = merge[key];
675
+ });
676
+ else entity = merge;
677
+ entity.plot = plot;
678
+ entity.skeleton = skeleton;
679
+ entity.index = index;
680
+ entities.push(entity);
681
+ });
682
+ });
683
+ }
684
+ plot.skeletons = entities;
685
+ };
686
+ const { addGraphicEvent } = useGraphicEvent();
687
+ watchEffect((onCleanup) => {
688
+ const remove = addGraphicEvent("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
689
+ if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
690
+ const entity = pick.id;
691
+ const plot = entity.plot;
692
+ if (plot.defining) return;
693
+ activeEntity.value = entity;
694
+ const skeleton = entity.skeleton;
695
+ const index = entity.index;
696
+ const packable = plot.sampled.getValue(getCurrentTime());
697
+ skeleton.onDrag?.({
698
+ viewer: viewer.value,
699
+ sampled: plot.sampled,
700
+ packable,
701
+ active: current.value === plot,
702
+ index,
703
+ event,
704
+ dragging,
705
+ lockCamera
706
+ });
707
+ } else activeEntity.value = void 0;
708
+ }, {
709
+ cursor: ({ pick }) => {
710
+ if (!current.value?.defining && entityScope.scope.has(pick.id)) {
711
+ const skeleton = pick.id.skeleton;
712
+ return isFunction(skeleton?.cursor) ? skeleton.cursor(pick) : toValue(skeleton?.cursor);
713
+ }
714
+ },
715
+ dragCursor: ({ pick }) => {
716
+ if (!current.value?.defining && entityScope.scope.has(pick.id)) {
717
+ const skeleton = pick.id.skeleton;
718
+ return isFunction(skeleton?.dragCursor) ? skeleton.dragCursor(pick) : toValue(skeleton?.dragCursor);
719
+ }
720
+ }
721
+ });
722
+ onCleanup(remove);
723
+ });
724
+ onKeyStroke((keyEvent) => {
725
+ if (activeEntity.value) {
726
+ const entity = activeEntity.value;
727
+ const plot = entity.plot;
728
+ const skeleton = entity.skeleton;
729
+ const index = entity.index;
730
+ const packable = plot.sampled.getValue(getCurrentTime());
731
+ skeleton.onKeyPressed?.({
732
+ viewer: viewer.value,
733
+ sampled: plot.sampled,
734
+ packable,
735
+ index,
736
+ keyEvent
737
+ });
738
+ }
739
+ });
740
+ watchEffect((onCleanup) => {
741
+ const remove = addGraphicEvent("global", "HOVER", ({ hovering, pick }) => {
742
+ if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
743
+ const entity = pick.id;
744
+ hoverEntity.value = entity;
745
+ } else hoverEntity.value = void 0;
746
+ });
747
+ onCleanup(remove);
748
+ });
749
+ watchEffect((onCleanup) => {
750
+ const remove = addGraphicEvent("global", "LEFT_CLICK", ({ event, pick }) => {
751
+ if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
752
+ const entity = pick.id;
753
+ activeEntity.value = entity;
754
+ const plot = entity.plot;
755
+ const skeleton = entity.skeleton;
756
+ const index = entity.index;
757
+ const packable = plot.sampled.getValue(getCurrentTime());
758
+ skeleton.onLeftClick?.({
759
+ viewer: viewer.value,
760
+ sampled: plot.sampled,
761
+ packable,
762
+ active: current.value === plot,
763
+ defining: plot.defining,
764
+ index,
765
+ event
766
+ });
767
+ } else activeEntity.value = void 0;
768
+ });
769
+ onCleanup(remove);
770
+ });
771
+ watchArray(plots, (value, oldValue, added, removed = []) => {
772
+ added.forEach((plot) => update(plot));
773
+ removed.forEach((plot) => update(plot, true));
774
+ });
775
+ useCesiumEventListener(() => plots.value.map((plot) => plot.definitionChanged), (plot, key, newValue, oldValue) => {
776
+ if ([
777
+ "disabled",
778
+ "defining",
779
+ "scheme",
780
+ "sampled",
781
+ "time"
782
+ ].includes(key)) nextTick(() => update(plot));
783
+ else if (key === "skeletons") {
784
+ const { added, removed } = arrayDiff(newValue, oldValue);
785
+ added.forEach((item) => entityScope.add(item));
786
+ removed.forEach((item) => entityScope.remove(item));
787
+ }
788
+ });
789
+ watch(current, (plot, previous) => {
790
+ plot && update(plot);
791
+ previous && update(previous);
792
+ });
793
+ return { dataSource };
846
794
  }
795
+
796
+ //#endregion
797
+ //#region usePlot/usePlot.ts
847
798
  function usePlot(options) {
848
- const time = (options == null ? void 0 : options.time) || shallowRef();
849
- const viewer = useViewer();
850
- const getCurrentTime = () => {
851
- var _a;
852
- return ((_a = time.value) == null ? void 0 : _a.clone()) || new JulianDate(0, 0);
853
- };
854
- const collection = shallowReactive(/* @__PURE__ */ new Set());
855
- const plots = computed(() => Array.from(collection));
856
- const current = shallowRef();
857
- const packable = shallowRef();
858
- useCesiumEventListener([
859
- () => {
860
- var _a;
861
- return (_a = current.value) == null ? void 0 : _a.sampled.definitionChanged;
862
- }
863
- ], () => {
864
- var _a;
865
- packable.value = (_a = current.value) == null ? void 0 : _a.sampled.getValue(getCurrentTime());
866
- });
867
- useSampled(current, getCurrentTime);
868
- useRender(plots, current, getCurrentTime);
869
- useSkeleton(plots, current, getCurrentTime);
870
- useScreenSpaceEventHandler(ScreenSpaceEventType.LEFT_CLICK, (data) => {
871
- var _a, _b, _c;
872
- if ((_a = current.value) == null ? void 0 : _a.defining) {
873
- return;
874
- }
875
- const pick = (_b = viewer.value) == null ? void 0 : _b.scene.pick(data.position.clone());
876
- if (((_c = pick == null ? void 0 : pick.id) == null ? void 0 : _c.plot) instanceof PlotFeature) {
877
- return;
878
- }
879
- if (!pick) {
880
- current.value = void 0;
881
- return;
882
- }
883
- current.value = plots.value.find((plot) => pickHitGraphic(pick, [...plot.entities, ...plot.primitives, ...plot.groundPrimitives]));
884
- });
885
- let operateResolve;
886
- let operateReject;
887
- watch(current, (plot, previous) => {
888
- var _a, _b;
889
- if (previous) {
890
- if (previous.defining) {
891
- const packable2 = previous.sampled.getValue(getCurrentTime());
892
- const completed = (_b = (_a = previous.scheme).allowManualComplete) == null ? void 0 : _b.call(_a, packable2);
893
- if (completed) {
894
- PlotFeature.setDefining(previous, false);
895
- operateResolve == null ? void 0 : operateResolve(previous);
896
- } else {
897
- collection.delete(previous);
898
- }
899
- }
900
- }
901
- });
902
- const operate = async (plot) => {
903
- return new Promise((resolve, reject) => {
904
- operateResolve = resolve;
905
- operateReject = reject;
906
- const _plot = plot instanceof PlotFeature ? plot : new PlotFeature(plot);
907
- if (!collection.has(_plot)) {
908
- collection.add(_plot);
909
- }
910
- current.value = _plot;
911
- return resolve(_plot);
912
- });
913
- };
914
- const remove = (plot) => {
915
- if (plot === current.value) {
916
- current.value = void 0;
917
- }
918
- if (collection.has(plot)) {
919
- collection.delete(plot);
920
- return true;
921
- }
922
- return false;
923
- };
924
- return {
925
- plots,
926
- time,
927
- operate,
928
- remove,
929
- cancel: operateReject
930
- };
799
+ const time = options?.time || shallowRef();
800
+ const viewer = useViewer();
801
+ const getCurrentTime = () => {
802
+ return time.value?.clone() || new JulianDate(0, 0);
803
+ };
804
+ const collection = shallowReactive(/* @__PURE__ */ new Set());
805
+ const plots = computed(() => Array.from(collection));
806
+ const current = shallowRef();
807
+ const packable = shallowRef();
808
+ useCesiumEventListener([() => current.value?.sampled.definitionChanged], () => {
809
+ packable.value = current.value?.sampled.getValue(getCurrentTime());
810
+ });
811
+ useSampled(current, getCurrentTime);
812
+ useRender(plots, current, getCurrentTime);
813
+ useSkeleton(plots, current, getCurrentTime);
814
+ useScreenSpaceEventHandler(ScreenSpaceEventType.LEFT_CLICK, (data) => {
815
+ if (current.value?.defining) return;
816
+ const pick = viewer.value?.scene.pick(data.position.clone());
817
+ if (pick?.id?.plot instanceof PlotFeature) return;
818
+ if (!pick) {
819
+ current.value = void 0;
820
+ return;
821
+ }
822
+ current.value = plots.value.find((plot) => pickHitGraphic(pick, [
823
+ ...plot.entities,
824
+ ...plot.primitives,
825
+ ...plot.groundPrimitives
826
+ ]));
827
+ });
828
+ let operateResolve;
829
+ let operateReject;
830
+ watch(current, (plot, previous) => {
831
+ if (previous) {
832
+ if (previous.defining) {
833
+ const packable$1 = previous.sampled.getValue(getCurrentTime());
834
+ const completed = previous.scheme.allowManualComplete?.(packable$1);
835
+ if (completed) {
836
+ PlotFeature.setDefining(previous, false);
837
+ operateResolve?.(previous);
838
+ } else collection.delete(previous);
839
+ }
840
+ }
841
+ });
842
+ const operate = async (plot) => {
843
+ return new Promise((resolve, reject) => {
844
+ operateResolve = resolve;
845
+ operateReject = reject;
846
+ const _plot = plot instanceof PlotFeature ? plot : new PlotFeature(plot);
847
+ if (!collection.has(_plot)) collection.add(_plot);
848
+ current.value = _plot;
849
+ return resolve(_plot);
850
+ });
851
+ };
852
+ const remove = (plot) => {
853
+ if (plot === current.value) current.value = void 0;
854
+ if (collection.has(plot)) {
855
+ collection.delete(plot);
856
+ return true;
857
+ }
858
+ return false;
859
+ };
860
+ return {
861
+ plots,
862
+ time,
863
+ operate,
864
+ remove,
865
+ cancel: operateReject
866
+ };
931
867
  }
868
+
869
+ //#endregion
870
+ //#region skeleton/control.ts
871
+ /**
872
+ * 绘制控制的框架点,拖拽时,将更新该控制点的实时位置
873
+ */
932
874
  function control() {
933
- return {
934
- disabled: ({ active }) => !active,
935
- cursor: "pointer",
936
- dragCursor: "crosshair",
937
- onDrag({ viewer, sampled, packable, event, index, lockCamera }) {
938
- lockCamera();
939
- const position = canvasCoordToCartesian(event.endPosition, viewer.scene);
940
- if (position) {
941
- const positions = [...packable.positions ?? []];
942
- positions[index] = position;
943
- sampled.setSample({
944
- time: packable.time,
945
- derivative: packable.derivative,
946
- positions
947
- });
948
- }
949
- },
950
- onKeyPressed({ viewer, keyEvent, sampled, packable, index }) {
951
- var _a;
952
- const height = (_a = toCartographic(viewer.camera.position)) == null ? void 0 : _a.height;
953
- if (!height || !["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft"].includes(keyEvent.key))
954
- return;
955
- keyEvent.preventDefault();
956
- let headingAdjust = 0;
957
- switch (keyEvent.key) {
958
- case "ArrowRight":
959
- headingAdjust = Math.PI / 2;
960
- break;
961
- case "ArrowDown":
962
- headingAdjust = Math.PI;
963
- break;
964
- case "ArrowLeft":
965
- headingAdjust = -Math.PI / 2;
966
- break;
967
- case "ArrowUp":
968
- headingAdjust = 0;
969
- break;
970
- }
971
- const newHeading = (viewer.camera.heading + headingAdjust) % (2 * Math.PI);
972
- const positions = [...packable.positions ?? []];
973
- const cartographic = toCartographic(positions[index]);
974
- const r = height / 1e5;
975
- const distance = r * Math.PI / 180 / 1e3;
976
- cartographic.latitude += distance * Math.cos(newHeading);
977
- cartographic.longitude += distance * Math.sin(newHeading);
978
- positions[index] = toCartesian3(cartographic);
979
- sampled.setSample({
980
- time: packable.time,
981
- derivative: packable.derivative,
982
- positions
983
- });
984
- },
985
- render: ({ position, action }) => {
986
- const colors = {
987
- [PlotAction.IDLE]: Color.BLUE.withAlpha(0.4),
988
- [PlotAction.HOVER]: Color.BLUE.withAlpha(0.6),
989
- [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
990
- };
991
- return {
992
- position,
993
- point: {
994
- pixelSize: 8,
995
- color: colors[action],
996
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
997
- outlineWidth: 1,
998
- outlineColor: Color.WHITE.withAlpha(0.4)
999
- }
1000
- };
1001
- }
1002
- };
875
+ return {
876
+ disabled: ({ active }) => !active,
877
+ cursor: "pointer",
878
+ dragCursor: "crosshair",
879
+ onDrag({ viewer, sampled, packable, event, index, lockCamera }) {
880
+ lockCamera();
881
+ const position = canvasCoordToCartesian(event.endPosition, viewer.scene);
882
+ if (position) {
883
+ const positions = [...packable.positions ?? []];
884
+ positions[index] = position;
885
+ sampled.setSample({
886
+ time: packable.time,
887
+ derivative: packable.derivative,
888
+ positions
889
+ });
890
+ }
891
+ },
892
+ onKeyPressed({ viewer, keyEvent, sampled, packable, index }) {
893
+ const height = toCartographic(viewer.camera.position)?.height;
894
+ if (!height || ![
895
+ "ArrowUp",
896
+ "ArrowRight",
897
+ "ArrowDown",
898
+ "ArrowLeft"
899
+ ].includes(keyEvent.key)) return;
900
+ keyEvent.preventDefault();
901
+ let headingAdjust = 0;
902
+ switch (keyEvent.key) {
903
+ case "ArrowRight":
904
+ headingAdjust = Math.PI / 2;
905
+ break;
906
+ case "ArrowDown":
907
+ headingAdjust = Math.PI;
908
+ break;
909
+ case "ArrowLeft":
910
+ headingAdjust = -Math.PI / 2;
911
+ break;
912
+ case "ArrowUp":
913
+ headingAdjust = 0;
914
+ break;
915
+ }
916
+ const newHeading = (viewer.camera.heading + headingAdjust) % (2 * Math.PI);
917
+ const positions = [...packable.positions ?? []];
918
+ const cartographic = toCartographic(positions[index]);
919
+ const r = height / 1e5;
920
+ const distance = r * Math.PI / 180 / 1e3;
921
+ cartographic.latitude += distance * Math.cos(newHeading);
922
+ cartographic.longitude += distance * Math.sin(newHeading);
923
+ positions[index] = toCartesian3(cartographic);
924
+ sampled.setSample({
925
+ time: packable.time,
926
+ derivative: packable.derivative,
927
+ positions
928
+ });
929
+ },
930
+ render: ({ position, action }) => {
931
+ const colors = {
932
+ [PlotAction.IDLE]: Color.BLUE.withAlpha(.4),
933
+ [PlotAction.HOVER]: Color.BLUE.withAlpha(.6),
934
+ [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
935
+ };
936
+ return {
937
+ position,
938
+ point: {
939
+ pixelSize: 8,
940
+ color: colors[action],
941
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
942
+ outlineWidth: 1,
943
+ outlineColor: Color.WHITE.withAlpha(.4)
944
+ }
945
+ };
946
+ }
947
+ };
1003
948
  }
949
+
950
+ //#endregion
951
+ //#region skeleton/interval.ts
952
+ /**
953
+ * 绘制封闭的间隔框架点,如多边形。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
954
+ */
1004
955
  function interval() {
1005
- let dragIndex = -1;
1006
- return {
1007
- disabled: ({ active, defining }) => !active || defining,
1008
- cursor: "pointer",
1009
- dragCursor: "crosshair",
1010
- format(packable) {
1011
- const _positions = packable.positions ?? [];
1012
- if (_positions.length < 2) {
1013
- return [];
1014
- }
1015
- return _positions.map((position, i) => {
1016
- const next = i === _positions.length - 1 ? _positions[0] : _positions[i + 1];
1017
- return Cartesian3.midpoint(position, next, new Cartesian3());
1018
- });
1019
- },
1020
- onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
1021
- lockCamera();
1022
- const position = canvasCoordToCartesian(event.endPosition, viewer.scene);
1023
- if (!position) {
1024
- return;
1025
- }
1026
- const positions = [...packable.positions ?? []];
1027
- if (dragIndex === -1) {
1028
- dragIndex = index;
1029
- positions.splice(index + 1, 0, position);
1030
- } else {
1031
- positions[dragIndex + 1] = position;
1032
- }
1033
- if (!dragging) {
1034
- dragIndex = -1;
1035
- }
1036
- sampled.setSample({
1037
- time: packable.time,
1038
- derivative: packable.derivative,
1039
- positions
1040
- });
1041
- },
1042
- render: ({ position, action, active }) => {
1043
- if (!active) {
1044
- return;
1045
- }
1046
- const colors = {
1047
- [PlotAction.IDLE]: Color.GREEN.withAlpha(0.4),
1048
- [PlotAction.HOVER]: Color.GREEN.withAlpha(0.6),
1049
- [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
1050
- };
1051
- return {
1052
- position,
1053
- point: {
1054
- pixelSize: 6,
1055
- color: colors[action],
1056
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
1057
- outlineWidth: 1,
1058
- outlineColor: Color.WHITE.withAlpha(0.4)
1059
- }
1060
- };
1061
- }
1062
- };
956
+ let dragIndex = -1;
957
+ return {
958
+ disabled: ({ active, defining }) => !active || defining,
959
+ cursor: "pointer",
960
+ dragCursor: "crosshair",
961
+ format(packable) {
962
+ const _positions = packable.positions ?? [];
963
+ if (_positions.length < 2) return [];
964
+ return _positions.map((position, i) => {
965
+ const next = i === _positions.length - 1 ? _positions[0] : _positions[i + 1];
966
+ return Cartesian3.midpoint(position, next, new Cartesian3());
967
+ });
968
+ },
969
+ onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
970
+ lockCamera();
971
+ const position = canvasCoordToCartesian(event.endPosition, viewer.scene);
972
+ if (!position) return;
973
+ const positions = [...packable.positions ?? []];
974
+ if (dragIndex === -1) {
975
+ dragIndex = index;
976
+ positions.splice(index + 1, 0, position);
977
+ } else positions[dragIndex + 1] = position;
978
+ if (!dragging) dragIndex = -1;
979
+ sampled.setSample({
980
+ time: packable.time,
981
+ derivative: packable.derivative,
982
+ positions
983
+ });
984
+ },
985
+ render: ({ position, action, active }) => {
986
+ if (!active) return;
987
+ const colors = {
988
+ [PlotAction.IDLE]: Color.GREEN.withAlpha(.4),
989
+ [PlotAction.HOVER]: Color.GREEN.withAlpha(.6),
990
+ [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
991
+ };
992
+ return {
993
+ position,
994
+ point: {
995
+ pixelSize: 6,
996
+ color: colors[action],
997
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
998
+ outlineWidth: 1,
999
+ outlineColor: Color.WHITE.withAlpha(.4)
1000
+ }
1001
+ };
1002
+ }
1003
+ };
1063
1004
  }
1005
+
1006
+ //#endregion
1007
+ //#region skeleton/intervalNonclosed.ts
1008
+ /**
1009
+ * 绘制非封闭的间隔框架点,如线段。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
1010
+ */
1064
1011
  function intervalNonclosed() {
1065
- let dragIndex = -1;
1066
- return {
1067
- disabled: ({ active, defining }) => !active || defining,
1068
- cursor: "pointer",
1069
- dragCursor: "crosshair",
1070
- format(packable) {
1071
- const _positions = packable.positions ?? [];
1072
- if (_positions.length < 2) {
1073
- return [];
1074
- }
1075
- const midpoints = [];
1076
- for (let i = 0; i < _positions.length - 1; i++) {
1077
- midpoints.push(Cartesian3.midpoint(_positions[i], _positions[i + 1], new Cartesian3()));
1078
- }
1079
- return midpoints;
1080
- },
1081
- onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
1082
- lockCamera();
1083
- const position = canvasCoordToCartesian(event.endPosition, viewer.scene);
1084
- if (!position) {
1085
- return;
1086
- }
1087
- const positions = [...packable.positions ?? []];
1088
- if (dragIndex === -1) {
1089
- dragIndex = index;
1090
- positions.splice(index + 1, 0, position);
1091
- } else {
1092
- positions[dragIndex + 1] = position;
1093
- }
1094
- if (!dragging) {
1095
- dragIndex = -1;
1096
- }
1097
- sampled.setSample({
1098
- time: packable.time,
1099
- derivative: packable.derivative,
1100
- positions
1101
- });
1102
- },
1103
- render: ({ position, action }) => {
1104
- const colors = {
1105
- [PlotAction.IDLE]: Color.GREEN.withAlpha(0.4),
1106
- [PlotAction.HOVER]: Color.GREEN.withAlpha(0.6),
1107
- [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
1108
- };
1109
- return {
1110
- position,
1111
- point: {
1112
- pixelSize: 6,
1113
- color: colors[action],
1114
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
1115
- outlineWidth: 1,
1116
- outlineColor: Color.WHITE.withAlpha(0.4)
1117
- }
1118
- };
1119
- }
1120
- };
1012
+ let dragIndex = -1;
1013
+ return {
1014
+ disabled: ({ active, defining }) => !active || defining,
1015
+ cursor: "pointer",
1016
+ dragCursor: "crosshair",
1017
+ format(packable) {
1018
+ const _positions = packable.positions ?? [];
1019
+ if (_positions.length < 2) return [];
1020
+ const midpoints = [];
1021
+ for (let i = 0; i < _positions.length - 1; i++) midpoints.push(Cartesian3.midpoint(_positions[i], _positions[i + 1], new Cartesian3()));
1022
+ return midpoints;
1023
+ },
1024
+ onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
1025
+ lockCamera();
1026
+ const position = canvasCoordToCartesian(event.endPosition, viewer.scene);
1027
+ if (!position) return;
1028
+ const positions = [...packable.positions ?? []];
1029
+ if (dragIndex === -1) {
1030
+ dragIndex = index;
1031
+ positions.splice(index + 1, 0, position);
1032
+ } else positions[dragIndex + 1] = position;
1033
+ if (!dragging) dragIndex = -1;
1034
+ sampled.setSample({
1035
+ time: packable.time,
1036
+ derivative: packable.derivative,
1037
+ positions
1038
+ });
1039
+ },
1040
+ render: ({ position, action }) => {
1041
+ const colors = {
1042
+ [PlotAction.IDLE]: Color.GREEN.withAlpha(.4),
1043
+ [PlotAction.HOVER]: Color.GREEN.withAlpha(.6),
1044
+ [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
1045
+ };
1046
+ return {
1047
+ position,
1048
+ point: {
1049
+ pixelSize: 6,
1050
+ color: colors[action],
1051
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
1052
+ outlineWidth: 1,
1053
+ outlineColor: Color.WHITE.withAlpha(.4)
1054
+ }
1055
+ };
1056
+ }
1057
+ };
1121
1058
  }
1122
- const svg = `data:image/svg+xml;utf8,${encodeURIComponent(
1123
- '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m18 9l3 3l-3 3m-3-3h6M6 9l-3 3l3 3m-3-3h6m0 6l3 3l3-3m-3-3v6m3-15l-3-3l-3 3m3-3v6"/></svg>'
1124
- )}`;
1059
+
1060
+ //#endregion
1061
+ //#region skeleton/moved.ts
1062
+ const svg = `data:image/svg+xml;utf8,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" height=\"32\" viewBox=\"0 0 24 24\"><path stroke=\"#ffffff\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m18 9l3 3l-3 3m-3-3h6M6 9l-3 3l3 3m-3-3h6m0 6l3 3l3-3m-3-3v6m3-15l-3-3l-3 3m3-3v6\"/></svg>")}`;
1063
+ /**
1064
+ * 绘制非封闭的间隔框架点,如线段。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
1065
+ */
1125
1066
  function moved() {
1126
- return {
1127
- disabled: ({ active, defining }) => !active || defining,
1128
- cursor: "pointer",
1129
- dragCursor: "crosshair",
1130
- format(packable) {
1131
- const positions = packable.positions ?? [];
1132
- if (positions.length === 0) {
1133
- return [];
1134
- } else if (positions.length === 1) {
1135
- return [positions[0]];
1136
- } else {
1137
- const center = Rectangle.center(Rectangle.fromCartesianArray(positions));
1138
- return [toCartesian3(center)];
1139
- }
1140
- },
1141
- onDrag({ viewer, sampled, packable, event, lockCamera, dragging }) {
1142
- dragging && lockCamera();
1143
- const startPosition = canvasCoordToCartesian(event.startPosition, viewer.scene);
1144
- const endPosition = canvasCoordToCartesian(event.endPosition, viewer.scene);
1145
- if (!startPosition || !endPosition) {
1146
- return;
1147
- }
1148
- const offset = Cartesian3.subtract(endPosition, startPosition, new Cartesian3());
1149
- const positions = [...packable.positions ?? []];
1150
- sampled.setSample({
1151
- time: packable.time,
1152
- derivative: packable.derivative,
1153
- positions: positions.map((position) => Cartesian3.add(position, offset, new Cartesian3()))
1154
- });
1155
- },
1156
- render: ({ position, action }) => {
1157
- const colors = {
1158
- [PlotAction.IDLE]: Color.WHITE,
1159
- [PlotAction.HOVER]: Color.WHITE,
1160
- [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
1161
- };
1162
- return {
1163
- position,
1164
- billboard: {
1165
- image: svg,
1166
- width: 20,
1167
- height: 20,
1168
- color: colors[action],
1169
- pixelOffset: new Cartesian3(0, -20),
1170
- horizontalOrigin: HorizontalOrigin.CENTER,
1171
- verticalOrigin: VerticalOrigin.BOTTOM,
1172
- disableDepthTestDistance: Number.POSITIVE_INFINITY
1173
- }
1174
- };
1175
- }
1176
- };
1067
+ return {
1068
+ disabled: ({ active, defining }) => !active || defining,
1069
+ cursor: "pointer",
1070
+ dragCursor: "crosshair",
1071
+ format(packable) {
1072
+ const positions = packable.positions ?? [];
1073
+ if (positions.length === 0) return [];
1074
+ else if (positions.length === 1) return [positions[0]];
1075
+ else {
1076
+ const center = Rectangle.center(Rectangle.fromCartesianArray(positions));
1077
+ return [toCartesian3(center)];
1078
+ }
1079
+ },
1080
+ onDrag({ viewer, sampled, packable, event, lockCamera, dragging }) {
1081
+ dragging && lockCamera();
1082
+ const startPosition = canvasCoordToCartesian(event.startPosition, viewer.scene);
1083
+ const endPosition = canvasCoordToCartesian(event.endPosition, viewer.scene);
1084
+ if (!startPosition || !endPosition) return;
1085
+ const offset = Cartesian3.subtract(endPosition, startPosition, new Cartesian3());
1086
+ const positions = [...packable.positions ?? []];
1087
+ sampled.setSample({
1088
+ time: packable.time,
1089
+ derivative: packable.derivative,
1090
+ positions: positions.map((position) => Cartesian3.add(position, offset, new Cartesian3()))
1091
+ });
1092
+ },
1093
+ render: ({ position, action }) => {
1094
+ const colors = {
1095
+ [PlotAction.IDLE]: Color.WHITE,
1096
+ [PlotAction.HOVER]: Color.WHITE,
1097
+ [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
1098
+ };
1099
+ return {
1100
+ position,
1101
+ billboard: {
1102
+ image: svg,
1103
+ width: 20,
1104
+ height: 20,
1105
+ color: colors[action],
1106
+ pixelOffset: new Cartesian3(0, -20),
1107
+ horizontalOrigin: HorizontalOrigin.CENTER,
1108
+ verticalOrigin: VerticalOrigin.BOTTOM,
1109
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
1110
+ }
1111
+ };
1112
+ }
1113
+ };
1177
1114
  }
1115
+
1116
+ //#endregion
1117
+ //#region measure/utils/tesselate.ts
1118
+ /**
1119
+ * 将多个边界点组成的面切割成多个三角形
1120
+ * @param positions
1121
+ */
1178
1122
  function tesselate(positions) {
1179
- if (positions.length < 3) {
1180
- throw new Error("positions must >= 3");
1181
- }
1182
- if (positions.length === 3) {
1183
- return [[positions[0].clone(), positions[1].clone(), positions[2].clone()]];
1184
- }
1185
- const geometry = CoplanarPolygonGeometry.createGeometry(
1186
- CoplanarPolygonGeometry.fromPositions({
1187
- positions,
1188
- vertexFormat: VertexFormat.POSITION_ONLY
1189
- })
1190
- );
1191
- if (!geometry) {
1192
- throw new Error("positions无法组成有效的geometry,检查点位是否错误");
1193
- }
1194
- const values = geometry.attributes.position.values;
1195
- const indices = geometry.indices;
1196
- const result = [];
1197
- for (let i = 0; i < indices.length; i += 3) {
1198
- const a = Cartesian3.unpack(values, indices[i] * 3, new Cartesian3());
1199
- const b = Cartesian3.unpack(values, indices[i + 1] * 3, new Cartesian3());
1200
- const c = Cartesian3.unpack(values, indices[i + 2] * 3, new Cartesian3());
1201
- result.push([a, b, c]);
1202
- }
1203
- return result;
1123
+ if (positions.length < 3) throw new Error("positions must >= 3");
1124
+ if (positions.length === 3) return [[
1125
+ positions[0].clone(),
1126
+ positions[1].clone(),
1127
+ positions[2].clone()
1128
+ ]];
1129
+ const geometry = CoplanarPolygonGeometry.createGeometry(CoplanarPolygonGeometry.fromPositions({
1130
+ positions,
1131
+ vertexFormat: VertexFormat.POSITION_ONLY
1132
+ }));
1133
+ if (!geometry) throw new Error("positions无法组成有效的geometry,检查点位是否错误");
1134
+ const values = geometry.attributes.position.values;
1135
+ const indices = geometry.indices;
1136
+ const result = [];
1137
+ for (let i = 0; i < indices.length; i += 3) {
1138
+ const a = Cartesian3.unpack(values, indices[i] * 3, new Cartesian3());
1139
+ const b = Cartesian3.unpack(values, indices[i + 1] * 3, new Cartesian3());
1140
+ const c = Cartesian3.unpack(values, indices[i + 2] * 3, new Cartesian3());
1141
+ result.push([
1142
+ a,
1143
+ b,
1144
+ c
1145
+ ]);
1146
+ }
1147
+ return result;
1148
+ }
1149
+
1150
+ //#endregion
1151
+ //#region measure/utils/clampToGround.ts
1152
+ /**
1153
+ * 将传入的点位列表进行贴地处理,若某个点位获取高程失败则将此进行克隆返回
1154
+ * @param options - 配置项
1155
+ */
1156
+ async function clampToHeightMostDetailedByTilesetOrTerrain(options) {
1157
+ const { positions, scene, classificationType = ClassificationType.BOTH, terrainProvider = scene.terrainProvider } = options;
1158
+ const tileset = [ClassificationType.BOTH, ClassificationType.CESIUM_3D_TILE].includes(classificationType);
1159
+ const terrain = [ClassificationType.BOTH, ClassificationType.TERRAIN].includes(classificationType);
1160
+ const tilesetPromise = new Promise((resolve) => {
1161
+ if (tileset) scene.clampToHeightMostDetailed(positions.map((e) => e.clone())).then(resolve).catch((error) => {
1162
+ console.warn(error);
1163
+ resolve([]);
1164
+ });
1165
+ else resolve([]);
1166
+ });
1167
+ const terrainPromise = new Promise((resolve) => {
1168
+ if (terrain && terrainProvider) sampleTerrainMostDetailed(terrainProvider, positions.map((e) => Cartographic.fromCartesian(e))).then((e) => resolve(e)).catch((error) => {
1169
+ console.warn(error);
1170
+ resolve([]);
1171
+ });
1172
+ else resolve([]);
1173
+ });
1174
+ const [tilesetPositions, terrainPositions] = await Promise.all([tilesetPromise, terrainPromise]);
1175
+ const resluts = [];
1176
+ positions.forEach((item, index) => {
1177
+ const position = tilesetPositions[index] || terrainPositions[index] ? Ellipsoid.WGS84.cartographicToCartesian(terrainPositions[index]) : item.clone();
1178
+ resluts.push(position);
1179
+ });
1180
+ return resluts;
1204
1181
  }
1182
+
1183
+ //#endregion
1184
+ //#region measure/utils/triangleGrid.ts
1185
+ function defaultOptions$1(original) {
1186
+ const clampToGround = original?.clampToGround ?? false;
1187
+ const classificationType = original?.classificationType ?? ClassificationType.BOTH;
1188
+ const density = Math.floor(original?.density ?? 10);
1189
+ return {
1190
+ scene: original?.scene,
1191
+ clampToGround,
1192
+ classificationType,
1193
+ terrainProvider: original?.terrainProvider,
1194
+ density
1195
+ };
1196
+ }
1197
+ /**
1198
+ * 生成三角网数组
1199
+ * @param positions - 边界点数组
1200
+ * @param options - 配置项
1201
+ */
1202
+ async function triangleGrid(positions, options) {
1203
+ if (positions.length < 3) throw new Error("positions must >= 3");
1204
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1205
+ if (density <= 0) throw new Error("options.density must > 0");
1206
+ const bbox = Rectangle.fromCartesianArray(positions);
1207
+ const vertical = bbox.north - bbox.south;
1208
+ const horizontal = bbox.east - bbox.west;
1209
+ const max = Math.max(horizontal, vertical);
1210
+ const granularity = max / density;
1211
+ const polygonGeometry = PolygonGeometry.fromPositions({
1212
+ positions,
1213
+ vertexFormat: PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
1214
+ granularity
1215
+ });
1216
+ const geometry = PolygonGeometry.createGeometry(polygonGeometry);
1217
+ const values = geometry.attributes.position.values;
1218
+ if (!geometry || !values) throw new Error("positions无法组成有效的geometry,检查点位是否错误");
1219
+ const indices = geometry.indices;
1220
+ let cartesian3List = [];
1221
+ for (let i = 0; i < indices.length; i += 3) {
1222
+ const a = Cartesian3.unpack(values, indices[i] * 3, new Cartesian3());
1223
+ const b = Cartesian3.unpack(values, indices[i + 1] * 3, new Cartesian3());
1224
+ const c = Cartesian3.unpack(values, indices[i + 2] * 3, new Cartesian3());
1225
+ cartesian3List.push(a, b, c);
1226
+ }
1227
+ if (clampToGround) {
1228
+ if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1229
+ const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
1230
+ scene,
1231
+ terrainProvider,
1232
+ positions: cartesian3List,
1233
+ classificationType
1234
+ });
1235
+ cartesian3List = detaileds;
1236
+ }
1237
+ const grid = [];
1238
+ while (cartesian3List?.length) {
1239
+ const [a, b, c] = cartesian3List.splice(0, 3);
1240
+ grid.push([
1241
+ a,
1242
+ b,
1243
+ c
1244
+ ]);
1245
+ }
1246
+ return grid;
1247
+ }
1248
+
1249
+ //#endregion
1250
+ //#region measure/utils/area.ts
1251
+ /**
1252
+ * 计算三维坐标系下三角形面积
1253
+ * @param p0 - 三角形第一个点
1254
+ * @param p1 - 三角形第二个点
1255
+ * @param p2 - 三角形第三个点
1256
+ */
1205
1257
  function triangleArea(p0, p1, p2) {
1206
- const v0 = Cartesian3.subtract(p0, p1, new Cartesian3());
1207
- const v1 = Cartesian3.subtract(p2, p1, new Cartesian3());
1208
- const cross = Cartesian3.cross(v0, v1, v0);
1209
- return Cartesian3.magnitude(cross) * 0.5;
1258
+ const v0 = Cartesian3.subtract(p0, p1, new Cartesian3());
1259
+ const v1 = Cartesian3.subtract(p2, p1, new Cartesian3());
1260
+ const cross = Cartesian3.cross(v0, v1, v0);
1261
+ return Cartesian3.magnitude(cross) * .5;
1210
1262
  }
1211
1263
  function defaultOptions(original) {
1212
- const clampToGround = false;
1213
- const classificationType = ClassificationType.BOTH;
1214
- const density = Math.floor(10);
1215
- return {
1216
- scene: original == null ? void 0 : original.scene,
1217
- clampToGround,
1218
- classificationType,
1219
- terrainProvider: original == null ? void 0 : original.terrainProvider,
1220
- density
1221
- };
1264
+ const clampToGround = original?.clampToGround ?? false;
1265
+ const classificationType = original?.classificationType ?? ClassificationType.BOTH;
1266
+ const density = Math.floor(original?.density ?? 10);
1267
+ return {
1268
+ scene: original?.scene,
1269
+ clampToGround,
1270
+ classificationType,
1271
+ terrainProvider: original?.terrainProvider,
1272
+ density
1273
+ };
1222
1274
  }
1275
+ /**
1276
+ * 计算三维坐标系下图形面积
1277
+ * @param positions - 图形各点的笛卡尔数组
1278
+ */
1223
1279
  async function area(positions, options) {
1224
- if (positions.length < 2) {
1225
- throw new Error("positions.length must >= 2");
1226
- }
1227
- const { density } = defaultOptions(options);
1228
- if (density <= 0) {
1229
- throw new Error("options.density must > 0");
1230
- }
1231
- {
1232
- const triangles2 = tesselate(positions);
1233
- return triangles2.reduce((count, current) => count += triangleArea(...current), 0);
1234
- }
1280
+ if (positions.length < 2) throw new Error("positions.length must >= 2");
1281
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions(options);
1282
+ if (density <= 0) throw new Error("options.density must > 0");
1283
+ if (!clampToGround) {
1284
+ const triangles$1 = tesselate(positions);
1285
+ return triangles$1.reduce((count, current) => count += triangleArea(...current), 0);
1286
+ }
1287
+ const triangles = await triangleGrid(positions, {
1288
+ density,
1289
+ scene,
1290
+ clampToGround,
1291
+ classificationType,
1292
+ terrainProvider
1293
+ });
1294
+ return triangles.reduce((count, current) => count += triangleArea(...current), 0);
1235
1295
  }
1296
+
1297
+ //#endregion
1298
+ //#region measure/measureArea.ts
1236
1299
  const schemeMeasureArea = new PlotScheme({
1237
- type: "measureArea",
1238
- allowManualComplete: (packable) => packable.positions.length >= 3,
1239
- skeletons: [
1240
- control,
1241
- interval
1242
- ],
1243
- initEntites: () => [
1244
- new Entity({
1245
- label: {
1246
- font: "14pt"
1247
- },
1248
- polyline: {
1249
- material: Color.YELLOW.withAlpha(0.5)
1250
- },
1251
- polygon: {
1252
- material: Color.YELLOW.withAlpha(0.5)
1253
- }
1254
- })
1255
- ],
1256
- render(options) {
1257
- var _a;
1258
- const { mouse, packable } = options;
1259
- const entity = ((_a = options.previous.entities) == null ? void 0 : _a[0]) ?? new Entity({
1260
- label: {
1261
- font: "14pt"
1262
- },
1263
- polyline: {
1264
- material: Color.YELLOW.withAlpha(0.5)
1265
- },
1266
- polygon: {
1267
- material: Color.YELLOW.withAlpha(0.5)
1268
- }
1269
- });
1270
- const positions = [...packable.positions ?? []];
1271
- mouse && positions.push(mouse);
1272
- if (positions.length === 2) {
1273
- entity.position = void 0;
1274
- entity.label.text = void 0;
1275
- entity.polygon.hierarchy = void 0;
1276
- entity.polyline.positions = new CallbackProperty(() => positions, false);
1277
- } else if (positions.length >= 3) {
1278
- positions.push(positions[0]);
1279
- entity.position = new ConstantPositionProperty(
1280
- toCartesian3(
1281
- Rectangle.center(Rectangle.fromCartesianArray(positions))
1282
- )
1283
- );
1284
- entity.label.text = new ConstantProperty("");
1285
- area(positions).then((e) => {
1286
- let text = "";
1287
- if (e / 1e3 / 1e3 > 10) {
1288
- text = `${(e / 1e3 / 1e3).toFixed(2)}km²`;
1289
- } else {
1290
- text = `${(+e).toFixed(2)}m²`;
1291
- }
1292
- entity.label.text = new ConstantProperty(text);
1293
- });
1294
- entity.polyline.positions = void 0;
1295
- entity.polygon.hierarchy = new CallbackProperty(() => {
1296
- return positions.length >= 3 ? new PolygonHierarchy([...positions]) : void 0;
1297
- }, false);
1298
- } else {
1299
- entity.position = void 0;
1300
- entity.polygon.hierarchy = void 0;
1301
- entity.polyline.positions = void 0;
1302
- }
1303
- return {
1304
- entities: [entity]
1305
- };
1306
- }
1300
+ type: "measureArea",
1301
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1302
+ skeletons: [control, interval],
1303
+ initEntites: () => [new Entity({
1304
+ label: { font: "14pt" },
1305
+ polyline: { material: Color.YELLOW.withAlpha(.5) },
1306
+ polygon: { material: Color.YELLOW.withAlpha(.5) }
1307
+ })],
1308
+ render(options) {
1309
+ const { mouse, packable } = options;
1310
+ const entity = options.previous.entities?.[0] ?? new Entity({
1311
+ label: { font: "14pt" },
1312
+ polyline: { material: Color.YELLOW.withAlpha(.5) },
1313
+ polygon: { material: Color.YELLOW.withAlpha(.5) }
1314
+ });
1315
+ const positions = [...packable.positions ?? []];
1316
+ mouse && positions.push(mouse);
1317
+ if (positions.length === 2) {
1318
+ entity.position = void 0;
1319
+ entity.label.text = void 0;
1320
+ entity.polygon.hierarchy = void 0;
1321
+ entity.polyline.positions = new CallbackProperty(() => positions, false);
1322
+ } else if (positions.length >= 3) {
1323
+ positions.push(positions[0]);
1324
+ entity.position = new ConstantPositionProperty(toCartesian3(Rectangle.center(Rectangle.fromCartesianArray(positions))));
1325
+ entity.label.text = new ConstantProperty("");
1326
+ area(positions).then((e) => {
1327
+ let text = "";
1328
+ if (e / 1e3 / 1e3 > 10) text = `${(e / 1e3 / 1e3).toFixed(2)}km²`;
1329
+ else text = `${(+e).toFixed(2)}m²`;
1330
+ entity.label.text = new ConstantProperty(text);
1331
+ });
1332
+ entity.polyline.positions = void 0;
1333
+ entity.polygon.hierarchy = new CallbackProperty(() => {
1334
+ return positions.length >= 3 ? new PolygonHierarchy([...positions]) : void 0;
1335
+ }, false);
1336
+ } else {
1337
+ entity.position = void 0;
1338
+ entity.polygon.hierarchy = void 0;
1339
+ entity.polyline.positions = void 0;
1340
+ }
1341
+ return { entities: [entity] };
1342
+ }
1307
1343
  });
1344
+
1345
+ //#endregion
1346
+ //#region scheme/billboard.ts
1347
+ /**
1348
+ * 广告牌标绘方案
1349
+ */
1308
1350
  const schemeBillboard = new PlotScheme({
1309
- type: "billboard",
1310
- complete: (packable) => packable.positions.length >= 1,
1311
- skeletons: [
1312
- moved
1313
- ],
1314
- initEntites: () => [
1315
- new Entity({ billboard: { image: "/favicon.svg", width: 32, height: 32 } })
1316
- ],
1317
- render(options) {
1318
- var _a, _b;
1319
- const { mouse, packable } = options;
1320
- const entity = ((_a = options.previous.entities) == null ? void 0 : _a[0]) ?? new Entity({ billboard: {} });
1321
- const position = ((_b = packable.positions) == null ? void 0 : _b[0]) ?? mouse;
1322
- entity.position = new CallbackPositionProperty(() => position, true);
1323
- return {
1324
- entities: [entity]
1325
- };
1326
- }
1351
+ type: "billboard",
1352
+ complete: (packable) => packable.positions.length >= 1,
1353
+ skeletons: [moved],
1354
+ initEntites: () => [new Entity({ billboard: {
1355
+ image: "/favicon.svg",
1356
+ width: 32,
1357
+ height: 32
1358
+ } })],
1359
+ render(options) {
1360
+ const { mouse, packable } = options;
1361
+ const entity = options.previous.entities?.[0] ?? new Entity({ billboard: {} });
1362
+ const position = packable.positions?.[0] ?? mouse;
1363
+ entity.position = new CallbackPositionProperty(() => position, true);
1364
+ return { entities: [entity] };
1365
+ }
1327
1366
  });
1367
+
1368
+ //#endregion
1369
+ //#region scheme/label.ts
1370
+ /**
1371
+ * 标签文字标绘方案
1372
+ */
1328
1373
  const schemeLabel = new PlotScheme({
1329
- type: "label",
1330
- complete: (packable) => packable.positions.length >= 1,
1331
- skeletons: [
1332
- moved
1333
- ],
1334
- initEntites: () => [
1335
- new Entity({ label: { text: "Label" } })
1336
- ],
1337
- render(options) {
1338
- var _a, _b;
1339
- const { mouse, packable } = options;
1340
- const entity = ((_a = options.previous.entities) == null ? void 0 : _a[0]) ?? new Entity({ label: {} });
1341
- const position = ((_b = packable.positions) == null ? void 0 : _b[0]) ?? mouse;
1342
- entity.position = new CallbackPositionProperty(() => position, true);
1343
- return {
1344
- entities: [entity]
1345
- };
1346
- }
1374
+ type: "label",
1375
+ complete: (packable) => packable.positions.length >= 1,
1376
+ skeletons: [moved],
1377
+ initEntites: () => [new Entity({ label: { text: "Label" } })],
1378
+ render(options) {
1379
+ const { mouse, packable } = options;
1380
+ const entity = options.previous.entities?.[0] ?? new Entity({ label: {} });
1381
+ const position = packable.positions?.[0] ?? mouse;
1382
+ entity.position = new CallbackPositionProperty(() => position, true);
1383
+ return { entities: [entity] };
1384
+ }
1347
1385
  });
1386
+
1387
+ //#endregion
1388
+ //#region scheme/polygon.ts
1389
+ /**
1390
+ * 内置的多边形标绘方案
1391
+ */
1348
1392
  const schemePolygon = new PlotScheme({
1349
- type: "polygon",
1350
- allowManualComplete: (packable) => packable.positions.length >= 3,
1351
- skeletons: [
1352
- control,
1353
- interval,
1354
- moved
1355
- ],
1356
- initEntites: () => [
1357
- new Entity({
1358
- polyline: {
1359
- material: Color.YELLOW.withAlpha(0.5)
1360
- },
1361
- polygon: {
1362
- material: Color.YELLOW.withAlpha(0.5)
1363
- }
1364
- })
1365
- ],
1366
- render(options) {
1367
- var _a;
1368
- const { mouse, packable } = options;
1369
- const entity = ((_a = options.previous.entities) == null ? void 0 : _a[0]) ?? new Entity({
1370
- polyline: {
1371
- material: Color.YELLOW.withAlpha(0.5)
1372
- },
1373
- polygon: {
1374
- material: Color.YELLOW.withAlpha(0.5)
1375
- }
1376
- });
1377
- const positions = [...packable.positions ?? []];
1378
- mouse && positions.push(mouse);
1379
- if (positions.length === 2) {
1380
- entity.polygon.hierarchy = void 0;
1381
- entity.polyline.positions = new CallbackProperty(() => positions, false);
1382
- } else if (positions.length >= 3) {
1383
- entity.polyline.positions = void 0;
1384
- entity.polygon.hierarchy = new CallbackProperty(() => {
1385
- positions.push(positions[0]);
1386
- return positions.length >= 3 ? new PolygonHierarchy([...positions]) : void 0;
1387
- }, false);
1388
- } else {
1389
- entity.polygon.hierarchy = void 0;
1390
- entity.polyline.positions = void 0;
1391
- }
1392
- return {
1393
- entities: [entity]
1394
- };
1395
- }
1393
+ type: "polygon",
1394
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1395
+ skeletons: [
1396
+ control,
1397
+ interval,
1398
+ moved
1399
+ ],
1400
+ initEntites: () => [new Entity({
1401
+ polyline: { material: Color.YELLOW.withAlpha(.5) },
1402
+ polygon: { material: Color.YELLOW.withAlpha(.5) }
1403
+ })],
1404
+ render(options) {
1405
+ const { mouse, packable } = options;
1406
+ const entity = options.previous.entities?.[0] ?? new Entity({
1407
+ polyline: { material: Color.YELLOW.withAlpha(.5) },
1408
+ polygon: { material: Color.YELLOW.withAlpha(.5) }
1409
+ });
1410
+ const positions = [...packable.positions ?? []];
1411
+ mouse && positions.push(mouse);
1412
+ if (positions.length === 2) {
1413
+ entity.polygon.hierarchy = void 0;
1414
+ entity.polyline.positions = new CallbackProperty(() => positions, false);
1415
+ } else if (positions.length >= 3) {
1416
+ entity.polyline.positions = void 0;
1417
+ entity.polygon.hierarchy = new CallbackProperty(() => {
1418
+ positions.push(positions[0]);
1419
+ return positions.length >= 3 ? new PolygonHierarchy([...positions]) : void 0;
1420
+ }, false);
1421
+ } else {
1422
+ entity.polygon.hierarchy = void 0;
1423
+ entity.polyline.positions = void 0;
1424
+ }
1425
+ return { entities: [entity] };
1426
+ }
1396
1427
  });
1397
- const schemePolyline = new PlotScheme(
1398
- {
1399
- type: "polyline",
1400
- allowManualComplete: (packable) => packable.positions.length >= 2,
1401
- skeletons: [
1402
- control,
1403
- intervalNonclosed,
1404
- moved
1405
- ],
1406
- initEntites: () => [
1407
- new Entity({ polyline: { width: 1 } })
1408
- ],
1409
- render(options) {
1410
- var _a;
1411
- const { mouse, packable } = options;
1412
- const entity = ((_a = options.previous.entities) == null ? void 0 : _a[0]) ?? new Entity({ polyline: {} });
1413
- entity.polyline.positions = new CallbackProperty(() => {
1414
- const positions = [...packable.positions ?? []].concat(mouse ? [mouse] : []);
1415
- return positions.length >= 2 ? positions : [];
1416
- }, false);
1417
- return {
1418
- entities: [entity]
1419
- };
1420
- }
1421
- }
1422
- );
1428
+
1429
+ //#endregion
1430
+ //#region scheme/polyline.ts
1431
+ /**
1432
+ * 内置的线段标绘方案
1433
+ */
1434
+ const schemePolyline = new PlotScheme({
1435
+ type: "polyline",
1436
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1437
+ skeletons: [
1438
+ control,
1439
+ intervalNonclosed,
1440
+ moved
1441
+ ],
1442
+ initEntites: () => [new Entity({ polyline: { width: 1 } })],
1443
+ render(options) {
1444
+ const { mouse, packable } = options;
1445
+ const entity = options.previous.entities?.[0] ?? new Entity({ polyline: {} });
1446
+ entity.polyline.positions = new CallbackProperty(() => {
1447
+ const positions = [...packable.positions ?? []].concat(mouse ? [mouse] : []);
1448
+ return positions.length >= 2 ? positions : [];
1449
+ }, false);
1450
+ return { entities: [entity] };
1451
+ }
1452
+ });
1453
+
1454
+ //#endregion
1455
+ //#region scheme/rectangle.ts
1456
+ /**
1457
+ * 内置的多边形标绘方案
1458
+ */
1423
1459
  const schemeRectangle = new PlotScheme({
1424
- type: "rectangle",
1425
- complete: (packable) => packable.positions.length >= 2,
1426
- skeletons: [
1427
- control,
1428
- interval,
1429
- moved
1430
- ],
1431
- initEntites: () => [
1432
- new Entity({
1433
- rectangle: {
1434
- material: Color.YELLOW.withAlpha(0.5)
1435
- }
1436
- })
1437
- ],
1438
- render(options) {
1439
- var _a;
1440
- const { mouse, packable } = options;
1441
- const entity = ((_a = options.previous.entities) == null ? void 0 : _a[0]) ?? new Entity({
1442
- rectangle: {
1443
- material: Color.YELLOW.withAlpha(0.5)
1444
- }
1445
- });
1446
- const positions = [...packable.positions ?? []];
1447
- mouse && positions.push(mouse);
1448
- if (positions.length >= 2) {
1449
- entity.rectangle.coordinates = new CallbackProperty(() => Rectangle.fromCartesianArray(positions), false);
1450
- } else {
1451
- entity.rectangle.coordinates = void 0;
1452
- }
1453
- return {
1454
- entities: [entity]
1455
- };
1456
- }
1460
+ type: "rectangle",
1461
+ complete: (packable) => packable.positions.length >= 2,
1462
+ skeletons: [
1463
+ control,
1464
+ interval,
1465
+ moved
1466
+ ],
1467
+ initEntites: () => [new Entity({ rectangle: { material: Color.YELLOW.withAlpha(.5) } })],
1468
+ render(options) {
1469
+ const { mouse, packable } = options;
1470
+ const entity = options.previous.entities?.[0] ?? new Entity({ rectangle: { material: Color.YELLOW.withAlpha(.5) } });
1471
+ const positions = [...packable.positions ?? []];
1472
+ mouse && positions.push(mouse);
1473
+ if (positions.length >= 2) entity.rectangle.coordinates = new CallbackProperty(() => Rectangle.fromCartesianArray(positions), false);
1474
+ else entity.rectangle.coordinates = void 0;
1475
+ return { entities: [entity] };
1476
+ }
1457
1477
  });
1458
- export {
1459
- PlotAction,
1460
- PlotFeature,
1461
- PlotScheme,
1462
- PlotSkeletonEntity,
1463
- SampledPlotProperty,
1464
- SampledPlotStrategy,
1465
- control,
1466
- interval,
1467
- intervalNonclosed,
1468
- moved,
1469
- schemeBillboard,
1470
- schemeLabel,
1471
- schemeMeasureArea,
1472
- schemePolygon,
1473
- schemePolyline,
1474
- schemeRectangle,
1475
- usePlot
1476
- };
1477
- //# sourceMappingURL=index.mjs.map
1478
+
1479
+ //#endregion
1480
+ export { PlotAction, PlotFeature, PlotScheme, PlotSkeletonEntity, SampledPlotProperty, SampledPlotStrategy, control, interval, intervalNonclosed, moved, schemeBillboard, schemeLabel, schemeMeasureArea, schemePolygon, schemePolyline, schemeRectangle, usePlot };
1481
+ //# sourceMappingURL=index.mjs.map