@vesium/plot 1.0.1-beta.52 → 1.0.1-beta.57

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.
@@ -1,3029 +1,2041 @@
1
- (function(exports, cesium, vesium, __vueuse_core, vue, __turf_turf) {
1
+ (function(exports, cesium, vesium, __vueuse_core, vue, __vesium_geometry, __turf_turf) {
2
2
 
3
3
  //#region rolldown:runtime
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
- value: mod,
22
- enumerable: true
23
- }) : target, mod));
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) {
15
+ __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ }
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
24
28
 
25
29
  //#endregion
26
- cesium = __toESM(cesium);
27
- vesium = __toESM(vesium);
28
- __vueuse_core = __toESM(__vueuse_core);
29
- vue = __toESM(vue);
30
30
  __turf_turf = __toESM(__turf_turf);
31
31
 
32
32
  //#region usePlot/PlotScheme.ts
33
- var PlotScheme = class PlotScheme {
34
- constructor(options) {
35
- this.type = options.type;
36
- this.complete = options.complete;
37
- this.allowManualComplete = options.allowManualComplete;
38
- this.definingCursor = options.definingCursor ?? "crosshair";
39
- this.skeletons = options.skeletons?.map((item) => item()) ?? [];
40
- this.initRender = options.initRender;
41
- this.render = options.render;
42
- }
43
- /**
44
- * 标绘类型。应当是全局唯一的字符串,会作为键名缓存
45
- */
46
- type;
47
- /**
48
- * 判断是否立即完成标绘.
49
- * 每次控制点发生变变化时,执行该回调函数,返回`true`则完成标绘
50
- */
51
- complete;
52
- /**
53
- * 判断是否允许手动完成标绘。
54
- * 每次控制点发生变变化时,执行该回调函数,返回`true`则后续左键双击即完成标绘
55
- */
56
- allowManualComplete;
57
- /**
58
- * 处于定义态时鼠标的样式
59
- * @default 'crosshair'
60
- */
61
- definingCursor;
62
- /**
63
- * 当前标绘的框架点数据
64
- */
65
- skeletons;
66
- /**
67
- * 初始化时创建贴地`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
68
- */
69
- initRender;
70
- /**
71
- * 当标绘数据变化时,会触发`render`回调,返回的数据会被添加到cesium中
72
- */
73
- render;
74
- static _record = /* @__PURE__ */ new Map();
75
- /**
76
- * 标绘方案缓存。
77
- * 每次标绘时都会将`PlotScheme.type`作为键名缓存,
78
- * 后续可用过`PlotScheme.getCache(type)`获取完整的`PlotScheme`配置。
79
- */
80
- static getCacheTypes() {
81
- return [...this._record.keys()];
82
- }
83
- /**
84
- * 通过`PlotScheme.type`获取缓存中的`PlotScheme`配置。
85
- */
86
- static getCache(type) {
87
- return PlotScheme._record.get(type);
88
- }
89
- /**
90
- * 缓存标绘方案。
91
- */
92
- static setCache(scheme) {
93
- (0, vesium.assertError)(!scheme.type, "`scheme.type` is required");
94
- PlotScheme._record.set(scheme.type, scheme);
95
- }
96
- /**
97
- * 解析传入的maybeScheme,maybeScheme可能是一个完整的PlotScheme,也可能是缓存中的`PlotScheme.type`,并返回 PlotScheme 实例。
98
- * 若传入的是`PlotScheme.type`字符串,并且缓存中不存在该标绘方案,则抛出错误。
99
- */
100
- static resolve(maybeScheme) {
101
- if (typeof maybeScheme === "string") {
102
- const _scheme = PlotScheme.getCache(maybeScheme);
103
- (0, __vueuse_core.assert)(!!_scheme, `scheme ${maybeScheme} not found`);
104
- return _scheme;
105
- } else if (!(maybeScheme instanceof PlotScheme)) return new PlotScheme(maybeScheme);
106
- else return maybeScheme;
107
- }
108
- };
33
+ var PlotScheme = class PlotScheme {
34
+ constructor(options) {
35
+ this.type = options.type;
36
+ this.complete = options.complete;
37
+ this.allowManualComplete = options.allowManualComplete;
38
+ this.definingCursor = options.definingCursor ?? "crosshair";
39
+ this.skeletons = options.skeletons?.map((item) => item()) ?? [];
40
+ this.initRender = options.initRender;
41
+ this.render = options.render;
42
+ }
43
+ /**
44
+ * 标绘类型。应当是全局唯一的字符串,会作为键名缓存
45
+ */
46
+ type;
47
+ /**
48
+ * 判断是否立即完成标绘.
49
+ * 每次控制点发生变变化时,执行该回调函数,返回`true`则完成标绘
50
+ */
51
+ complete;
52
+ /**
53
+ * 判断是否允许手动完成标绘。
54
+ * 每次控制点发生变变化时,执行该回调函数,返回`true`则后续左键双击即完成标绘
55
+ */
56
+ allowManualComplete;
57
+ /**
58
+ * 处于定义态时鼠标的样式
59
+ * @default 'crosshair'
60
+ */
61
+ definingCursor;
62
+ /**
63
+ * 当前标绘的框架点数据
64
+ */
65
+ skeletons;
66
+ /**
67
+ * 初始化时创建贴地`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
68
+ */
69
+ initRender;
70
+ /**
71
+ * 当标绘数据变化时,会触发`render`回调,返回的数据会被添加到cesium中
72
+ */
73
+ render;
74
+ static _record = /* @__PURE__ */ new Map();
75
+ /**
76
+ * 标绘方案缓存。
77
+ * 每次标绘时都会将`PlotScheme.type`作为键名缓存,
78
+ * 后续可用过`PlotScheme.getCache(type)`获取完整的`PlotScheme`配置。
79
+ */
80
+ static getCacheTypes() {
81
+ return [...this._record.keys()];
82
+ }
83
+ /**
84
+ * 通过`PlotScheme.type`获取缓存中的`PlotScheme`配置。
85
+ */
86
+ static getCache(type) {
87
+ return PlotScheme._record.get(type);
88
+ }
89
+ /**
90
+ * 缓存标绘方案。
91
+ */
92
+ static setCache(scheme) {
93
+ (0, vesium.assertError)(!scheme.type, "`scheme.type` is required");
94
+ PlotScheme._record.set(scheme.type, scheme);
95
+ }
96
+ /**
97
+ * 解析传入的maybeScheme,maybeScheme可能是一个完整的PlotScheme,也可能是缓存中的`PlotScheme.type`,并返回 PlotScheme 实例。
98
+ * 若传入的是`PlotScheme.type`字符串,并且缓存中不存在该标绘方案,则抛出错误。
99
+ */
100
+ static resolve(maybeScheme) {
101
+ if (typeof maybeScheme === "string") {
102
+ const _scheme = PlotScheme.getCache(maybeScheme);
103
+ (0, __vueuse_core.assert)(!!_scheme, `scheme ${maybeScheme} not found`);
104
+ return _scheme;
105
+ } else if (!(maybeScheme instanceof PlotScheme)) return new PlotScheme(maybeScheme);
106
+ else return maybeScheme;
107
+ }
108
+ };
109
109
 
110
110
  //#endregion
111
111
  //#region usePlot/SampledPlotProperty.ts
112
- let SampledPlotStrategy = /* @__PURE__ */ function(SampledPlotStrategy$1) {
113
- SampledPlotStrategy$1[SampledPlotStrategy$1["NEAR"] = 0] = "NEAR";
114
- SampledPlotStrategy$1[SampledPlotStrategy$1["CYCLE"] = 1] = "CYCLE";
115
- SampledPlotStrategy$1[SampledPlotStrategy$1["STRICT"] = 2] = "STRICT";
116
- return SampledPlotStrategy$1;
117
- }({});
118
- /**
119
- * 默认插值算法
120
- *
121
- * @param time 时间
122
- * @param previous 前一个数据点
123
- * @param next 后一个数据点
124
- * @param proportion 比例
125
- * @returns 插值结果
126
- */
127
- const defaultInterpolationAlgorithm = (time, previous, next, proportion) => {
128
- if (proportion === 0) return {
129
- time,
130
- positions: previous.positions?.map((item) => item.clone()),
131
- derivative: previous.derivative
132
- };
133
- else if (proportion === 1) return {
134
- time,
135
- positions: next.positions?.map((item) => item.clone()),
136
- derivative: previous.derivative
137
- };
138
- return {
139
- time,
140
- positions: next.positions?.map((right, index) => {
141
- const left = previous.positions?.[index];
142
- return !left ? right : cesium.Cartesian3.lerp(left, right, proportion, new cesium.Cartesian3());
143
- }),
144
- derivative: previous.derivative
145
- };
146
- };
147
- /**
148
- * 标绘采样点数据。
149
- * 标绘采样点数据是一个时间序列数据,包含时间、位置和附带的额外数据。
150
- * 具体用法可参考 [Cesium.SampledProperty](https://cesium.com/learn/cesiumjs/ref-doc/SampledProperty.html)
151
- */
152
- var SampledPlotProperty = class SampledPlotProperty {
153
- constructor(options) {
154
- this.interpolationAlgorithm = options?.interpolationAlgorithm;
155
- this.strategy = options?.strategy ?? SampledPlotStrategy.NEAR;
156
- options?.packables?.forEach((packable) => this.setSample(packable));
157
- if (!this._times.length) this.setSample({
158
- time: new cesium.JulianDate(0, 0),
159
- positions: [],
160
- derivative: void 0
161
- });
162
- }
163
- static defaultInterpolationAlgorithm = defaultInterpolationAlgorithm;
164
- strategy;
165
- interpolationAlgorithm;
112
+ let SampledPlotStrategy = /* @__PURE__ */ function(SampledPlotStrategy$1) {
113
+ SampledPlotStrategy$1[SampledPlotStrategy$1["NEAR"] = 0] = "NEAR";
114
+ SampledPlotStrategy$1[SampledPlotStrategy$1["CYCLE"] = 1] = "CYCLE";
115
+ SampledPlotStrategy$1[SampledPlotStrategy$1["STRICT"] = 2] = "STRICT";
116
+ return SampledPlotStrategy$1;
117
+ }({});
166
118
  /**
167
- * @internal
168
- */
169
- _times = [];
170
- /**
171
- * @internal
172
- */
173
- _sampleds = [];
174
- /**
175
- * @internal
176
- */
177
- _derivatives = [];
178
- get isConstant() {
179
- return this._times.length === 0;
180
- }
181
- /**
182
- * @internal
183
- */
184
- _definitionChanged = new cesium.Event();
185
- get definitionChanged() {
186
- return this._definitionChanged;
187
- }
188
- /**
189
- * 获取时间数组
119
+ * 默认插值算法
190
120
  *
191
- * @returns 返回包含所有时间的 JulianDate 数组
121
+ * @param time 时间
122
+ * @param previous 前一个数据点
123
+ * @param next 后一个数据点
124
+ * @param proportion 比例
125
+ * @returns 插值结果
192
126
  */
193
- getTimes() {
194
- return this._times.map((t) => t.clone());
195
- }
196
- /**
197
- * 根据给定的儒略日期获取时间索引范围及比例
198
- *
199
- * @param time 给定的儒略日期
200
- * @returns 返回包含前一个索引、后一个索引及时间比例的对象,若不符合条件则返回undefined
201
- * @internal
202
- */
203
- getIndexScope(time) {
204
- if (!this._times.length) return;
205
- const start = this._times[0];
206
- const end = this._times[this._times.length - 1];
207
- if (cesium.JulianDate.lessThan(time, start) || cesium.JulianDate.greaterThan(time, end)) switch (this.strategy) {
208
- case SampledPlotStrategy.STRICT: return;
209
- case SampledPlotStrategy.NEAR: {
210
- time = cesium.JulianDate.lessThan(time, this._times[0]) ? this._times[0].clone() : this._times[this._times.length - 1].clone();
211
- break;
212
- }
213
- case SampledPlotStrategy.CYCLE: {
214
- const startMS = cesium.JulianDate.toDate(this._times[0]).getTime();
215
- const endMS = cesium.JulianDate.toDate(this._times[this._times.length - 1]).getTime();
216
- const duration = endMS - startMS;
217
- const timeMS = cesium.JulianDate.toDate(time).getTime();
218
- const diff = (timeMS - startMS) % duration;
219
- const dete = new Date(startMS + diff);
220
- time = cesium.JulianDate.fromDate(dete);
221
- break;
222
- }
223
- }
224
- const prevIndex = this._times.findIndex((t) => cesium.JulianDate.lessThanOrEquals(time, t));
225
- const nextIndex = Math.min(prevIndex, this._times.length - 1);
226
- const prevMs = cesium.JulianDate.toDate(this._times[prevIndex]).getTime();
227
- const nextMs = cesium.JulianDate.toDate(this._times[nextIndex]).getTime();
228
- const ms = cesium.JulianDate.toDate(time).getTime();
229
- return {
230
- prevIndex,
231
- nextIndex,
232
- proportion: (ms - prevMs) / (nextMs - prevMs) || 0
233
- };
234
- }
235
- /**
236
- * 根据给定的儒略日期(JulianDate)获取插值后的样本点数据。
237
- *
238
- * @param time 指定的儒略日期(JulianDate)。
239
- * @param result 可选参数,用于存储结果的容器。如果未提供,则创建一个新的容器。
240
- * @returns 插值后的样本点数据,存储在提供的或新创建的result容器中。
241
- * @template D 数据类型。
242
- */
243
- getValue(time, result) {
244
- result ??= {
127
+ const defaultInterpolationAlgorithm = (time, previous, next, proportion) => {
128
+ if (proportion === 0) return {
245
129
  time,
246
- positions: []
130
+ positions: previous.positions?.map((item) => item.clone()),
131
+ derivative: previous.derivative
247
132
  };
248
- Object.assign(result, {
249
- time: time?.clone(),
250
- positions: [],
251
- derivative: void 0
252
- });
253
- if (!time) {
254
- result.time = this._times[0].clone();
255
- result.positions = this._sampleds[0]?.map((c) => c.clone(c));
256
- result.derivative = this._derivatives[0];
257
- return result;
258
- }
259
- const scope = this.getIndexScope(time);
260
- if (!scope) return result;
261
- result.time = time;
262
- const { prevIndex, nextIndex, proportion } = scope;
263
- const previous = {
264
- time: this._times[prevIndex],
265
- positions: this._sampleds[prevIndex],
266
- derivative: this._derivatives[prevIndex]
133
+ else if (proportion === 1) return {
134
+ time,
135
+ positions: next.positions?.map((item) => item.clone()),
136
+ derivative: previous.derivative
267
137
  };
268
- const next = {
269
- time: this._times[nextIndex],
270
- positions: this._sampleds[nextIndex],
271
- derivative: this._derivatives[nextIndex]
138
+ return {
139
+ time,
140
+ positions: next.positions?.map((right, index) => {
141
+ const left = previous.positions?.[index];
142
+ return !left ? right : cesium.Cartesian3.lerp(left, right, proportion, new cesium.Cartesian3());
143
+ }),
144
+ derivative: previous.derivative
272
145
  };
273
- const packable = (this.interpolationAlgorithm || SampledPlotProperty.defaultInterpolationAlgorithm)(time, previous, next, proportion);
274
- Object.assign(result, packable);
275
- return result;
276
- }
146
+ };
277
147
  /**
278
- * 设置样本数据,如果传入的数据不含时间,则会存入时间最早的集合中
279
- * @param value 样本数据对象,包含时间、位置和导数信息
148
+ * 标绘采样点数据。
149
+ * 标绘采样点数据是一个时间序列数据,包含时间、位置和附带的额外数据。
150
+ * 具体用法可参考 [Cesium.SampledProperty](https://cesium.com/learn/cesiumjs/ref-doc/SampledProperty.html)
280
151
  */
281
- setSample(value) {
282
- const time = value.time?.clone() ?? this._times[0].clone();
283
- const positions = value.positions?.map((item) => item.clone()) ?? [];
284
- const derivative = value.derivative;
285
- const index = this._times.findIndex((t) => cesium.JulianDate.equals(time, t));
286
- if (index !== -1) {
287
- this._times[index] = time;
288
- this._sampleds[index] = positions;
289
- this._derivatives[index] = value.derivative;
290
- } else if (this._times.length === 0) {
291
- this._times[0] = time;
292
- this._sampleds[0] = positions;
293
- this._derivatives[0] = value.derivative;
294
- } else if (cesium.JulianDate.lessThan(time, this._times[0])) {
295
- this._times.splice(0, 0, time);
296
- this._sampleds.splice(0, 0, positions);
297
- this._derivatives.splice(0, 0, derivative);
298
- } else if (cesium.JulianDate.greaterThan(time, this._times[this._times.length - 1])) {
299
- this._times.push(time);
300
- this._sampleds.push(positions);
301
- this._derivatives.push(derivative);
152
+ var SampledPlotProperty = class SampledPlotProperty {
153
+ constructor(options) {
154
+ this.interpolationAlgorithm = options?.interpolationAlgorithm;
155
+ this.strategy = options?.strategy ?? SampledPlotStrategy.NEAR;
156
+ options?.packables?.forEach((packable) => this.setSample(packable));
157
+ if (!this._times.length) this.setSample({
158
+ time: new cesium.JulianDate(0, 0),
159
+ positions: [],
160
+ derivative: void 0
161
+ });
302
162
  }
303
- this.definitionChanged.raiseEvent(this);
304
- }
305
- /**
306
- * 设置样本数据
307
- *
308
- * @param values 样本数据数组,每个元素都是类型为SampledPlotPackable<D>的对象
309
- */
310
- setSamples(values) {
311
- values.forEach((value) => this.setSample(value));
312
- }
313
- /**
314
- * 从样本中移除指定时间点的数据
315
- *
316
- * @param time 需要移除的时间点,使用儒略日期表示
317
- * @returns 如果成功移除,则返回 true;否则返回 false
318
- */
319
- removeSample(time) {
320
- const index = this._times.findIndex((t) => t.equals(time));
321
- if (index !== -1) {
322
- this._sampleds.splice(index, 1);
323
- this._derivatives.splice(index, 1);
324
- const removed = this._times.splice(index, 1);
325
- if (removed.length) {
326
- this._definitionChanged.raiseEvent(this);
327
- return true;
163
+ static defaultInterpolationAlgorithm = defaultInterpolationAlgorithm;
164
+ strategy;
165
+ interpolationAlgorithm;
166
+ /**
167
+ * @internal
168
+ */
169
+ _times = [];
170
+ /**
171
+ * @internal
172
+ */
173
+ _sampleds = [];
174
+ /**
175
+ * @internal
176
+ */
177
+ _derivatives = [];
178
+ get isConstant() {
179
+ return this._times.length === 0;
180
+ }
181
+ /**
182
+ * @internal
183
+ */
184
+ _definitionChanged = new cesium.Event();
185
+ get definitionChanged() {
186
+ return this._definitionChanged;
187
+ }
188
+ /**
189
+ * 获取时间数组
190
+ *
191
+ * @returns 返回包含所有时间的 JulianDate 数组
192
+ */
193
+ getTimes() {
194
+ return this._times.map((t) => t.clone());
195
+ }
196
+ /**
197
+ * 根据给定的儒略日期获取时间索引范围及比例
198
+ *
199
+ * @param time 给定的儒略日期
200
+ * @returns 返回包含前一个索引、后一个索引及时间比例的对象,若不符合条件则返回undefined
201
+ * @internal
202
+ */
203
+ getIndexScope(time) {
204
+ if (!this._times.length) return;
205
+ const start = this._times[0];
206
+ const end = this._times[this._times.length - 1];
207
+ if (cesium.JulianDate.lessThan(time, start) || cesium.JulianDate.greaterThan(time, end)) switch (this.strategy) {
208
+ case SampledPlotStrategy.STRICT: return;
209
+ case SampledPlotStrategy.NEAR:
210
+ time = cesium.JulianDate.lessThan(time, this._times[0]) ? this._times[0].clone() : this._times[this._times.length - 1].clone();
211
+ break;
212
+ case SampledPlotStrategy.CYCLE: {
213
+ const startMS = cesium.JulianDate.toDate(this._times[0]).getTime();
214
+ const duration = cesium.JulianDate.toDate(this._times[this._times.length - 1]).getTime() - startMS;
215
+ const diff = (cesium.JulianDate.toDate(time).getTime() - startMS) % duration;
216
+ const dete = new Date(startMS + diff);
217
+ time = cesium.JulianDate.fromDate(dete);
218
+ break;
219
+ }
328
220
  }
221
+ const prevIndex = this._times.findIndex((t) => cesium.JulianDate.lessThanOrEquals(time, t));
222
+ const nextIndex = Math.min(prevIndex, this._times.length - 1);
223
+ const prevMs = cesium.JulianDate.toDate(this._times[prevIndex]).getTime();
224
+ const nextMs = cesium.JulianDate.toDate(this._times[nextIndex]).getTime();
225
+ return {
226
+ prevIndex,
227
+ nextIndex,
228
+ proportion: (cesium.JulianDate.toDate(time).getTime() - prevMs) / (nextMs - prevMs) || 0
229
+ };
329
230
  }
330
- return false;
331
- }
332
- /**
333
- * 从样本中移除指定时间间隔内的样本。
334
- *
335
- * @param interval 要移除样本的时间间隔
336
- */
337
- removeSamples(interval$1) {
338
- for (let i = 0; i < this._times.length; i++) {
339
- const time = this._times[i];
340
- cesium.TimeInterval.contains(interval$1, time) && this.removeSample(time);
231
+ /**
232
+ * 根据给定的儒略日期(JulianDate)获取插值后的样本点数据。
233
+ *
234
+ * @param time 指定的儒略日期(JulianDate)。
235
+ * @param result 可选参数,用于存储结果的容器。如果未提供,则创建一个新的容器。
236
+ * @returns 插值后的样本点数据,存储在提供的或新创建的result容器中。
237
+ * @template D 数据类型。
238
+ */
239
+ getValue(time, result) {
240
+ result ??= {
241
+ time,
242
+ positions: []
243
+ };
244
+ Object.assign(result, {
245
+ time: time?.clone(),
246
+ positions: [],
247
+ derivative: void 0
248
+ });
249
+ if (!time) {
250
+ result.time = this._times[0].clone();
251
+ result.positions = this._sampleds[0]?.map((c) => c.clone(c));
252
+ result.derivative = this._derivatives[0];
253
+ return result;
254
+ }
255
+ const scope = this.getIndexScope(time);
256
+ if (!scope) return result;
257
+ result.time = time;
258
+ const { prevIndex, nextIndex, proportion } = scope;
259
+ const previous = {
260
+ time: this._times[prevIndex],
261
+ positions: this._sampleds[prevIndex],
262
+ derivative: this._derivatives[prevIndex]
263
+ };
264
+ const next = {
265
+ time: this._times[nextIndex],
266
+ positions: this._sampleds[nextIndex],
267
+ derivative: this._derivatives[nextIndex]
268
+ };
269
+ const packable = (this.interpolationAlgorithm || SampledPlotProperty.defaultInterpolationAlgorithm)(time, previous, next, proportion);
270
+ Object.assign(result, packable);
271
+ return result;
341
272
  }
342
- }
343
- /**
344
- * 判断两个property是否相等
345
- */
346
- equals(other) {
347
- return other === this;
348
- }
349
- };
273
+ /**
274
+ * 设置样本数据,如果传入的数据不含时间,则会存入时间最早的集合中
275
+ * @param value 样本数据对象,包含时间、位置和导数信息
276
+ */
277
+ setSample(value) {
278
+ const time = value.time?.clone() ?? this._times[0].clone();
279
+ const positions = value.positions?.map((item) => item.clone()) ?? [];
280
+ const derivative = value.derivative;
281
+ const index = this._times.findIndex((t) => cesium.JulianDate.equals(time, t));
282
+ if (index !== -1) {
283
+ this._times[index] = time;
284
+ this._sampleds[index] = positions;
285
+ this._derivatives[index] = value.derivative;
286
+ } else if (this._times.length === 0) {
287
+ this._times[0] = time;
288
+ this._sampleds[0] = positions;
289
+ this._derivatives[0] = value.derivative;
290
+ } else if (cesium.JulianDate.lessThan(time, this._times[0])) {
291
+ this._times.splice(0, 0, time);
292
+ this._sampleds.splice(0, 0, positions);
293
+ this._derivatives.splice(0, 0, derivative);
294
+ } else if (cesium.JulianDate.greaterThan(time, this._times[this._times.length - 1])) {
295
+ this._times.push(time);
296
+ this._sampleds.push(positions);
297
+ this._derivatives.push(derivative);
298
+ }
299
+ this.definitionChanged.raiseEvent(this);
300
+ }
301
+ /**
302
+ * 设置样本数据
303
+ *
304
+ * @param values 样本数据数组,每个元素都是类型为SampledPlotPackable<D>的对象
305
+ */
306
+ setSamples(values) {
307
+ values.forEach((value) => this.setSample(value));
308
+ }
309
+ /**
310
+ * 从样本中移除指定时间点的数据
311
+ *
312
+ * @param time 需要移除的时间点,使用儒略日期表示
313
+ * @returns 如果成功移除,则返回 true;否则返回 false
314
+ */
315
+ removeSample(time) {
316
+ const index = this._times.findIndex((t) => t.equals(time));
317
+ if (index !== -1) {
318
+ this._sampleds.splice(index, 1);
319
+ this._derivatives.splice(index, 1);
320
+ if (this._times.splice(index, 1).length) {
321
+ this._definitionChanged.raiseEvent(this);
322
+ return true;
323
+ }
324
+ }
325
+ return false;
326
+ }
327
+ /**
328
+ * 从样本中移除指定时间间隔内的样本。
329
+ *
330
+ * @param interval 要移除样本的时间间隔
331
+ */
332
+ removeSamples(interval$1) {
333
+ for (let i = 0; i < this._times.length; i++) {
334
+ const time = this._times[i];
335
+ cesium.TimeInterval.contains(interval$1, time) && this.removeSample(time);
336
+ }
337
+ }
338
+ /**
339
+ * 判断两个property是否相等
340
+ */
341
+ equals(other) {
342
+ return other === this;
343
+ }
344
+ };
350
345
 
351
346
  //#endregion
352
347
  //#region usePlot/PlotFeature.ts
353
348
  /**
354
- * 标绘实例
355
- */
356
- var PlotFeature = class {
357
- constructor(options) {
358
- const { id, disabled = false, sampled } = options;
359
- this._id = id || (0, cesium.createGuid)();
360
- this._scheme = PlotScheme.resolve(options.scheme);
361
- this._definitionChanged = new cesium.Event();
362
- this._defining = true;
363
- this._disabled = disabled;
364
- this._sampled = sampled instanceof SampledPlotProperty ? sampled : new SampledPlotProperty(sampled);
365
- this._sampled.definitionChanged.addEventListener((property) => this._definitionChanged.raiseEvent(this, "sampled", property, property), this);
366
- const init = this._scheme.initRender?.() ?? {};
367
- this._entities = [...init.entities ?? []];
368
- this._primitives = [...init.primitives ?? []];
369
- this._groundPrimitives = [...init.groundPrimitives ?? []];
370
- this._skeletons = [];
371
- }
372
- /**
373
- * @internal
349
+ * 标绘实例
374
350
  */
375
- _id;
376
- get id() {
377
- return this._id;
378
- }
379
- /**
380
- * @internal
381
- */
382
- _scheme;
383
- get scheme() {
384
- return this._scheme;
385
- }
386
- /**
387
- * @internal
388
- */
389
- _definitionChanged;
390
- get definitionChanged() {
391
- return this._definitionChanged;
392
- }
393
- /**
394
- * @internal
395
- */
396
- _defining;
397
- get defining() {
398
- return this._defining;
399
- }
400
- /**
401
- * @internal
402
- */
403
- static setDefining(plot, value) {
404
- if (plot._defining !== value) {
405
- plot._definitionChanged.raiseEvent(plot, "defining", value, plot._defining);
406
- plot._defining = value;
351
+ var PlotFeature = class {
352
+ constructor(options) {
353
+ const { id, disabled = false, sampled } = options;
354
+ this._id = id || (0, cesium.createGuid)();
355
+ this._scheme = PlotScheme.resolve(options.scheme);
356
+ this._definitionChanged = new cesium.Event();
357
+ this._defining = true;
358
+ this._disabled = disabled;
359
+ this._sampled = sampled instanceof SampledPlotProperty ? sampled : new SampledPlotProperty(sampled);
360
+ this._sampled.definitionChanged.addEventListener((property) => this._definitionChanged.raiseEvent(this, "sampled", property, property), this);
361
+ const init = this._scheme.initRender?.() ?? {};
362
+ this._entities = [...init.entities ?? []];
363
+ this._primitives = [...init.primitives ?? []];
364
+ this._groundPrimitives = [...init.groundPrimitives ?? []];
365
+ this._skeletons = [];
407
366
  }
408
- }
409
- /**
410
- * @internal
411
- */
412
- _disabled;
413
- /**
414
- * 获取禁用状态
415
- *
416
- * 当为 `true` 时,标绘实例将停止响应交互和更新;
417
- * 为 `false` 时恢复正常功能。
418
- */
419
- get disabled() {
420
- return this._disabled;
421
- }
422
- set disabled(value) {
423
- this.disabled = value;
424
- }
425
- /**
426
- * @internal
427
- */
428
- _sampled;
429
- get sampled() {
430
- return this._sampled;
431
- }
432
- /**
433
- * @internal
434
- */
435
- _entities;
436
- get entities() {
437
- return this._entities;
438
- }
439
- set entities(value) {
440
- this._definitionChanged.raiseEvent(this, "entities", value, this._entities);
441
- this._entities = value;
442
- }
443
- /**
444
- * @internal
445
- */
446
- _primitives;
447
- get primitives() {
448
- return this._primitives;
449
- }
450
- /**
451
- * @internal
452
- */
453
- set primitives(value) {
454
- this._definitionChanged.raiseEvent(this, "primitives", value, this._primitives);
455
- this._primitives = value;
456
- }
457
- /**
458
- * @internal
459
- */
460
- _groundPrimitives;
461
- get groundPrimitives() {
462
- return this._groundPrimitives;
463
- }
464
- /**
465
- * @internal
466
- */
467
- set groundPrimitives(value) {
468
- this._definitionChanged.raiseEvent(this, "groundPrimitives", value, this._groundPrimitives);
469
- this._groundPrimitives = value;
470
- }
471
- /**
472
- * @internal
473
- */
474
- _skeletons;
475
- get skeletons() {
476
- return this._skeletons;
477
- }
478
- /**
479
- * @internal
480
- */
481
- set skeletons(value) {
482
- this._definitionChanged.raiseEvent(this, "skeletons", value, this._skeletons);
483
- this._skeletons = value;
484
- }
485
- };
367
+ /**
368
+ * @internal
369
+ */
370
+ _id;
371
+ get id() {
372
+ return this._id;
373
+ }
374
+ /**
375
+ * @internal
376
+ */
377
+ _scheme;
378
+ get scheme() {
379
+ return this._scheme;
380
+ }
381
+ /**
382
+ * @internal
383
+ */
384
+ _definitionChanged;
385
+ get definitionChanged() {
386
+ return this._definitionChanged;
387
+ }
388
+ /**
389
+ * @internal
390
+ */
391
+ _defining;
392
+ get defining() {
393
+ return this._defining;
394
+ }
395
+ /**
396
+ * @internal
397
+ */
398
+ static setDefining(plot, value) {
399
+ if (plot._defining !== value) {
400
+ plot._definitionChanged.raiseEvent(plot, "defining", value, plot._defining);
401
+ plot._defining = value;
402
+ }
403
+ }
404
+ /**
405
+ * @internal
406
+ */
407
+ _disabled;
408
+ /**
409
+ * 获取禁用状态
410
+ *
411
+ * 当为 `true` 时,标绘实例将停止响应交互和更新;
412
+ * `false` 时恢复正常功能。
413
+ */
414
+ get disabled() {
415
+ return this._disabled;
416
+ }
417
+ set disabled(value) {
418
+ this.disabled = value;
419
+ }
420
+ /**
421
+ * @internal
422
+ */
423
+ _sampled;
424
+ get sampled() {
425
+ return this._sampled;
426
+ }
427
+ /**
428
+ * @internal
429
+ */
430
+ _entities;
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
+ /**
439
+ * @internal
440
+ */
441
+ _primitives;
442
+ get primitives() {
443
+ return this._primitives;
444
+ }
445
+ /**
446
+ * @internal
447
+ */
448
+ set primitives(value) {
449
+ this._definitionChanged.raiseEvent(this, "primitives", value, this._primitives);
450
+ this._primitives = value;
451
+ }
452
+ /**
453
+ * @internal
454
+ */
455
+ _groundPrimitives;
456
+ get groundPrimitives() {
457
+ return this._groundPrimitives;
458
+ }
459
+ /**
460
+ * @internal
461
+ */
462
+ set groundPrimitives(value) {
463
+ this._definitionChanged.raiseEvent(this, "groundPrimitives", value, this._groundPrimitives);
464
+ this._groundPrimitives = value;
465
+ }
466
+ /**
467
+ * @internal
468
+ */
469
+ _skeletons;
470
+ get skeletons() {
471
+ return this._skeletons;
472
+ }
473
+ /**
474
+ * @internal
475
+ */
476
+ set skeletons(value) {
477
+ this._definitionChanged.raiseEvent(this, "skeletons", value, this._skeletons);
478
+ this._skeletons = value;
479
+ }
480
+ };
486
481
 
487
482
  //#endregion
488
483
  //#region usePlot/PlotSkeleton.ts
489
484
  /**
490
- * 框架点执行状态枚举
491
- * - IDLE 空闲状态
492
- * - HOVER 悬停状态
493
- * - ACTIVE 激活状态
494
- */
495
- let PlotAction = /* @__PURE__ */ function(PlotAction$1) {
496
- PlotAction$1[PlotAction$1["IDLE"] = 0] = "IDLE";
497
- PlotAction$1[PlotAction$1["HOVER"] = 1] = "HOVER";
498
- PlotAction$1[PlotAction$1["ACTIVE"] = 2] = "ACTIVE";
499
- return PlotAction$1;
500
- }({});
501
- /**
502
- * 标绘框架点 Entity
503
- */
504
- var PlotSkeletonEntity = class extends cesium.Entity {
505
- constructor(options) {
506
- super(options);
507
- }
508
- };
485
+ * 框架点执行状态枚举
486
+ * - IDLE 空闲状态
487
+ * - HOVER 悬停状态
488
+ * - ACTIVE 激活状态
489
+ */
490
+ let PlotAction = /* @__PURE__ */ function(PlotAction$1) {
491
+ PlotAction$1[PlotAction$1["IDLE"] = 0] = "IDLE";
492
+ PlotAction$1[PlotAction$1["HOVER"] = 1] = "HOVER";
493
+ PlotAction$1[PlotAction$1["ACTIVE"] = 2] = "ACTIVE";
494
+ return PlotAction$1;
495
+ }({});
496
+ /**
497
+ * 标绘框架点 Entity
498
+ */
499
+ var PlotSkeletonEntity = class extends cesium.Entity {
500
+ constructor(options) {
501
+ super(options);
502
+ }
503
+ };
509
504
 
510
505
  //#endregion
511
506
  //#region usePlot/useRender.ts
512
- function useRender(plots, current, getCurrentTime) {
513
- const viewer = (0, vesium.useViewer)();
514
- const primitiveCollection = (0, vesium.usePrimitive)(new cesium.PrimitiveCollection());
515
- const groundPrimitiveCollection = (0, vesium.usePrimitive)(new cesium.PrimitiveCollection(), { collection: "ground" });
516
- const dataSource = (0, vesium.useDataSource)(new cesium.CustomDataSource());
517
- const entityScope = (0, vesium.useEntityScope)({ collection: () => dataSource.value.entities });
518
- const primitiveScope = (0, vesium.usePrimitiveScope)({ collection: () => primitiveCollection.value });
519
- const groundPrimitiveScope = (0, vesium.usePrimitiveScope)({ collection: () => groundPrimitiveCollection.value });
520
- const mouseCartesian = (0, vue.shallowRef)();
521
- (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.MOUSE_MOVE, (event) => {
522
- mouseCartesian.value = (0, vesium.canvasCoordToCartesian)(event?.endPosition, viewer.value.scene);
523
- });
524
- (0, __vueuse_core.watchArray)(plots, (_value, _oldValue, added, removed = []) => {
525
- removed.forEach((plot) => {
526
- entityScope.removeWhere((item) => plot.entities.includes(item));
527
- primitiveScope.removeWhere((item) => plot.primitives.includes(item));
528
- groundPrimitiveScope.removeWhere((item) => plot.groundPrimitives.includes(item));
507
+ function useRender(plots, current, getCurrentTime) {
508
+ const viewer = (0, vesium.useViewer)();
509
+ const primitiveCollection = (0, vesium.usePrimitive)(new cesium.PrimitiveCollection());
510
+ const groundPrimitiveCollection = (0, vesium.usePrimitive)(new cesium.PrimitiveCollection(), { collection: "ground" });
511
+ const dataSource = (0, vesium.useDataSource)(new cesium.CustomDataSource());
512
+ const entityScope = (0, vesium.useEntityScope)({ collection: () => dataSource.value.entities });
513
+ const primitiveScope = (0, vesium.usePrimitiveScope)({ collection: () => primitiveCollection.value });
514
+ const groundPrimitiveScope = (0, vesium.usePrimitiveScope)({ collection: () => groundPrimitiveCollection.value });
515
+ const mouseCartesian = (0, vue.shallowRef)();
516
+ (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.MOUSE_MOVE, (event) => {
517
+ mouseCartesian.value = (0, vesium.canvasCoordToCartesian)(event?.endPosition, viewer.value.scene);
529
518
  });
530
- added.forEach((plot) => {
531
- plot.entities.forEach((item) => entityScope.add(item));
532
- plot.primitives.forEach((item) => primitiveScope.add(item));
533
- plot.groundPrimitives.forEach((item) => groundPrimitiveScope.add(item));
519
+ (0, __vueuse_core.watchArray)(plots, (_value, _oldValue, added, removed = []) => {
520
+ removed.forEach((plot) => {
521
+ entityScope.removeWhere((item) => plot.entities.includes(item));
522
+ primitiveScope.removeWhere((item) => plot.primitives.includes(item));
523
+ groundPrimitiveScope.removeWhere((item) => plot.groundPrimitives.includes(item));
524
+ });
525
+ added.forEach((plot) => {
526
+ plot.entities.forEach((item) => entityScope.add(item));
527
+ plot.primitives.forEach((item) => primitiveScope.add(item));
528
+ plot.groundPrimitives.forEach((item) => groundPrimitiveScope.add(item));
529
+ });
530
+ }, {
531
+ immediate: true,
532
+ flush: "post"
534
533
  });
535
- }, {
536
- immediate: true,
537
- flush: "post"
538
- });
539
- (0, vesium.useCesiumEventListener)(() => plots.value.map((item) => item.definitionChanged), (_scope, key, newValue, oldValue) => {
540
- if (key === "entities") {
541
- const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
542
- added.forEach((item) => entityScope.add(item));
543
- removed.forEach((item) => entityScope.remove(item));
544
- } else if (key === "primitives") {
545
- const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
546
- added.forEach((item) => primitiveScope.add(item));
547
- removed.forEach((item) => primitiveScope.remove(item));
548
- } else if (key === "groundPrimitives") {
549
- const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
550
- added.forEach((item) => groundPrimitiveScope.add(item));
551
- removed.forEach((item) => groundPrimitiveScope.remove(item));
552
- }
553
- });
554
- const update = async (plot) => {
555
- const reslut = await plot.scheme.render?.({
556
- packable: plot.sampled.getValue(getCurrentTime()),
557
- mouse: plot.defining ? mouseCartesian.value : void 0,
558
- defining: plot.defining,
559
- previous: {
560
- entities: plot.entities,
561
- primitives: plot.primitives,
562
- groundPrimitives: plot.groundPrimitives
534
+ (0, vesium.useCesiumEventListener)(() => plots.value.map((item) => item.definitionChanged), (_scope, key, newValue, oldValue) => {
535
+ if (key === "entities") {
536
+ const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
537
+ added.forEach((item) => entityScope.add(item));
538
+ removed.forEach((item) => entityScope.remove(item));
539
+ } else if (key === "primitives") {
540
+ const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
541
+ added.forEach((item) => primitiveScope.add(item));
542
+ removed.forEach((item) => primitiveScope.remove(item));
543
+ } else if (key === "groundPrimitives") {
544
+ const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
545
+ added.forEach((item) => groundPrimitiveScope.add(item));
546
+ removed.forEach((item) => groundPrimitiveScope.remove(item));
563
547
  }
564
548
  });
565
- plot.entities = reslut?.entities ?? [];
566
- plot.primitives = reslut?.primitives ?? [];
567
- plot.groundPrimitives = reslut?.groundPrimitives ?? [];
568
- };
569
- (0, vue.watch)(current, (plot, previous) => {
570
- previous && update(previous);
571
- });
572
- (0, vesium.useCesiumEventListener)(() => plots.value.map((item) => item.definitionChanged), (plot, key) => {
573
- if ([
574
- "disabled",
575
- "defining",
576
- "scheme",
577
- "sampled",
578
- "time"
579
- ].includes(key)) update(plot);
580
- });
581
- (0, vue.watch)(mouseCartesian, () => {
582
- plots.value.forEach((plot) => plot.defining && update(plot));
583
- });
584
- return {
585
- primitives: (0, vue.computed)(() => Array.from(primitiveScope.scope)),
586
- groundPrimitives: (0, vue.computed)(() => Array.from(primitiveScope.scope)),
587
- entities: (0, vue.computed)(() => Array.from(entityScope.scope))
588
- };
589
- }
549
+ const update = async (plot) => {
550
+ await (0, vue.nextTick)();
551
+ const packable = plot.sampled.getValue(getCurrentTime());
552
+ const mouse = plot.defining ? mouseCartesian.value : void 0;
553
+ const result = await plot.scheme.render?.({
554
+ packable,
555
+ mouse,
556
+ defining: plot.defining,
557
+ previous: {
558
+ entities: plot.entities,
559
+ primitives: plot.primitives,
560
+ groundPrimitives: plot.groundPrimitives
561
+ },
562
+ getPositions() {
563
+ const points = packable.positions;
564
+ mouse && points.push(mouse);
565
+ return points;
566
+ }
567
+ });
568
+ plot.entities = result?.entities ?? [];
569
+ plot.primitives = result?.primitives ?? [];
570
+ plot.groundPrimitives = result?.groundPrimitives ?? [];
571
+ };
572
+ (0, vue.watch)(current, (plot, previous) => {
573
+ previous && update(previous);
574
+ });
575
+ (0, vesium.useCesiumEventListener)(() => plots.value.map((item) => item.definitionChanged), (plot, key) => {
576
+ if ([
577
+ "disabled",
578
+ "defining",
579
+ "scheme",
580
+ "sampled",
581
+ "time"
582
+ ].includes(key)) update(plot);
583
+ });
584
+ (0, vue.watch)(mouseCartesian, () => {
585
+ plots.value.forEach((plot) => plot.defining && update(plot));
586
+ });
587
+ return {
588
+ primitives: (0, vue.computed)(() => Array.from(primitiveScope.scope)),
589
+ groundPrimitives: (0, vue.computed)(() => Array.from(primitiveScope.scope)),
590
+ entities: (0, vue.computed)(() => Array.from(entityScope.scope))
591
+ };
592
+ }
590
593
 
591
594
  //#endregion
592
595
  //#region usePlot/useSampled.ts
593
- function useSampled(current, getCurrentTime) {
594
- const viewer = (0, vesium.useViewer)();
595
- const doubleClicking = (0, vue.ref)(false);
596
- const packable = (0, vue.computed)(() => {
597
- return current.value?.sampled.getValue(getCurrentTime());
598
- });
599
- (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_CLICK, async (ctx) => {
600
- await (0, __vueuse_core.promiseTimeout)(1);
601
- if (!current.value || !packable.value) return;
602
- if (doubleClicking.value) return;
603
- const { scheme, defining, sampled } = current.value;
604
- if (!defining) return;
605
- const position = (0, vesium.canvasCoordToCartesian)(ctx.position, viewer.value.scene);
606
- if (!position) return;
607
- packable.value.positions ??= [];
608
- packable.value.positions.push(position);
609
- sampled.setSample(packable.value);
610
- const completed = scheme.complete?.(packable.value);
611
- completed && PlotFeature.setDefining(current.value, false);
612
- });
613
- (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, async (ctx) => {
614
- if (!current.value || !packable.value) return;
615
- doubleClicking.value = true;
616
- await (0, __vueuse_core.promiseTimeout)(2);
617
- doubleClicking.value = false;
618
- const { scheme, defining } = current.value;
619
- if (!defining) return;
620
- const position = (0, vesium.canvasCoordToCartesian)(ctx.position, viewer.value.scene);
621
- if (!position) return;
622
- const completed = scheme.allowManualComplete?.(packable.value);
623
- completed && PlotFeature.setDefining(current.value, false);
624
- });
625
- (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.RIGHT_CLICK, async () => {
626
- if (!current.value || !packable.value) return;
627
- const { defining, sampled } = current.value;
628
- if (!defining) return;
629
- packable.value.positions ??= [];
630
- if (packable.value.positions.length === 0) return;
631
- packable.value.positions.splice(packable.value.positions.length - 1, 1);
632
- sampled.setSample(packable.value);
633
- });
634
- const definingCursorCss = (0, vue.ref)();
635
- const setDefiningCursorCss = () => {
636
- if (!current.value?.defining) {
637
- if (definingCursorCss.value) {
638
- definingCursorCss.value = void 0;
639
- viewer.value.container.parentElement.style.removeProperty("cursor");
596
+ function useSampled(current, getCurrentTime) {
597
+ const viewer = (0, vesium.useViewer)();
598
+ const doubleClicking = (0, vue.ref)(false);
599
+ const packable = (0, vue.computed)(() => {
600
+ return current.value?.sampled.getValue(getCurrentTime());
601
+ });
602
+ (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_CLICK, async (ctx) => {
603
+ await (0, __vueuse_core.promiseTimeout)(1);
604
+ if (!current.value || !packable.value) return;
605
+ if (doubleClicking.value) return;
606
+ const { scheme, defining, sampled } = current.value;
607
+ if (!defining) return;
608
+ const position = (0, vesium.canvasCoordToCartesian)(ctx.position, viewer.value.scene);
609
+ if (!position) return;
610
+ packable.value.positions ??= [];
611
+ packable.value.positions.push(position);
612
+ sampled.setSample(packable.value);
613
+ scheme.complete?.(packable.value) && PlotFeature.setDefining(current.value, false);
614
+ });
615
+ (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, async (ctx) => {
616
+ if (!current.value || !packable.value) return;
617
+ doubleClicking.value = true;
618
+ await (0, __vueuse_core.promiseTimeout)(2);
619
+ doubleClicking.value = false;
620
+ const { scheme, defining } = current.value;
621
+ if (!defining) return;
622
+ if (!(0, vesium.canvasCoordToCartesian)(ctx.position, viewer.value.scene)) return;
623
+ scheme.allowManualComplete?.(packable.value) && PlotFeature.setDefining(current.value, false);
624
+ });
625
+ (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.RIGHT_CLICK, async () => {
626
+ if (!current.value || !packable.value) return;
627
+ const { defining, sampled } = current.value;
628
+ if (!defining) return;
629
+ packable.value.positions ??= [];
630
+ if (packable.value.positions.length === 0) return;
631
+ packable.value.positions.splice(packable.value.positions.length - 1, 1);
632
+ sampled.setSample(packable.value);
633
+ });
634
+ const definingCursorCss = (0, vue.ref)();
635
+ const setDefiningCursorCss = () => {
636
+ if (!current.value?.defining) {
637
+ if (definingCursorCss.value) {
638
+ definingCursorCss.value = void 0;
639
+ viewer.value.container.parentElement.style.removeProperty("cursor");
640
+ }
641
+ } else {
642
+ const definingCursor = current.value.scheme.definingCursor;
643
+ definingCursorCss.value = (0, vesium.isFunction)(definingCursor) ? definingCursor(packable.value) : definingCursor;
644
+ if (definingCursorCss.value) viewer.value?.container.parentElement.style.setProperty("cursor", definingCursorCss.value);
640
645
  }
641
- } else {
642
- const definingCursor = current.value.scheme.definingCursor;
643
- definingCursorCss.value = (0, vesium.isFunction)(definingCursor) ? definingCursor(packable.value) : definingCursor;
644
- if (definingCursorCss.value) viewer.value?.container.parentElement.style.setProperty("cursor", definingCursorCss.value);
645
- }
646
- };
647
- (0, vesium.useCesiumEventListener)(() => current.value?.definitionChanged, (plot, key) => {
648
- if (key === "defining" || key === "sampled") setDefiningCursorCss();
649
- });
650
- (0, vue.watch)(current, () => setDefiningCursorCss());
651
- }
646
+ };
647
+ (0, vesium.useCesiumEventListener)(() => current.value?.definitionChanged, (plot, key) => {
648
+ if (key === "defining" || key === "sampled") setDefiningCursorCss();
649
+ });
650
+ (0, vue.watch)(current, () => setDefiningCursorCss());
651
+ }
652
652
 
653
653
  //#endregion
654
654
  //#region usePlot/useSkeleton.ts
655
- function useSkeleton(plots, current, getCurrentTime) {
656
- const viewer = (0, vesium.useViewer)();
657
- const dataSource = (0, vesium.useDataSource)(new cesium.CustomDataSource());
658
- const entityScope = (0, vesium.useEntityScope)({ collection: () => dataSource.value.entities });
659
- const hoverEntity = (0, vue.shallowRef)();
660
- const activeEntity = (0, vue.shallowRef)();
661
- const getPointAction = (entity) => {
662
- if (!entity) return PlotAction.IDLE;
663
- return activeEntity.value?.id === entity.id ? PlotAction.ACTIVE : hoverEntity.value?.id === entity.id ? PlotAction.HOVER : PlotAction.IDLE;
664
- };
665
- const update = (plot, destroyed) => {
666
- const oldEntities = plot.skeletons;
667
- const entities = [];
668
- if (destroyed || plot.disabled) plot.skeletons = [];
669
- else {
670
- const packable = plot.sampled.getValue(getCurrentTime());
671
- const defining = plot.defining;
672
- const active = current.value === plot;
673
- const skeletons = plot.scheme.skeletons;
674
- skeletons.forEach((skeleton) => {
675
- const disabled = (0, vesium.isFunction)(skeleton.disabled) ? skeleton.disabled({
676
- active,
677
- defining
678
- }) : skeleton.disabled;
679
- if (disabled) return;
680
- const positions = skeleton.format?.(packable) ?? packable?.positions ?? [];
681
- positions.forEach((position, index) => {
682
- let entity = oldEntities.find((item) => item.index === index && item.skeleton === skeleton);
683
- const options = skeleton.render?.({
684
- defining,
655
+ function useSkeleton(plots, current, getCurrentTime) {
656
+ const viewer = (0, vesium.useViewer)();
657
+ const dataSource = (0, vesium.useDataSource)(new cesium.CustomDataSource());
658
+ const entityScope = (0, vesium.useEntityScope)({ collection: () => dataSource.value.entities });
659
+ const hoverEntity = (0, vue.shallowRef)();
660
+ const activeEntity = (0, vue.shallowRef)();
661
+ const getPointAction = (entity) => {
662
+ if (!entity) return PlotAction.IDLE;
663
+ return activeEntity.value?.id === entity.id ? PlotAction.ACTIVE : hoverEntity.value?.id === entity.id ? PlotAction.HOVER : PlotAction.IDLE;
664
+ };
665
+ const update = (plot, destroyed) => {
666
+ const oldEntities = plot.skeletons;
667
+ const entities = [];
668
+ if (destroyed || plot.disabled) plot.skeletons = [];
669
+ else {
670
+ const packable = plot.sampled.getValue(getCurrentTime());
671
+ const defining = plot.defining;
672
+ const active = current.value === plot;
673
+ plot.scheme.skeletons.forEach((skeleton) => {
674
+ if ((0, vesium.isFunction)(skeleton.disabled) ? skeleton.disabled({
685
675
  active,
686
- index,
687
- packable,
688
- positions,
689
- position,
690
- action: getPointAction(entity)
691
- });
692
- const merge = new PlotSkeletonEntity(options ?? {});
693
- if (entity) merge.propertyNames.forEach((key) => {
694
- if (key !== "id") entity[key] = merge[key];
676
+ defining
677
+ }) : skeleton.disabled) return;
678
+ const positions = skeleton.format?.(packable) ?? packable?.positions ?? [];
679
+ positions.forEach((position, index) => {
680
+ let entity = oldEntities.find((item) => item.index === index && item.skeleton === skeleton);
681
+ const options = skeleton.render?.({
682
+ defining,
683
+ active,
684
+ index,
685
+ packable,
686
+ positions,
687
+ position,
688
+ action: getPointAction(entity)
689
+ });
690
+ const merge = new PlotSkeletonEntity(options ?? {});
691
+ if (entity) merge.propertyNames.forEach((key) => {
692
+ if (key !== "id") entity[key] = merge[key];
693
+ });
694
+ else entity = merge;
695
+ entity.plot = plot;
696
+ entity.skeleton = skeleton;
697
+ entity.index = index;
698
+ entities.push(entity);
695
699
  });
696
- else entity = merge;
697
- entity.plot = plot;
698
- entity.skeleton = skeleton;
699
- entity.index = index;
700
- entities.push(entity);
701
700
  });
702
- });
703
- }
704
- plot.skeletons = entities;
705
- };
706
- const { addGraphicEvent } = (0, vesium.useGraphicEvent)();
707
- (0, vue.watchEffect)((onCleanup) => {
708
- const remove = addGraphicEvent("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
709
- if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
710
- const entity = pick.id;
701
+ }
702
+ plot.skeletons = entities;
703
+ };
704
+ const graphicEvent = (0, vesium.useGraphicEvent)();
705
+ (0, vue.watchEffect)((onCleanup) => {
706
+ onCleanup(graphicEvent.add("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
707
+ if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
708
+ const entity = pick.id;
709
+ const plot = entity.plot;
710
+ if (plot.defining) return;
711
+ activeEntity.value = entity;
712
+ const skeleton = entity.skeleton;
713
+ const index = entity.index;
714
+ const packable = plot.sampled.getValue(getCurrentTime());
715
+ skeleton.onDrag?.({
716
+ viewer: viewer.value,
717
+ sampled: plot.sampled,
718
+ packable,
719
+ active: current.value === plot,
720
+ index,
721
+ event,
722
+ dragging,
723
+ lockCamera
724
+ });
725
+ } else activeEntity.value = void 0;
726
+ }, {
727
+ cursor: ({ pick }) => {
728
+ if (!current.value?.defining && entityScope.scope.has(pick.id)) {
729
+ const skeleton = pick.id.skeleton;
730
+ return (0, vesium.isFunction)(skeleton?.cursor) ? skeleton.cursor(pick) : (0, vue.toValue)(skeleton?.cursor);
731
+ }
732
+ },
733
+ dragCursor: ({ pick }) => {
734
+ if (!current.value?.defining && entityScope.scope.has(pick.id)) {
735
+ const skeleton = pick.id.skeleton;
736
+ return (0, vesium.isFunction)(skeleton?.dragCursor) ? skeleton.dragCursor(pick) : (0, vue.toValue)(skeleton?.dragCursor);
737
+ }
738
+ }
739
+ }));
740
+ });
741
+ (0, __vueuse_core.onKeyStroke)((keyEvent) => {
742
+ if (activeEntity.value) {
743
+ const entity = activeEntity.value;
711
744
  const plot = entity.plot;
712
- if (plot.defining) return;
713
- activeEntity.value = entity;
714
745
  const skeleton = entity.skeleton;
715
746
  const index = entity.index;
716
747
  const packable = plot.sampled.getValue(getCurrentTime());
717
- skeleton.onDrag?.({
748
+ skeleton.onKeyPressed?.({
718
749
  viewer: viewer.value,
719
750
  sampled: plot.sampled,
720
751
  packable,
721
- active: current.value === plot,
722
752
  index,
723
- event,
724
- dragging,
725
- lockCamera
753
+ keyEvent
726
754
  });
727
- } else activeEntity.value = void 0;
728
- }, {
729
- cursor: ({ pick }) => {
730
- if (!current.value?.defining && entityScope.scope.has(pick.id)) {
731
- const skeleton = pick.id.skeleton;
732
- return (0, vesium.isFunction)(skeleton?.cursor) ? skeleton.cursor(pick) : (0, vue.toValue)(skeleton?.cursor);
733
- }
734
- },
735
- dragCursor: ({ pick }) => {
736
- if (!current.value?.defining && entityScope.scope.has(pick.id)) {
737
- const skeleton = pick.id.skeleton;
738
- return (0, vesium.isFunction)(skeleton?.dragCursor) ? skeleton.dragCursor(pick) : (0, vue.toValue)(skeleton?.dragCursor);
739
- }
740
755
  }
741
756
  });
742
- onCleanup(remove);
743
- });
744
- (0, __vueuse_core.onKeyStroke)((keyEvent) => {
745
- if (activeEntity.value) {
746
- const entity = activeEntity.value;
747
- const plot = entity.plot;
748
- const skeleton = entity.skeleton;
749
- const index = entity.index;
750
- const packable = plot.sampled.getValue(getCurrentTime());
751
- skeleton.onKeyPressed?.({
752
- viewer: viewer.value,
753
- sampled: plot.sampled,
754
- packable,
755
- index,
756
- keyEvent
757
- });
758
- }
759
- });
760
- (0, vue.watchEffect)((onCleanup) => {
761
- const remove = addGraphicEvent("global", "HOVER", ({ hovering, pick }) => {
762
- if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
763
- const entity = pick.id;
764
- hoverEntity.value = entity;
765
- } else hoverEntity.value = void 0;
757
+ (0, vue.watchEffect)((onCleanup) => {
758
+ onCleanup(graphicEvent.add("global", "HOVER", ({ hovering, pick }) => {
759
+ if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) hoverEntity.value = pick.id;
760
+ else hoverEntity.value = void 0;
761
+ }));
766
762
  });
767
- onCleanup(remove);
768
- });
769
- (0, vue.watchEffect)((onCleanup) => {
770
- const remove = addGraphicEvent("global", "LEFT_CLICK", ({ event, pick }) => {
771
- if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
772
- const entity = pick.id;
773
- activeEntity.value = entity;
774
- const plot = entity.plot;
775
- const skeleton = entity.skeleton;
776
- const index = entity.index;
777
- const packable = plot.sampled.getValue(getCurrentTime());
778
- skeleton.onLeftClick?.({
779
- viewer: viewer.value,
780
- sampled: plot.sampled,
781
- packable,
782
- active: current.value === plot,
783
- defining: plot.defining,
784
- index,
785
- event
786
- });
787
- } else activeEntity.value = void 0;
763
+ (0, vue.watchEffect)((onCleanup) => {
764
+ onCleanup(graphicEvent.add("global", "LEFT_CLICK", ({ event, pick }) => {
765
+ if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
766
+ const entity = pick.id;
767
+ activeEntity.value = entity;
768
+ const plot = entity.plot;
769
+ const skeleton = entity.skeleton;
770
+ const index = entity.index;
771
+ const packable = plot.sampled.getValue(getCurrentTime());
772
+ skeleton.onLeftClick?.({
773
+ viewer: viewer.value,
774
+ sampled: plot.sampled,
775
+ packable,
776
+ active: current.value === plot,
777
+ defining: plot.defining,
778
+ index,
779
+ event
780
+ });
781
+ } else activeEntity.value = void 0;
782
+ }));
788
783
  });
789
- onCleanup(remove);
790
- });
791
- (0, __vueuse_core.watchArray)(plots, (value, oldValue, added, removed = []) => {
792
- added.forEach((plot) => update(plot));
793
- removed.forEach((plot) => update(plot, true));
794
- });
795
- (0, vesium.useCesiumEventListener)(() => plots.value.map((plot) => plot.definitionChanged), (plot, key, newValue, oldValue) => {
796
- if ([
797
- "disabled",
798
- "defining",
799
- "scheme",
800
- "sampled",
801
- "time"
802
- ].includes(key)) (0, vue.nextTick)(() => update(plot));
803
- else if (key === "skeletons") {
804
- const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
805
- added.forEach((item) => entityScope.add(item));
806
- removed.forEach((item) => entityScope.remove(item));
807
- }
808
- });
809
- (0, vue.watch)(current, (plot, previous) => {
810
- plot && update(plot);
811
- previous && update(previous);
812
- });
813
- return { dataSource };
814
- }
784
+ (0, __vueuse_core.watchArray)(plots, (value, oldValue, added, removed = []) => {
785
+ added.forEach((plot) => update(plot));
786
+ removed.forEach((plot) => update(plot, true));
787
+ });
788
+ (0, vesium.useCesiumEventListener)(() => plots.value.map((plot) => plot.definitionChanged), (plot, key, newValue, oldValue) => {
789
+ if ([
790
+ "disabled",
791
+ "defining",
792
+ "scheme",
793
+ "sampled",
794
+ "time"
795
+ ].includes(key)) (0, vue.nextTick)(() => update(plot));
796
+ else if (key === "skeletons") {
797
+ const { added, removed } = (0, vesium.arrayDiff)(newValue, oldValue);
798
+ added.forEach((item) => entityScope.add(item));
799
+ removed.forEach((item) => entityScope.remove(item));
800
+ }
801
+ });
802
+ (0, vue.watch)(current, (plot, previous) => {
803
+ plot && update(plot);
804
+ previous && update(previous);
805
+ });
806
+ return { dataSource };
807
+ }
815
808
 
816
809
  //#endregion
817
810
  //#region usePlot/usePlot.ts
818
- function usePlot(options) {
819
- const time = options?.time || (0, vue.shallowRef)();
820
- const viewer = (0, vesium.useViewer)();
821
- const getCurrentTime = () => {
822
- return time.value?.clone() || new cesium.JulianDate(0, 0);
823
- };
824
- const collection = (0, vue.shallowReactive)(/* @__PURE__ */ new Set());
825
- const plots = (0, vue.computed)(() => Array.from(collection));
826
- const current = (0, vue.shallowRef)();
827
- const packable = (0, vue.shallowRef)();
828
- (0, vesium.useCesiumEventListener)([() => current.value?.sampled.definitionChanged], () => {
829
- packable.value = current.value?.sampled.getValue(getCurrentTime());
830
- });
831
- useSampled(current, getCurrentTime);
832
- useRender(plots, current, getCurrentTime);
833
- useSkeleton(plots, current, getCurrentTime);
834
- (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_CLICK, (data) => {
835
- if (current.value?.defining) return;
836
- const pick = viewer.value?.scene.pick(data.position.clone());
837
- if (pick?.id?.plot instanceof PlotFeature) return;
838
- if (!pick) {
839
- current.value = void 0;
840
- return;
841
- }
842
- current.value = plots.value.find((plot) => (0, vesium.pickHitGraphic)(pick, [
843
- ...plot.entities,
844
- ...plot.primitives,
845
- ...plot.groundPrimitives
846
- ]));
847
- });
848
- let operateResolve;
849
- let operateReject;
850
- (0, vue.watch)(current, (plot, previous) => {
851
- if (previous) {
852
- if (previous.defining) {
853
- const packable$1 = previous.sampled.getValue(getCurrentTime());
854
- const completed = previous.scheme.allowManualComplete?.(packable$1);
855
- if (completed) {
856
- PlotFeature.setDefining(previous, false);
857
- operateResolve?.(previous);
858
- } else collection.delete(previous);
811
+ function usePlot(options) {
812
+ const time = options?.time || (0, vue.shallowRef)();
813
+ const viewer = (0, vesium.useViewer)();
814
+ const getCurrentTime = () => {
815
+ return time.value?.clone() || new cesium.JulianDate(0, 0);
816
+ };
817
+ const collection = (0, vue.shallowReactive)(/* @__PURE__ */ new Set());
818
+ const plots = (0, vue.computed)(() => Array.from(collection));
819
+ const current = (0, vue.shallowRef)();
820
+ const packable = (0, vue.shallowRef)();
821
+ (0, vesium.useCesiumEventListener)([() => current.value?.sampled.definitionChanged], () => {
822
+ packable.value = current.value?.sampled.getValue(getCurrentTime());
823
+ });
824
+ useSampled(current, getCurrentTime);
825
+ useRender(plots, current, getCurrentTime);
826
+ useSkeleton(plots, current, getCurrentTime);
827
+ (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_CLICK, (data) => {
828
+ if (current.value?.defining) return;
829
+ const pick = viewer.value?.scene.pick(data.position.clone());
830
+ if (pick?.id?.plot instanceof PlotFeature) return;
831
+ if (!pick) {
832
+ current.value = void 0;
833
+ return;
859
834
  }
860
- }
861
- });
862
- const operate = async (plot) => {
863
- return new Promise((resolve, reject) => {
864
- operateResolve = resolve;
865
- operateReject = reject;
866
- const _plot = plot instanceof PlotFeature ? plot : new PlotFeature(plot);
867
- if (!collection.has(_plot)) collection.add(_plot);
868
- current.value = _plot;
869
- return resolve(_plot);
835
+ current.value = plots.value.find((plot) => (0, vesium.pickHitGraphic)(pick, [
836
+ ...plot.entities,
837
+ ...plot.primitives,
838
+ ...plot.groundPrimitives
839
+ ]));
870
840
  });
871
- };
872
- const remove = (plot) => {
873
- if (plot === current.value) current.value = void 0;
874
- if (collection.has(plot)) {
875
- collection.delete(plot);
876
- return true;
877
- }
878
- return false;
879
- };
880
- return {
881
- plots,
882
- time,
883
- operate,
884
- remove,
885
- cancel: operateReject
886
- };
887
- }
841
+ let operateResolve;
842
+ let operateReject;
843
+ (0, vue.watch)(current, (plot, previous) => {
844
+ if (previous) {
845
+ if (previous.defining) {
846
+ const packable$1 = previous.sampled.getValue(getCurrentTime());
847
+ if (previous.scheme.allowManualComplete?.(packable$1)) {
848
+ PlotFeature.setDefining(previous, false);
849
+ operateResolve?.(previous);
850
+ } else collection.delete(previous);
851
+ }
852
+ }
853
+ });
854
+ const operate = async (plot) => {
855
+ return new Promise((resolve, reject) => {
856
+ operateResolve = resolve;
857
+ operateReject = reject;
858
+ const _plot = plot instanceof PlotFeature ? plot : new PlotFeature(plot);
859
+ if (!collection.has(_plot)) collection.add(_plot);
860
+ current.value = _plot;
861
+ return resolve(_plot);
862
+ });
863
+ };
864
+ const remove = (plot) => {
865
+ if (plot === current.value) current.value = void 0;
866
+ if (collection.has(plot)) {
867
+ collection.delete(plot);
868
+ return true;
869
+ }
870
+ return false;
871
+ };
872
+ return {
873
+ plots,
874
+ time,
875
+ operate,
876
+ remove,
877
+ cancel: operateReject
878
+ };
879
+ }
888
880
 
889
881
  //#endregion
890
882
  //#region skeleton/control.ts
891
883
  /**
892
- * 绘制控制的框架点,拖拽时,将更新该控制点的实时位置
893
- */
894
- function control() {
895
- return {
896
- disabled: ({ active }) => !active,
897
- cursor: "pointer",
898
- dragCursor: "crosshair",
899
- onDrag({ viewer, sampled, packable, event, index, lockCamera }) {
900
- lockCamera();
901
- const position = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
902
- if (position) {
884
+ * 绘制控制的框架点,拖拽时,将更新该控制点的实时位置
885
+ */
886
+ function control() {
887
+ return {
888
+ disabled: ({ active }) => !active,
889
+ cursor: "pointer",
890
+ dragCursor: "crosshair",
891
+ onDrag({ viewer, sampled, packable, event, index, lockCamera }) {
892
+ lockCamera();
893
+ const position = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
894
+ if (position) {
895
+ const positions = [...packable.positions ?? []];
896
+ positions[index] = position;
897
+ sampled.setSample({
898
+ time: packable.time,
899
+ derivative: packable.derivative,
900
+ positions
901
+ });
902
+ }
903
+ },
904
+ onKeyPressed({ viewer, keyEvent, sampled, packable, index }) {
905
+ const height = (0, vesium.toCartographic)(viewer.camera.position)?.height;
906
+ if (!height || ![
907
+ "ArrowUp",
908
+ "ArrowRight",
909
+ "ArrowDown",
910
+ "ArrowLeft"
911
+ ].includes(keyEvent.key)) return;
912
+ keyEvent.preventDefault();
913
+ let headingAdjust = 0;
914
+ switch (keyEvent.key) {
915
+ case "ArrowRight":
916
+ headingAdjust = Math.PI / 2;
917
+ break;
918
+ case "ArrowDown":
919
+ headingAdjust = Math.PI;
920
+ break;
921
+ case "ArrowLeft":
922
+ headingAdjust = -Math.PI / 2;
923
+ break;
924
+ case "ArrowUp":
925
+ headingAdjust = 0;
926
+ break;
927
+ }
928
+ const newHeading = (viewer.camera.heading + headingAdjust) % (2 * Math.PI);
903
929
  const positions = [...packable.positions ?? []];
904
- positions[index] = position;
930
+ const cartographic = (0, vesium.toCartographic)(positions[index]);
931
+ const distance$1 = height / 1e5 * Math.PI / 180 / 1e3;
932
+ cartographic.latitude += distance$1 * Math.cos(newHeading);
933
+ cartographic.longitude += distance$1 * Math.sin(newHeading);
934
+ positions[index] = (0, vesium.toCartesian3)(cartographic);
905
935
  sampled.setSample({
906
936
  time: packable.time,
907
937
  derivative: packable.derivative,
908
938
  positions
909
939
  });
940
+ },
941
+ render: ({ position, action }) => {
942
+ return {
943
+ position,
944
+ point: {
945
+ pixelSize: 8,
946
+ color: {
947
+ [PlotAction.IDLE]: cesium.Color.BLUE.withAlpha(.4),
948
+ [PlotAction.HOVER]: cesium.Color.BLUE.withAlpha(.6),
949
+ [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
950
+ }[action],
951
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
952
+ outlineWidth: 1,
953
+ outlineColor: cesium.Color.WHITE.withAlpha(.4)
954
+ }
955
+ };
910
956
  }
911
- },
912
- onKeyPressed({ viewer, keyEvent, sampled, packable, index }) {
913
- const height = (0, vesium.toCartographic)(viewer.camera.position)?.height;
914
- if (!height || ![
915
- "ArrowUp",
916
- "ArrowRight",
917
- "ArrowDown",
918
- "ArrowLeft"
919
- ].includes(keyEvent.key)) return;
920
- keyEvent.preventDefault();
921
- let headingAdjust = 0;
922
- switch (keyEvent.key) {
923
- case "ArrowRight":
924
- headingAdjust = Math.PI / 2;
925
- break;
926
- case "ArrowDown":
927
- headingAdjust = Math.PI;
928
- break;
929
- case "ArrowLeft":
930
- headingAdjust = -Math.PI / 2;
931
- break;
932
- case "ArrowUp":
933
- headingAdjust = 0;
934
- break;
935
- }
936
- const newHeading = (viewer.camera.heading + headingAdjust) % (2 * Math.PI);
937
- const positions = [...packable.positions ?? []];
938
- const cartographic = (0, vesium.toCartographic)(positions[index]);
939
- const r = height / 1e5;
940
- const distance$1 = r * Math.PI / 180 / 1e3;
941
- cartographic.latitude += distance$1 * Math.cos(newHeading);
942
- cartographic.longitude += distance$1 * Math.sin(newHeading);
943
- positions[index] = (0, vesium.toCartesian3)(cartographic);
944
- sampled.setSample({
945
- time: packable.time,
946
- derivative: packable.derivative,
947
- positions
948
- });
949
- },
950
- render: ({ position, action }) => {
951
- const colors = {
952
- [PlotAction.IDLE]: cesium.Color.BLUE.withAlpha(.4),
953
- [PlotAction.HOVER]: cesium.Color.BLUE.withAlpha(.6),
954
- [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
955
- };
956
- return {
957
- position,
958
- point: {
959
- pixelSize: 8,
960
- color: colors[action],
961
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
962
- outlineWidth: 1,
963
- outlineColor: cesium.Color.WHITE.withAlpha(.4)
964
- }
965
- };
966
- }
967
- };
968
- }
957
+ };
958
+ }
969
959
 
970
960
  //#endregion
971
961
  //#region skeleton/interval.ts
972
962
  /**
973
- * 绘制封闭的间隔框架点,如多边形。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
974
- */
975
- function interval() {
976
- let dragIndex = -1;
977
- return {
978
- disabled: ({ active, defining }) => !active || defining,
979
- cursor: "pointer",
980
- dragCursor: "crosshair",
981
- format(packable) {
982
- const _positions = packable.positions ?? [];
983
- if (_positions.length < 2) return [];
984
- return _positions.map((position, i) => {
985
- const next = i === _positions.length - 1 ? _positions[0] : _positions[i + 1];
986
- return cesium.Cartesian3.midpoint(position, next, new cesium.Cartesian3());
987
- });
988
- },
989
- onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
990
- lockCamera();
991
- const position = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
992
- if (!position) return;
993
- const positions = [...packable.positions ?? []];
994
- if (dragIndex === -1) {
995
- dragIndex = index;
996
- positions.splice(index + 1, 0, position);
997
- } else positions[dragIndex + 1] = position;
998
- if (!dragging) dragIndex = -1;
999
- sampled.setSample({
1000
- time: packable.time,
1001
- derivative: packable.derivative,
1002
- positions
1003
- });
1004
- },
1005
- render: ({ position, action, active }) => {
1006
- if (!active) return;
1007
- const colors = {
1008
- [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1009
- [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1010
- [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1011
- };
1012
- return {
1013
- position,
1014
- point: {
1015
- pixelSize: 6,
1016
- color: colors[action],
1017
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
1018
- outlineWidth: 1,
1019
- outlineColor: cesium.Color.WHITE.withAlpha(.4)
1020
- }
1021
- };
1022
- }
1023
- };
1024
- }
1025
-
1026
- //#endregion
1027
- //#region skeleton/intervalNonclosed.ts
1028
- /**
1029
- * 绘制非封闭的间隔框架点,如线段。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
1030
- */
1031
- function intervalNonclosed() {
1032
- let dragIndex = -1;
1033
- return {
1034
- disabled: ({ active, defining }) => !active || defining,
1035
- cursor: "pointer",
1036
- dragCursor: "crosshair",
1037
- format(packable) {
1038
- const _positions = packable.positions ?? [];
1039
- if (_positions.length < 2) return [];
1040
- const midpoints = [];
1041
- for (let i = 0; i < _positions.length - 1; i++) midpoints.push(cesium.Cartesian3.midpoint(_positions[i], _positions[i + 1], new cesium.Cartesian3()));
1042
- return midpoints;
1043
- },
1044
- onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
1045
- lockCamera();
1046
- const position = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
1047
- if (!position) return;
1048
- const positions = [...packable.positions ?? []];
1049
- if (dragIndex === -1) {
1050
- dragIndex = index;
1051
- positions.splice(index + 1, 0, position);
1052
- } else positions[dragIndex + 1] = position;
1053
- if (!dragging) dragIndex = -1;
1054
- sampled.setSample({
1055
- time: packable.time,
1056
- derivative: packable.derivative,
1057
- positions
1058
- });
1059
- },
1060
- render: ({ position, action }) => {
1061
- const colors = {
1062
- [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1063
- [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1064
- [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1065
- };
1066
- return {
1067
- position,
1068
- point: {
1069
- pixelSize: 6,
1070
- color: colors[action],
1071
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
1072
- outlineWidth: 1,
1073
- outlineColor: cesium.Color.WHITE.withAlpha(.4)
1074
- }
1075
- };
1076
- }
1077
- };
1078
- }
1079
-
1080
- //#endregion
1081
- //#region skeleton/moved.ts
1082
- 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>")}`;
1083
- /**
1084
- * 绘制非封闭的间隔框架点,如线段。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
1085
- */
1086
- function moved() {
1087
- return {
1088
- disabled: ({ active, defining }) => !active || defining,
1089
- cursor: "pointer",
1090
- dragCursor: "crosshair",
1091
- format(packable) {
1092
- const positions = packable.positions ?? [];
1093
- if (positions.length === 0) return [];
1094
- else if (positions.length === 1) return [positions[0]];
1095
- else {
1096
- const center = cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions));
1097
- return [(0, vesium.toCartesian3)(center)];
963
+ * 绘制封闭的间隔框架点,如多边形。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
964
+ */
965
+ function interval() {
966
+ let dragIndex = -1;
967
+ return {
968
+ disabled: ({ active, defining }) => !active || defining,
969
+ cursor: "pointer",
970
+ dragCursor: "crosshair",
971
+ format(packable) {
972
+ const _positions = packable.positions ?? [];
973
+ if (_positions.length < 2) return [];
974
+ return _positions.map((position, i) => {
975
+ const next = i === _positions.length - 1 ? _positions[0] : _positions[i + 1];
976
+ return cesium.Cartesian3.midpoint(position, next, new cesium.Cartesian3());
977
+ });
978
+ },
979
+ onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
980
+ lockCamera();
981
+ const position = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
982
+ if (!position) return;
983
+ const positions = [...packable.positions ?? []];
984
+ if (dragIndex === -1) {
985
+ dragIndex = index;
986
+ positions.splice(index + 1, 0, position);
987
+ } else positions[dragIndex + 1] = position;
988
+ if (!dragging) dragIndex = -1;
989
+ sampled.setSample({
990
+ time: packable.time,
991
+ derivative: packable.derivative,
992
+ positions
993
+ });
994
+ },
995
+ render: ({ position, action, active }) => {
996
+ if (!active) return;
997
+ return {
998
+ position,
999
+ point: {
1000
+ pixelSize: 6,
1001
+ color: {
1002
+ [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1003
+ [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1004
+ [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1005
+ }[action],
1006
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
1007
+ outlineWidth: 1,
1008
+ outlineColor: cesium.Color.WHITE.withAlpha(.4)
1009
+ }
1010
+ };
1098
1011
  }
1099
- },
1100
- onDrag({ viewer, sampled, packable, event, lockCamera, dragging }) {
1101
- dragging && lockCamera();
1102
- const startPosition = (0, vesium.canvasCoordToCartesian)(event.startPosition, viewer.scene);
1103
- const endPosition = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
1104
- if (!startPosition || !endPosition) return;
1105
- const offset = cesium.Cartesian3.subtract(endPosition, startPosition, new cesium.Cartesian3());
1106
- const positions = [...packable.positions ?? []];
1107
- sampled.setSample({
1108
- time: packable.time,
1109
- derivative: packable.derivative,
1110
- positions: positions.map((position) => cesium.Cartesian3.add(position, offset, new cesium.Cartesian3()))
1111
- });
1112
- },
1113
- render: ({ position, action }) => {
1114
- const colors = {
1115
- [PlotAction.IDLE]: cesium.Color.WHITE,
1116
- [PlotAction.HOVER]: cesium.Color.WHITE,
1117
- [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
1118
- };
1119
- return {
1120
- position,
1121
- billboard: {
1122
- image: svg,
1123
- width: 20,
1124
- height: 20,
1125
- color: colors[action],
1126
- pixelOffset: new cesium.Cartesian3(0, -20),
1127
- horizontalOrigin: cesium.HorizontalOrigin.CENTER,
1128
- verticalOrigin: cesium.VerticalOrigin.BOTTOM,
1129
- disableDepthTestDistance: Number.POSITIVE_INFINITY
1130
- }
1131
- };
1132
- }
1133
- };
1134
- }
1135
-
1136
- //#endregion
1137
- //#region measure/utils/tesselate.ts
1138
- /**
1139
- * 将多个边界点组成的面切割成多个三角形
1140
- * @param positions
1141
- */
1142
- function tesselate(positions) {
1143
- if (positions.length < 3) throw new Error("positions must >= 3");
1144
- if (positions.length === 3) return [[
1145
- positions[0].clone(),
1146
- positions[1].clone(),
1147
- positions[2].clone()
1148
- ]];
1149
- const geometry = cesium.CoplanarPolygonGeometry.createGeometry(cesium.CoplanarPolygonGeometry.fromPositions({
1150
- positions,
1151
- vertexFormat: cesium.VertexFormat.POSITION_ONLY
1152
- }));
1153
- if (!geometry) throw new Error("positions无法组成有效的geometry,检查点位是否错误");
1154
- const values = geometry.attributes.position.values;
1155
- const indices = geometry.indices;
1156
- const result = [];
1157
- for (let i = 0; i < indices.length; i += 3) {
1158
- const a = cesium.Cartesian3.unpack(values, indices[i] * 3, new cesium.Cartesian3());
1159
- const b = cesium.Cartesian3.unpack(values, indices[i + 1] * 3, new cesium.Cartesian3());
1160
- const c = cesium.Cartesian3.unpack(values, indices[i + 2] * 3, new cesium.Cartesian3());
1161
- result.push([
1162
- a,
1163
- b,
1164
- c
1165
- ]);
1166
- }
1167
- return result;
1168
- }
1169
-
1170
- //#endregion
1171
- //#region measure/utils/clampToGround.ts
1172
- /**
1173
- * 将传入的点位列表进行贴地处理,若某个点位获取高程失败则将此进行克隆返回
1174
- * @param options - 配置项
1175
- */
1176
- async function clampToHeightMostDetailedByTilesetOrTerrain(options) {
1177
- const { positions, scene, classificationType = cesium.ClassificationType.BOTH, terrainProvider = scene.terrainProvider } = options;
1178
- const tileset = [cesium.ClassificationType.BOTH, cesium.ClassificationType.CESIUM_3D_TILE].includes(classificationType);
1179
- const terrain = [cesium.ClassificationType.BOTH, cesium.ClassificationType.TERRAIN].includes(classificationType);
1180
- const tilesetPromise = new Promise((resolve) => {
1181
- if (tileset) scene.clampToHeightMostDetailed(positions.map((e) => e.clone())).then(resolve).catch((error) => {
1182
- console.warn(error);
1183
- resolve([]);
1184
- });
1185
- else resolve([]);
1186
- });
1187
- const terrainPromise = new Promise((resolve) => {
1188
- if (terrain && terrainProvider) (0, cesium.sampleTerrainMostDetailed)(terrainProvider, positions.map((e) => cesium.Cartographic.fromCartesian(e))).then((e) => resolve(e)).catch((error) => {
1189
- console.warn(error);
1190
- resolve([]);
1191
- });
1192
- else resolve([]);
1193
- });
1194
- const [tilesetPositions, terrainPositions] = await Promise.all([tilesetPromise, terrainPromise]);
1195
- const resluts = [];
1196
- positions.forEach((item, index) => {
1197
- const position = tilesetPositions[index] || terrainPositions[index] ? cesium.Ellipsoid.WGS84.cartographicToCartesian(terrainPositions[index]) : item.clone();
1198
- resluts.push(position);
1199
- });
1200
- return resluts;
1201
- }
1202
-
1203
- //#endregion
1204
- //#region measure/utils/triangleGrid.ts
1205
- function defaultOptions$2(original) {
1206
- const clampToGround = original?.clampToGround ?? false;
1207
- const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1208
- const density = Math.floor(original?.density ?? 10);
1209
- return {
1210
- scene: original?.scene,
1211
- clampToGround,
1212
- classificationType,
1213
- terrainProvider: original?.terrainProvider,
1214
- density
1215
- };
1216
- }
1217
- /**
1218
- * 生成三角网数组
1219
- * @param positions - 边界点数组
1220
- * @param options - 配置项
1221
- */
1222
- async function triangleGrid(positions, options) {
1223
- if (positions.length < 3) throw new Error("positions must >= 3");
1224
- const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$2(options);
1225
- if (density <= 0) throw new Error("options.density must > 0");
1226
- const bbox = cesium.Rectangle.fromCartesianArray(positions);
1227
- const vertical = bbox.north - bbox.south;
1228
- const horizontal = bbox.east - bbox.west;
1229
- const max = Math.max(horizontal, vertical);
1230
- const granularity = max / density;
1231
- const polygonGeometry = cesium.PolygonGeometry.fromPositions({
1232
- positions,
1233
- vertexFormat: cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
1234
- granularity
1235
- });
1236
- const geometry = cesium.PolygonGeometry.createGeometry(polygonGeometry);
1237
- const values = geometry.attributes.position.values;
1238
- if (!geometry || !values) throw new Error("positions无法组成有效的geometry,检查点位是否错误");
1239
- const indices = geometry.indices;
1240
- let cartesian3List = [];
1241
- for (let i = 0; i < indices.length; i += 3) {
1242
- const a = cesium.Cartesian3.unpack(values, indices[i] * 3, new cesium.Cartesian3());
1243
- const b = cesium.Cartesian3.unpack(values, indices[i + 1] * 3, new cesium.Cartesian3());
1244
- const c = cesium.Cartesian3.unpack(values, indices[i + 2] * 3, new cesium.Cartesian3());
1245
- cartesian3List.push(a, b, c);
1246
- }
1247
- if (clampToGround) {
1248
- if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1249
- const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
1250
- scene,
1251
- terrainProvider,
1252
- positions: cartesian3List,
1253
- classificationType
1254
- });
1255
- cartesian3List = detaileds;
1256
- }
1257
- const grid = [];
1258
- while (cartesian3List?.length) {
1259
- const [a, b, c] = cartesian3List.splice(0, 3);
1260
- grid.push([
1261
- a,
1262
- b,
1263
- c
1264
- ]);
1265
- }
1266
- return grid;
1267
- }
1268
-
1269
- //#endregion
1270
- //#region measure/utils/area.ts
1271
- /**
1272
- * 计算三维坐标系下三角形面积
1273
- * @param p0 - 三角形第一个点
1274
- * @param p1 - 三角形第二个点
1275
- * @param p2 - 三角形第三个点
1276
- */
1277
- function triangleArea(p0, p1, p2) {
1278
- const v0 = cesium.Cartesian3.subtract(p0, p1, new cesium.Cartesian3());
1279
- const v1 = cesium.Cartesian3.subtract(p2, p1, new cesium.Cartesian3());
1280
- const cross = cesium.Cartesian3.cross(v0, v1, v0);
1281
- return cesium.Cartesian3.magnitude(cross) * .5;
1282
- }
1283
- function defaultOptions$1(original) {
1284
- const clampToGround = original?.clampToGround ?? false;
1285
- const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1286
- const density = Math.floor(original?.density ?? 10);
1287
- return {
1288
- scene: original?.scene,
1289
- clampToGround,
1290
- classificationType,
1291
- terrainProvider: original?.terrainProvider,
1292
- density
1293
- };
1294
- }
1295
- /**
1296
- * 计算三维坐标系下图形面积
1297
- * @param positions - 图形各点的笛卡尔数组
1298
- */
1299
- async function area(positions, options) {
1300
- if (positions.length < 2) throw new Error("positions.length must >= 2");
1301
- const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1302
- if (density <= 0) throw new Error("options.density must > 0");
1303
- if (!clampToGround) {
1304
- const triangles$1 = tesselate(positions);
1305
- return triangles$1.reduce((count, current) => count += triangleArea(...current), 0);
1306
- }
1307
- const triangles = await triangleGrid(positions, {
1308
- density,
1309
- scene,
1310
- clampToGround,
1311
- classificationType,
1312
- terrainProvider
1313
- });
1314
- return triangles.reduce((count, current) => count += triangleArea(...current), 0);
1315
- }
1316
-
1317
- //#endregion
1318
- //#region measure/utils/lerpArray.ts
1319
- /**
1320
- * 在起点和终点间进行插值, 返回的数组包括起点和终点,数组长度为 count+1
1321
- */
1322
- async function lerpArray(options) {
1323
- const { start, end, count, scene, clampToGround, classificationType, terrainProvider } = options;
1324
- const result = [];
1325
- for (let i = 0; i < count; i++) {
1326
- const position = cesium.Cartesian3.lerp(start, end, 1 / count, new cesium.Cartesian3());
1327
- result.push(position);
1012
+ };
1328
1013
  }
1329
- result.push(end.clone());
1330
- if (!clampToGround) return result;
1331
- if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1332
- const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
1333
- scene,
1334
- terrainProvider,
1335
- positions: result,
1336
- classificationType
1337
- });
1338
- return detaileds;
1339
- }
1340
1014
 
1341
1015
  //#endregion
1342
- //#region measure/utils/distance.ts
1343
- function defaultOptions(original) {
1344
- const clampToGround = original?.clampToGround ?? false;
1345
- const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1346
- const density = Math.floor(original?.density ?? 50);
1347
- return {
1348
- scene: original?.scene,
1349
- clampToGround,
1350
- classificationType,
1351
- terrainProvider: original?.terrainProvider,
1352
- density
1353
- };
1354
- }
1016
+ //#region skeleton/intervalNonclosed.ts
1355
1017
  /**
1356
- * 计算多点位之间的距离
1357
- * @param positions
1358
- */
1359
- async function distance(positions, options) {
1360
- if (positions.length < 2) throw new Error("positions.length must >= 2");
1361
- const _options = defaultOptions(options);
1362
- const stages = [];
1363
- let count = 0;
1364
- positions.forEach((position, index) => {
1365
- if (index !== positions.length - 1) {
1366
- const next = positions[index + 1];
1367
- const distance$1 = cesium.Cartesian3.distance(position, next);
1368
- stages.push(distance$1);
1369
- count += distance$1;
1370
- }
1371
- });
1372
- if (!_options.clampToGround) return {
1373
- stages,
1374
- count
1375
- };
1376
- const density = _options.density;
1377
- if (density <= 0) throw new Error("options.density must > 0");
1378
- const densities = stages.map((stage) => {
1379
- return Math.floor(stage / count * density);
1380
- });
1381
- const diff = density - densities.reduce((count$1, current) => count$1 += current, 0);
1382
- if (diff) densities[densities.length - 1] += diff;
1383
- const positionListPromises = densities.map((density$1, i) => {
1384
- return lerpArray({
1385
- scene: _options.scene,
1386
- start: positions[i],
1387
- end: positions[i + 1],
1388
- count: density$1,
1389
- clampToGround: true,
1390
- classificationType: _options.classificationType,
1391
- terrainProvider: _options.terrainProvider
1392
- });
1393
- });
1394
- const detaileds = await Promise.all(positionListPromises);
1395
- const stagePromises = detaileds.map(async (positions$1) => {
1396
- const { count: count$1 } = await distance(positions$1);
1397
- return count$1;
1398
- });
1399
- const groundStages = await Promise.all(stagePromises);
1400
- return {
1401
- stages: groundStages,
1402
- count: groundStages.reduce((count$1, current) => count$1 += current, 0)
1403
- };
1404
- }
1405
-
1406
- //#endregion
1407
- //#region measure/measureArea.ts
1408
- const schemeMeasureArea = new PlotScheme({
1409
- type: "MeasureArea",
1410
- allowManualComplete: (packable) => packable.positions.length >= 3,
1411
- skeletons: [control, interval],
1412
- initRender() {
1413
- return { entities: [new cesium.Entity({
1414
- label: { font: "14pt" },
1415
- polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
1416
- polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
1417
- })] };
1418
- },
1419
- render(context) {
1420
- const entity = context.previous.entities[0];
1421
- const { mouse, packable } = context;
1422
- const positions = [...packable.positions ?? []];
1423
- mouse && positions.push(mouse);
1424
- if (positions.length === 2) {
1425
- entity.position = void 0;
1426
- entity.label.text = void 0;
1427
- entity.polygon.hierarchy = void 0;
1428
- entity.polyline.positions = new cesium.CallbackProperty(() => positions, false);
1429
- } else if (positions.length >= 3) {
1430
- positions.push(positions[0]);
1431
- entity.position = new cesium.ConstantPositionProperty((0, vesium.toCartesian3)(cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions))));
1432
- entity.label.text = new cesium.ConstantProperty("");
1433
- area(positions).then((e) => {
1434
- let text = "";
1435
- if (e / 1e3 / 1e3 > 10) text = `${(e / 1e3 / 1e3).toFixed(2)}km²`;
1436
- else text = `${(+e).toFixed(2)}m²`;
1437
- entity.label.text = new cesium.ConstantProperty(text);
1438
- });
1439
- entity.polyline.positions = void 0;
1440
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => {
1441
- return positions.length >= 3 ? new cesium.PolygonHierarchy([...positions]) : void 0;
1442
- }, false);
1443
- } else {
1444
- entity.position = void 0;
1445
- entity.polygon.hierarchy = void 0;
1446
- entity.polyline.positions = void 0;
1447
- }
1448
- return { entities: [entity] };
1449
- }
1450
- });
1451
-
1452
- //#endregion
1453
- //#region measure/measureDistance.ts
1454
- const schemeMeasureDistance = new PlotScheme({
1455
- type: "MeasureDistance",
1456
- allowManualComplete: (packable) => packable.positions.length >= 2,
1457
- skeletons: [control],
1458
- initRender() {
1459
- return { entities: [new cesium.Entity({ polyline: {
1460
- width: 2,
1461
- material: cesium.Color.YELLOW.withAlpha(.5)
1462
- } })] };
1463
- },
1464
- render(context) {
1465
- const entity = context.previous.entities[0];
1466
- const { mouse, packable, previous } = context;
1467
- const entities = previous.entities;
1468
- const positions = [...packable.positions ?? []];
1469
- mouse && positions.push(mouse);
1470
- if (positions.length < 2) return { entities };
1471
- const pl = entities[0];
1472
- pl.polyline ??= new cesium.PolylineGraphics();
1473
- pl.polyline.positions = new cesium.CallbackProperty(() => positions, false);
1474
- positions.forEach((item, index) => {
1475
- if (!entities[index + 1]) entities[index + 1] = new cesium.Entity({
1476
- position: item,
1477
- label: new cesium.LabelGraphics({
1478
- backgroundColor: cesium.Color.fromCssColorString("#fff"),
1479
- font: "12pt sans-serif"
1480
- })
1481
- });
1482
- });
1483
- entities.splice(positions.length, entities.length - positions.length - 1);
1484
- distance(positions).then(({ count, stages }) => {
1485
- stages.forEach((stage, index) => {
1486
- entities[index + 1].position = new cesium.CallbackPositionProperty(() => cesium.Cartesian3.midpoint(positions[index], positions[index + 1], new cesium.Cartesian3()), false);
1487
- entities[index + 1].label.text = new cesium.CallbackProperty(() => `${stage.toFixed(2)} m`, false);
1488
- });
1489
- if (stages.length > 1) {
1490
- entities[entities.length - 1].position = new cesium.CallbackPositionProperty(() => positions[positions.length - 1], false);
1491
- entities[entities.length - 1].label.text = new cesium.CallbackProperty(() => `${count.toFixed(2)} m`, false);
1492
- } else {
1493
- entities[entities.length - 1].position = void 0;
1494
- entities[entities.length - 1].label.text = void 0;
1018
+ * 绘制非封闭的间隔框架点,如线段。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
1019
+ */
1020
+ function intervalNonclosed() {
1021
+ let dragIndex = -1;
1022
+ return {
1023
+ disabled: ({ active, defining }) => !active || defining,
1024
+ cursor: "pointer",
1025
+ dragCursor: "crosshair",
1026
+ format(packable) {
1027
+ const _positions = packable.positions ?? [];
1028
+ if (_positions.length < 2) return [];
1029
+ const midpoints = [];
1030
+ for (let i = 0; i < _positions.length - 1; i++) midpoints.push(cesium.Cartesian3.midpoint(_positions[i], _positions[i + 1], new cesium.Cartesian3()));
1031
+ return midpoints;
1032
+ },
1033
+ onDrag({ viewer, sampled, packable, event, index, lockCamera, dragging }) {
1034
+ lockCamera();
1035
+ const position = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
1036
+ if (!position) return;
1037
+ const positions = [...packable.positions ?? []];
1038
+ if (dragIndex === -1) {
1039
+ dragIndex = index;
1040
+ positions.splice(index + 1, 0, position);
1041
+ } else positions[dragIndex + 1] = position;
1042
+ if (!dragging) dragIndex = -1;
1043
+ sampled.setSample({
1044
+ time: packable.time,
1045
+ derivative: packable.derivative,
1046
+ positions
1047
+ });
1048
+ },
1049
+ render: ({ position, action }) => {
1050
+ return {
1051
+ position,
1052
+ point: {
1053
+ pixelSize: 6,
1054
+ color: {
1055
+ [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1056
+ [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1057
+ [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1058
+ }[action],
1059
+ disableDepthTestDistance: Number.POSITIVE_INFINITY,
1060
+ outlineWidth: 1,
1061
+ outlineColor: cesium.Color.WHITE.withAlpha(.4)
1062
+ }
1063
+ };
1495
1064
  }
1496
- });
1497
- return { entities };
1498
- }
1499
- });
1500
-
1501
- //#endregion
1502
- //#region scheme/Billboard.ts
1503
- const PlotSchemeBillboard = new PlotScheme({
1504
- type: "Billboard",
1505
- complete: (packable) => packable.positions.length >= 1,
1506
- skeletons: [moved],
1507
- initRender: () => {
1508
- return { entities: [new cesium.Entity({ billboard: {
1509
- image: "/favicon.svg",
1510
- width: 32,
1511
- height: 32
1512
- } })] };
1513
- },
1514
- render(options) {
1515
- const { mouse, packable } = options;
1516
- const entity = options.previous.entities?.[0] ?? new cesium.Entity({ billboard: {} });
1517
- const position = packable.positions?.[0] ?? mouse;
1518
- entity.position = new cesium.CallbackPositionProperty(() => position, true);
1519
- return { entities: [entity] };
1520
- }
1521
- });
1522
-
1523
- //#endregion
1524
- //#region scheme/BillboardPinBuilder.ts
1525
- const PlotSchemeBillboardPinBuilder = new PlotScheme({
1526
- type: "BillboardPinBuilder",
1527
- complete: (packable) => packable.positions.length >= 1,
1528
- skeletons: [moved],
1529
- initRender() {
1530
- return { entities: [new cesium.Entity({ billboard: {} })] };
1531
- },
1532
- render(context) {
1533
- const entity = context.previous.entities[0];
1534
- const position = context.packable.positions[0] ?? context.mouse;
1535
- entity.position = new cesium.CallbackPositionProperty(() => position, true);
1536
- return { entities: [entity] };
1537
- }
1538
- });
1539
-
1540
- //#endregion
1541
- //#region scheme/Cylinder.ts
1542
- const PlotSchemeCylinder = new PlotScheme({
1543
- type: "Cylinder",
1544
- complete: (packable) => packable.positions.length >= 2,
1545
- skeletons: [moved, control],
1546
- initRender() {
1547
- return { entities: [new cesium.Entity({ cylinder: {} })] };
1548
- },
1549
- render(context) {
1550
- const entity = context.previous.entities[0];
1551
- const positions = [...context.packable.positions];
1552
- if (positions.length === 0) return context.previous;
1553
- if (positions.length === 1) {
1554
- const position = context.mouse;
1555
- position && positions.push(position);
1556
- }
1557
- if (positions.length < 2) return context.previous;
1558
- entity.position = new cesium.ConstantPositionProperty(positions[0]);
1559
- const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
1560
- entity.cylinder.bottomRadius = new cesium.CallbackProperty(() => radius, false);
1561
- if (context.defining || !(0, vesium.toPropertyValue)(entity.cylinder.length)) entity.cylinder.length = (0, vesium.toProperty)(radius * 2);
1562
- return { entities: [entity] };
1563
- }
1564
- });
1565
-
1566
- //#endregion
1567
- //#region scheme/Ellipse.ts
1568
- const PlotSchemeEllipse = new PlotScheme({
1569
- type: "Ellipse",
1570
- complete: (packable) => packable.positions.length >= 2,
1571
- skeletons: [moved, control],
1572
- initRender() {
1573
- return { entities: [new cesium.Entity({ ellipse: {} })] };
1574
- },
1575
- render(context) {
1576
- const entity = context.previous.entities[0];
1577
- const positions = [...context.packable.positions];
1578
- if (positions.length === 0) return context.previous;
1579
- if (positions.length === 1) {
1580
- const position = context.mouse;
1581
- position && positions.push(position);
1582
- }
1583
- if (positions.length < 2) return context.previous;
1584
- entity.position = new cesium.ConstantPositionProperty(positions[0]);
1585
- const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
1586
- entity.ellipse.semiMinorAxis = new cesium.CallbackProperty(() => radius || 1, false);
1587
- entity.ellipse.semiMajorAxis = entity.ellipse.semiMinorAxis;
1588
- return { entities: [entity] };
1589
- }
1590
- });
1591
-
1592
- //#endregion
1593
- //#region scheme/Label.ts
1594
- const PlotSchemeLabel = new PlotScheme({
1595
- type: "Label",
1596
- complete: (packable) => packable.positions.length >= 1,
1597
- skeletons: [moved],
1598
- initRender() {
1599
- return { entities: [new cesium.Entity({ label: { text: "Label" } })] };
1600
- },
1601
- render(context) {
1602
- const entity = context.previous.entities[0];
1603
- const position = context.packable.positions[0] ?? context.mouse;
1604
- entity.position = new cesium.CallbackPositionProperty(() => position, true);
1605
- return { entities: [entity] };
1065
+ };
1606
1066
  }
1607
- });
1608
1067
 
1609
1068
  //#endregion
1610
- //#region scheme/Point.ts
1611
- const PlotSchemePoint = new PlotScheme({
1612
- type: "Point",
1613
- complete: (packable) => packable.positions.length >= 1,
1614
- skeletons: [moved],
1615
- initRender() {
1616
- return { entities: [new cesium.Entity({ point: {
1617
- pixelSize: 10,
1618
- color: cesium.Color.RED
1619
- } })] };
1620
- },
1621
- render(context) {
1622
- const entity = context.previous.entities[0];
1623
- const position = context.packable.positions[0] ?? context.mouse;
1624
- entity.position = new cesium.CallbackPositionProperty(() => position, true);
1625
- return { entities: [entity] };
1069
+ //#region skeleton/moved.ts
1070
+ 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>")}`;
1071
+ /**
1072
+ * 绘制非封闭的间隔框架点,如线段。拖拽时,会在两点之间插入一个控制点,并持续拖拽该点。
1073
+ */
1074
+ function moved() {
1075
+ return {
1076
+ disabled: ({ active, defining }) => !active || defining,
1077
+ cursor: "pointer",
1078
+ dragCursor: "crosshair",
1079
+ format(packable) {
1080
+ const positions = packable.positions ?? [];
1081
+ if (positions.length === 0) return [];
1082
+ else if (positions.length === 1) return [positions[0]];
1083
+ else return [(0, vesium.toCartesian3)(cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions)))];
1084
+ },
1085
+ onDrag({ viewer, sampled, packable, event, lockCamera, dragging }) {
1086
+ dragging && lockCamera();
1087
+ const startPosition = (0, vesium.canvasCoordToCartesian)(event.startPosition, viewer.scene);
1088
+ const endPosition = (0, vesium.canvasCoordToCartesian)(event.endPosition, viewer.scene);
1089
+ if (!startPosition || !endPosition) return;
1090
+ const offset = cesium.Cartesian3.subtract(endPosition, startPosition, new cesium.Cartesian3());
1091
+ const positions = [...packable.positions ?? []];
1092
+ sampled.setSample({
1093
+ time: packable.time,
1094
+ derivative: packable.derivative,
1095
+ positions: positions.map((position) => cesium.Cartesian3.add(position, offset, new cesium.Cartesian3()))
1096
+ });
1097
+ },
1098
+ render: ({ position, action }) => {
1099
+ return {
1100
+ position,
1101
+ billboard: {
1102
+ image: svg,
1103
+ width: 20,
1104
+ height: 20,
1105
+ color: {
1106
+ [PlotAction.IDLE]: cesium.Color.WHITE,
1107
+ [PlotAction.HOVER]: cesium.Color.WHITE,
1108
+ [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
1109
+ }[action],
1110
+ pixelOffset: new cesium.Cartesian3(0, -20),
1111
+ horizontalOrigin: cesium.HorizontalOrigin.CENTER,
1112
+ verticalOrigin: cesium.VerticalOrigin.BOTTOM,
1113
+ disableDepthTestDistance: Number.POSITIVE_INFINITY
1114
+ }
1115
+ };
1116
+ }
1117
+ };
1626
1118
  }
1627
- });
1628
1119
 
1629
1120
  //#endregion
1630
- //#region scheme/Polygon.ts
1631
- const PlotSchemePolygon = new PlotScheme({
1632
- type: "Polygon",
1633
- allowManualComplete: (packable) => packable.positions.length >= 2,
1634
- skeletons: [
1635
- moved,
1636
- control,
1637
- interval
1638
- ],
1639
- initRender: () => {
1640
- return { entities: [new cesium.Entity({
1641
- polyline: {},
1642
- polygon: {}
1643
- })] };
1644
- },
1645
- render(options) {
1646
- const { mouse, packable } = options;
1647
- const entity = options.previous.entities[0];
1648
- const positions = [...packable.positions ?? []];
1649
- mouse && positions.push(mouse);
1650
- if (positions.length === 2) {
1651
- entity.polygon.hierarchy = void 0;
1652
- entity.polyline.positions = new cesium.CallbackProperty(() => positions, false);
1653
- } else if (positions.length >= 3) {
1654
- entity.polyline.positions = void 0;
1655
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => {
1656
- positions.push(positions[0]);
1657
- return positions.length >= 3 ? new cesium.PolygonHierarchy([...positions]) : void 0;
1658
- }, false);
1659
- } else {
1660
- entity.polygon.hierarchy = void 0;
1661
- entity.polyline.positions = void 0;
1121
+ //#region measure/utils/tesselate.ts
1122
+ /**
1123
+ * 将多个边界点组成的面切割成多个三角形
1124
+ * @param positions
1125
+ */
1126
+ function tesselate(positions) {
1127
+ if (positions.length < 3) throw new Error("positions must >= 3");
1128
+ if (positions.length === 3) return [[
1129
+ positions[0].clone(),
1130
+ positions[1].clone(),
1131
+ positions[2].clone()
1132
+ ]];
1133
+ const geometry = cesium.CoplanarPolygonGeometry.createGeometry(cesium.CoplanarPolygonGeometry.fromPositions({
1134
+ positions,
1135
+ vertexFormat: cesium.VertexFormat.POSITION_ONLY
1136
+ }));
1137
+ if (!geometry) throw new Error("positions无法组成有效的geometry,检查点位是否错误");
1138
+ const values = geometry.attributes.position.values;
1139
+ const indices = geometry.indices;
1140
+ const result = [];
1141
+ for (let i = 0; i < indices.length; i += 3) {
1142
+ const a = cesium.Cartesian3.unpack(values, indices[i] * 3, new cesium.Cartesian3());
1143
+ const b = cesium.Cartesian3.unpack(values, indices[i + 1] * 3, new cesium.Cartesian3());
1144
+ const c = cesium.Cartesian3.unpack(values, indices[i + 2] * 3, new cesium.Cartesian3());
1145
+ result.push([
1146
+ a,
1147
+ b,
1148
+ c
1149
+ ]);
1662
1150
  }
1663
- return { entities: [entity] };
1151
+ return result;
1664
1152
  }
1665
- });
1666
1153
 
1667
1154
  //#endregion
1668
- //#region geom/helper.ts
1669
- const FITTING_COUNT = 100;
1670
- const HALF_PI = Math.PI / 2;
1671
- const ZERO_TOLERANCE = 1e-4;
1672
- const TWO_PI = Math.PI * 2;
1673
- /**
1674
- * 计算两个坐标之间的距离
1675
- * @param coord1
1676
- * @param coord2
1677
- */
1678
- function mathDistance(coord1, coord2) {
1679
- return Math.hypot(coord1[0] - coord2[0], coord1[1] - coord2[1]);
1680
- }
1681
- /**
1682
- * 计算点集合的总距离
1683
- * @param points
1684
- */
1685
- function wholeDistance(points) {
1686
- let distance$1 = 0;
1687
- if (points && Array.isArray(points) && points.length > 0) points.forEach((item, index) => {
1688
- if (index < points.length - 1) distance$1 += mathDistance(item, points[index + 1]);
1689
- });
1690
- return distance$1;
1691
- }
1692
- /**
1693
- * 获取基础长度
1694
- * @param points
1695
- */
1696
- const getBaseLength = (points) => wholeDistance(points) ** .99;
1697
- /**
1698
- * 求取两个坐标的中间坐标
1699
- * @param coord1
1700
- * @param coord2
1701
- */
1702
- function mid(coord1, coord2) {
1703
- return [(coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2];
1704
- }
1705
- /**
1706
- * 通过三个点确定一个圆的中心点
1707
- * @param coord1
1708
- * @param coord2
1709
- * @param coord3
1710
- */
1711
- function getCircleCenterOfThreeCoords(coord1, coord2, coord3) {
1712
- const coordA = [(coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2];
1713
- const coordB = [coordA[0] - coord1[1] + coord2[1], coordA[1] + coord1[0] - coord2[0]];
1714
- const coordC = [(coord1[0] + coord3[0]) / 2, (coord1[1] + coord3[1]) / 2];
1715
- const coordD = [coordC[0] - coord1[1] + coord3[1], coordC[1] + coord1[0] - coord3[0]];
1716
- return getIntersectCoord(coordA, coordB, coordC, coordD);
1717
- }
1718
- /**
1719
- * 获取交集的点
1720
- * @param coordA
1721
- * @param coordB
1722
- * @param coordC
1723
- * @param coordD
1724
- */
1725
- function getIntersectCoord(coordA, coordB, coordC, coordD) {
1726
- if (coordA[1] === coordB[1]) {
1727
- const f$1 = (coordD[0] - coordC[0]) / (coordD[1] - coordC[1]);
1728
- const x$1 = f$1 * (coordA[1] - coordC[1]) + coordC[0];
1729
- const y$1 = coordA[1];
1730
- return [x$1, y$1];
1731
- }
1732
- if (coordC[1] === coordD[1]) {
1733
- const e$1 = (coordB[0] - coordA[0]) / (coordB[1] - coordA[1]);
1734
- const x$1 = e$1 * (coordC[1] - coordA[1]) + coordA[0];
1735
- const y$1 = coordC[1];
1736
- return [x$1, y$1];
1737
- }
1738
- const e = (coordB[0] - coordA[0]) / (coordB[1] - coordA[1]);
1739
- const f = (coordD[0] - coordC[0]) / (coordD[1] - coordC[1]);
1740
- const y = (e * coordA[1] - coordA[0] - f * coordC[1] + coordC[0]) / (e - f);
1741
- const x = e * y - e * coordA[1] + coordA[0];
1742
- return [x, y];
1743
- }
1744
- /**
1745
- * 获取方位角(地平经度)
1746
- * @param startCoord
1747
- * @param endCoord
1748
- */
1749
- function getAzimuth(startCoord, endCoord) {
1750
- let azimuth = 0;
1751
- const angle = Math.asin(Math.abs(endCoord[1] - startCoord[1]) / mathDistance(startCoord, endCoord));
1752
- if (endCoord[1] >= startCoord[1] && endCoord[0] >= startCoord[0]) azimuth = angle + Math.PI;
1753
- else if (endCoord[1] >= startCoord[1] && endCoord[0] < startCoord[0]) azimuth = Math.PI * 2 - angle;
1754
- else if (endCoord[1] < startCoord[1] && endCoord[0] < startCoord[0]) azimuth = angle;
1755
- else if (endCoord[1] < startCoord[1] && endCoord[0] >= startCoord[0]) azimuth = Math.PI - angle;
1756
- return azimuth;
1757
- }
1758
- /**
1759
- * 通过三个点获取方位角
1760
- * @param coordA
1761
- * @param coordB
1762
- * @param coordC
1763
- */
1764
- function getAngleOfThreeCoords(coordA, coordB, coordC) {
1765
- const angle = getAzimuth(coordB, coordA) - getAzimuth(coordB, coordC);
1766
- return angle < 0 ? angle + Math.PI * 2 : angle;
1767
- }
1768
- /**
1769
- * 判断是否是顺时针
1770
- * @param coord1
1771
- * @param coord2
1772
- * @param coord3
1773
- */
1774
- function isClockWise(coord1, coord2, coord3) {
1775
- return (coord3[1] - coord1[1]) * (coord2[0] - coord1[0]) > (coord2[1] - coord1[1]) * (coord3[0] - coord1[0]);
1776
- }
1777
- /**
1778
- * 获取立方值
1779
- */
1780
- function getCubicValue(t, startCoord, coord1, coord2, endCoord) {
1781
- t = Math.max(Math.min(t, 1), 0);
1782
- const [tp, t2] = [1 - t, t * t];
1783
- const t3 = t2 * t;
1784
- const tp2 = tp * tp;
1785
- const tp3 = tp2 * tp;
1786
- const x = tp3 * startCoord[0] + 3 * tp2 * t * coord1[0] + 3 * tp * t2 * coord2[0] + t3 * endCoord[0];
1787
- const y = tp3 * startCoord[1] + 3 * tp2 * t * coord1[1] + 3 * tp * t2 * coord2[1] + t3 * endCoord[1];
1788
- return [x, y];
1789
- }
1790
- /**
1791
- * 根据起止点和旋转方向求取第三个点
1792
- * @param startCoord
1793
- * @param endCoord
1794
- * @param angle
1795
- * @param distance
1796
- * @param clockWise
1797
- */
1798
- function getThirdCoord(startCoord, endCoord, angle, distance$1, clockWise) {
1799
- const azimuth = getAzimuth(startCoord, endCoord);
1800
- const alpha = clockWise ? azimuth + angle : azimuth - angle;
1801
- const dx = distance$1 * Math.cos(alpha);
1802
- const dy = distance$1 * Math.sin(alpha);
1803
- return [endCoord[0] + dx, endCoord[1] + dy];
1804
- }
1805
- /**
1806
- * 插值弓形线段点
1807
- * @param center
1808
- * @param radius
1809
- * @param startAngle
1810
- * @param endAngle
1811
- */
1812
- function getArcCoords(center, radius, startAngle, endAngle) {
1813
- let [x, y, coords, angleDiff] = [
1814
- 0,
1815
- 0,
1816
- [],
1817
- endAngle - startAngle
1818
- ];
1819
- angleDiff = angleDiff < 0 ? angleDiff + Math.PI * 2 : angleDiff;
1820
- for (let i = 0; i <= 100; i++) {
1821
- const angle = startAngle + angleDiff * i / 100;
1822
- x = center[0] + radius * Math.cos(angle);
1823
- y = center[1] + radius * Math.sin(angle);
1824
- coords.push([x, y]);
1825
- }
1826
- return coords;
1827
- }
1155
+ //#region measure/utils/clampToGround.ts
1828
1156
  /**
1829
- * getBisectorNormals
1830
- * @param t
1831
- * @param coord1
1832
- * @param coord2
1833
- * @param coord3
1834
- */
1835
- function getBisectorNormals(t, coord1, coord2, coord3) {
1836
- const normal = getNormal(coord1, coord2, coord3);
1837
- let [bisectorNormalRight, bisectorNormalLeft, dt, x, y] = [
1838
- [0, 0],
1839
- [0, 0],
1840
- 0,
1841
- 0,
1842
- 0
1843
- ];
1844
- const dist = Math.hypot(normal[0], normal[1]);
1845
- const uX = normal[0] / dist;
1846
- const uY = normal[1] / dist;
1847
- const d1 = mathDistance(coord1, coord2);
1848
- const d2 = mathDistance(coord2, coord3);
1849
- if (dist > ZERO_TOLERANCE) if (isClockWise(coord1, coord2, coord3)) {
1850
- dt = t * d1;
1851
- x = coord2[0] - dt * uY;
1852
- y = coord2[1] + dt * uX;
1853
- bisectorNormalRight = [x, y];
1854
- dt = t * d2;
1855
- x = coord2[0] + dt * uY;
1856
- y = coord2[1] - dt * uX;
1857
- bisectorNormalLeft = [x, y];
1858
- } else {
1859
- dt = t * d1;
1860
- x = coord2[0] + dt * uY;
1861
- y = coord2[1] - dt * uX;
1862
- bisectorNormalRight = [x, y];
1863
- dt = t * d2;
1864
- x = coord2[0] - dt * uY;
1865
- y = coord2[1] + dt * uX;
1866
- bisectorNormalLeft = [x, y];
1157
+ * 将传入的点位列表进行贴地处理,若某个点位获取高程失败则将此进行克隆返回
1158
+ * @param options - 配置项
1159
+ */
1160
+ async function clampToHeightMostDetailedByTilesetOrTerrain(options) {
1161
+ const { positions, scene, classificationType = cesium.ClassificationType.BOTH, terrainProvider = scene.terrainProvider } = options;
1162
+ const tileset = [cesium.ClassificationType.BOTH, cesium.ClassificationType.CESIUM_3D_TILE].includes(classificationType);
1163
+ const terrain = [cesium.ClassificationType.BOTH, cesium.ClassificationType.TERRAIN].includes(classificationType);
1164
+ const tilesetPromise = new Promise((resolve) => {
1165
+ if (tileset) scene.clampToHeightMostDetailed(positions.map((e) => e.clone())).then(resolve).catch((error) => {
1166
+ console.warn(error);
1167
+ resolve([]);
1168
+ });
1169
+ else resolve([]);
1170
+ });
1171
+ const terrainPromise = new Promise((resolve) => {
1172
+ if (terrain && terrainProvider) (0, cesium.sampleTerrainMostDetailed)(terrainProvider, positions.map((e) => cesium.Cartographic.fromCartesian(e))).then((e) => resolve(e)).catch((error) => {
1173
+ console.warn(error);
1174
+ resolve([]);
1175
+ });
1176
+ else resolve([]);
1177
+ });
1178
+ const [tilesetPositions, terrainPositions] = await Promise.all([tilesetPromise, terrainPromise]);
1179
+ const results = [];
1180
+ positions.forEach((item, index) => {
1181
+ const position = tilesetPositions[index] || terrainPositions[index] ? cesium.Ellipsoid.WGS84.cartographicToCartesian(terrainPositions[index]) : item.clone();
1182
+ results.push(position);
1183
+ });
1184
+ return results;
1867
1185
  }
1868
- else {
1869
- x = coord2[0] + t * (coord1[0] - coord2[0]);
1870
- y = coord2[1] + t * (coord1[1] - coord2[1]);
1871
- bisectorNormalRight = [x, y];
1872
- x = coord2[0] + t * (coord3[0] - coord2[0]);
1873
- y = coord2[1] + t * (coord3[1] - coord2[1]);
1874
- bisectorNormalLeft = [x, y];
1186
+
1187
+ //#endregion
1188
+ //#region measure/utils/triangleGrid.ts
1189
+ function defaultOptions$2(original) {
1190
+ const clampToGround = original?.clampToGround ?? false;
1191
+ const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1192
+ const density = Math.floor(original?.density ?? 10);
1193
+ return {
1194
+ scene: original?.scene,
1195
+ clampToGround,
1196
+ classificationType,
1197
+ terrainProvider: original?.terrainProvider,
1198
+ density
1199
+ };
1875
1200
  }
1876
- return [bisectorNormalRight, bisectorNormalLeft];
1877
- }
1878
- /**
1879
- * 获取默认三点的内切圆
1880
- * @param coord1
1881
- * @param coord2
1882
- * @param coord3
1883
- */
1884
- function getNormal(coord1, coord2, coord3) {
1885
- let dX1 = coord1[0] - coord2[0];
1886
- let dY1 = coord1[1] - coord2[1];
1887
- const d1 = Math.hypot(dX1, dY1);
1888
- dX1 /= d1;
1889
- dY1 /= d1;
1890
- let dX2 = coord3[0] - coord2[0];
1891
- let dY2 = coord3[1] - coord2[1];
1892
- const d2 = Math.hypot(dX2, dY2);
1893
- dX2 /= d2;
1894
- dY2 /= d2;
1895
- const uX = dX1 + dX2;
1896
- const uY = dY1 + dY2;
1897
- return [uX, uY];
1898
- }
1899
- /**
1900
- * 贝塞尔曲线
1901
- * @param points
1902
- */
1903
- function getBezierCoords(points) {
1904
- if (points.length <= 2) return points;
1905
- const bezierCoords = [];
1906
- const n = points.length - 1;
1907
- for (let t = 0; t <= 1; t += .01) {
1908
- let [x, y] = [0, 0];
1909
- for (let index = 0; index <= n; index++) {
1910
- const factor = getBinomialFactor(n, index);
1911
- const a = t ** index;
1912
- const b = (1 - t) ** (n - index);
1913
- x += factor * a * b * points[index][0];
1914
- y += factor * a * b * points[index][1];
1201
+ /**
1202
+ * 生成三角网数组
1203
+ * @param positions - 边界点数组
1204
+ * @param options - 配置项
1205
+ */
1206
+ async function triangleGrid(positions, options) {
1207
+ if (positions.length < 3) throw new Error("positions must >= 3");
1208
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$2(options);
1209
+ if (density <= 0) throw new Error("options.density must > 0");
1210
+ const bbox = cesium.Rectangle.fromCartesianArray(positions);
1211
+ const vertical = bbox.north - bbox.south;
1212
+ const horizontal = bbox.east - bbox.west;
1213
+ const granularity = Math.max(horizontal, vertical) / density;
1214
+ const polygonGeometry = cesium.PolygonGeometry.fromPositions({
1215
+ positions,
1216
+ vertexFormat: cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
1217
+ granularity
1218
+ });
1219
+ const geometry = cesium.PolygonGeometry.createGeometry(polygonGeometry);
1220
+ const values = geometry.attributes.position.values;
1221
+ if (!geometry || !values) throw new Error("positions无法组成有效的geometry,检查点位是否错误");
1222
+ const indices = geometry.indices;
1223
+ let cartesian3List = [];
1224
+ for (let i = 0; i < indices.length; i += 3) {
1225
+ const a = cesium.Cartesian3.unpack(values, indices[i] * 3, new cesium.Cartesian3());
1226
+ const b = cesium.Cartesian3.unpack(values, indices[i + 1] * 3, new cesium.Cartesian3());
1227
+ const c = cesium.Cartesian3.unpack(values, indices[i + 2] * 3, new cesium.Cartesian3());
1228
+ cartesian3List.push(a, b, c);
1915
1229
  }
1916
- bezierCoords.push([x, y]);
1917
- }
1918
- bezierCoords.push(points[n]);
1919
- return bezierCoords;
1920
- }
1921
- /**
1922
- * 获取阶乘数据
1923
- * @param n
1924
- */
1925
- function getFactorial(n) {
1926
- let result = 1;
1927
- switch (true) {
1928
- case n <= 1:
1929
- result = 1;
1930
- break;
1931
- case n === 2:
1932
- result = 2;
1933
- break;
1934
- case n === 3:
1935
- result = 6;
1936
- break;
1937
- case n === 24:
1938
- result = 24;
1939
- break;
1940
- case n === 5:
1941
- result = 120;
1942
- break;
1943
- default:
1944
- for (let i = 1; i <= n; i++) result *= i;
1945
- break;
1946
- }
1947
- return result;
1948
- }
1949
- /**
1950
- * 获取二项分布
1951
- * @param n
1952
- * @param index
1953
- */
1954
- function getBinomialFactor(n, index) {
1955
- return getFactorial(n) / (getFactorial(index) * getFactorial(n - index));
1956
- }
1957
- /**
1958
- * 插值线性点
1959
- * @param points
1960
- */
1961
- function getQBSplineCoords(points) {
1962
- if (points.length <= 2) return points;
1963
- const [n, bSplineCoords] = [2, []];
1964
- const m = points.length - n - 1;
1965
- bSplineCoords.push(points[0]);
1966
- for (let i = 0; i <= m; i++) for (let t = 0; t <= 1; t += .05) {
1967
- let [x, y] = [0, 0];
1968
- for (let k = 0; k <= n; k++) {
1969
- const factor = getQuadricBSplineFactor(k, t);
1970
- x += factor * points[i + k][0];
1971
- y += factor * points[i + k][1];
1230
+ if (clampToGround) {
1231
+ if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1232
+ cartesian3List = await clampToHeightMostDetailedByTilesetOrTerrain({
1233
+ scene,
1234
+ terrainProvider,
1235
+ positions: cartesian3List,
1236
+ classificationType
1237
+ });
1972
1238
  }
1973
- bSplineCoords.push([x, y]);
1239
+ const grid = [];
1240
+ while (cartesian3List?.length) {
1241
+ const [a, b, c] = cartesian3List.splice(0, 3);
1242
+ grid.push([
1243
+ a,
1244
+ b,
1245
+ c
1246
+ ]);
1247
+ }
1248
+ return grid;
1974
1249
  }
1975
- bSplineCoords.push(points.at(-1));
1976
- return bSplineCoords;
1977
- }
1978
- /**
1979
- * 得到二次线性因子
1980
- * @param k
1981
- * @param t
1982
- */
1983
- function getQuadricBSplineFactor(k, t) {
1984
- let res = 0;
1985
- if (k === 0) res = (t - 1) ** 2 / 2;
1986
- else if (k === 1) res = (-2 * t ** 2 + 2 * t + 1) / 2;
1987
- else if (k === 2) res = t ** 2 / 2;
1988
- return res;
1989
- }
1990
1250
 
1991
1251
  //#endregion
1992
- //#region geom/arc.ts
1252
+ //#region measure/utils/area.ts
1993
1253
  /**
1994
- * 标绘画弓形算法,继承线要素相关方法和属性
1995
- */
1996
- function arc(coords) {
1997
- const coordlength = coords.length;
1998
- if (coordlength <= 2) throw new Error("coords.length must >= 3");
1999
- else {
2000
- let [coord1, coord2, coord3, startAngle, endAngle] = [
2001
- coords[0],
2002
- coords[1],
2003
- coords[2],
2004
- 0,
2005
- 0
2006
- ];
2007
- const center = getCircleCenterOfThreeCoords(coord1, coord2, coord3);
2008
- const radius = mathDistance(coord1, center);
2009
- const angle1 = getAzimuth(coord1, center);
2010
- const angle2 = getAzimuth(coord2, center);
2011
- if (isClockWise(coord1, coord2, coord3)) {
2012
- startAngle = angle2;
2013
- endAngle = angle1;
2014
- } else {
2015
- startAngle = angle1;
2016
- endAngle = angle2;
2017
- }
2018
- return getArcCoords(center, radius, startAngle, endAngle);
1254
+ * 计算三维坐标系下三角形面积
1255
+ * @param p0 - 三角形第一个点
1256
+ * @param p1 - 三角形第二个点
1257
+ * @param p2 - 三角形第三个点
1258
+ */
1259
+ function triangleArea(p0, p1, p2) {
1260
+ const v0 = cesium.Cartesian3.subtract(p0, p1, new cesium.Cartesian3());
1261
+ const v1 = cesium.Cartesian3.subtract(p2, p1, new cesium.Cartesian3());
1262
+ const cross = cesium.Cartesian3.cross(v0, v1, v0);
1263
+ return cesium.Cartesian3.magnitude(cross) * .5;
1264
+ }
1265
+ function defaultOptions$1(original) {
1266
+ const clampToGround = original?.clampToGround ?? false;
1267
+ const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1268
+ const density = Math.floor(original?.density ?? 10);
1269
+ return {
1270
+ scene: original?.scene,
1271
+ clampToGround,
1272
+ classificationType,
1273
+ terrainProvider: original?.terrainProvider,
1274
+ density
1275
+ };
1276
+ }
1277
+ /**
1278
+ * 计算三维坐标系下图形面积
1279
+ * @param positions - 图形各点的笛卡尔数组
1280
+ */
1281
+ async function area(positions, options) {
1282
+ if (positions.length < 2) throw new Error("positions.length must >= 2");
1283
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1284
+ if (density <= 0) throw new Error("options.density must > 0");
1285
+ if (!clampToGround) return tesselate(positions).reduce((count, current) => count += triangleArea(...current), 0);
1286
+ return (await triangleGrid(positions, {
1287
+ density,
1288
+ scene,
1289
+ clampToGround,
1290
+ classificationType,
1291
+ terrainProvider
1292
+ })).reduce((count, current) => count += triangleArea(...current), 0);
2019
1293
  }
2020
- }
2021
1294
 
2022
1295
  //#endregion
2023
- //#region geom/arrowAttackDirection.ts
1296
+ //#region measure/utils/lerpArray.ts
2024
1297
  /**
2025
- * 尖曲箭头
2026
- */
2027
- function arrowAttackDirection(coords, options = {}) {
2028
- const coordLength = coords.length;
2029
- if (coordLength < 3) throw new Error("coords.length must >= 3");
2030
- else {
2031
- let [tailLeft, tailRight] = [coords[0], coords[1]];
2032
- if (isClockWise(coords[0], coords[1], coords[2])) {
2033
- tailLeft = coords[1];
2034
- tailRight = coords[0];
1298
+ * 在起点和终点间进行插值, 返回的数组包括起点和终点,数组长度为 count+1
1299
+ */
1300
+ async function lerpArray(options) {
1301
+ const { start, end, count, scene, clampToGround, classificationType, terrainProvider } = options;
1302
+ const result = [];
1303
+ for (let i = 0; i < count; i++) {
1304
+ const position = cesium.Cartesian3.lerp(start, end, 1 / count, new cesium.Cartesian3());
1305
+ result.push(position);
2035
1306
  }
2036
- const midTail = mid(tailLeft, tailRight);
2037
- const boneCoords = [midTail].concat(coords.slice(2));
2038
- const headCoords = getArrowHeadCoords(boneCoords, {
2039
- tailLeft,
2040
- tailRight,
2041
- ...options
1307
+ result.push(end.clone());
1308
+ if (!clampToGround) return result;
1309
+ if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1310
+ return await clampToHeightMostDetailedByTilesetOrTerrain({
1311
+ scene,
1312
+ terrainProvider,
1313
+ positions: result,
1314
+ classificationType
2042
1315
  });
2043
- if (headCoords && headCoords.length > 4) {
2044
- const [neckLeft, neckRight] = [headCoords[0], headCoords[4]];
2045
- const tailWidthFactor = mathDistance(tailLeft, tailRight) / getBaseLength(boneCoords);
2046
- const bodyCoords = getArrowBodyCoords(boneCoords, neckLeft, neckRight, tailWidthFactor);
2047
- const coordlength = bodyCoords.length;
2048
- let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength / 2));
2049
- leftCoords.push(neckLeft);
2050
- let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength / 2, coordlength));
2051
- rightCoords.push(neckRight);
2052
- leftCoords = getQBSplineCoords(leftCoords);
2053
- rightCoords = getQBSplineCoords(rightCoords);
2054
- return leftCoords.concat(headCoords, rightCoords.reverse());
2055
- } else return [];
2056
- }
2057
- }
2058
- /**
2059
- * 插值头部点
2060
- */
2061
- function getArrowHeadCoords(points, options) {
2062
- const { tailLeft, tailRight, headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, headTailFactor = .8 } = options;
2063
- let len = getBaseLength(points);
2064
- let headHeight = len * headHeightFactor;
2065
- const headCoord = points.at(-1);
2066
- len = mathDistance(headCoord, points.at(-2));
2067
- let tailWidth = 0;
2068
- if (tailLeft && tailRight) tailWidth = mathDistance(tailLeft, tailRight);
2069
- if (headHeight > tailWidth * headTailFactor) headHeight = tailWidth * headTailFactor;
2070
- const headWidth = headHeight * headWidthFactor;
2071
- const neckWidth = headHeight * neckWidthFactor;
2072
- headHeight = Math.min(headHeight, len);
2073
- const neckHeight = headHeight * neckHeightFactor;
2074
- const headEndCoord = getThirdCoord(points.at(-2), headCoord, 0, headHeight, true);
2075
- const neckEndCoord = getThirdCoord(points.at(-2), headCoord, 0, neckHeight, true);
2076
- const headLeft = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, false);
2077
- const headRight = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, true);
2078
- const neckLeft = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, false);
2079
- const neckRight = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, true);
2080
- return [
2081
- neckLeft,
2082
- headLeft,
2083
- headCoord,
2084
- headRight,
2085
- neckRight
2086
- ];
2087
- }
2088
- /**
2089
- * 插值面部分数据
2090
- * @param points
2091
- * @param neckLeft
2092
- * @param neckRight
2093
- * @param tailWidthFactor
2094
- */
2095
- function getArrowBodyCoords(points, neckLeft, neckRight, tailWidthFactor) {
2096
- const allLen = wholeDistance(points);
2097
- const len = getBaseLength(points);
2098
- const tailWidth = len * tailWidthFactor;
2099
- const neckWidth = mathDistance(neckLeft, neckRight);
2100
- const widthDif = (tailWidth - neckWidth) / 2;
2101
- let tempLen = 0;
2102
- const leftBodyCoords = [];
2103
- const rightBodyCoords = [];
2104
- for (let i = 1; i < points.length - 1; i++) {
2105
- const angle = getAngleOfThreeCoords(points[i - 1], points[i], points[i + 1]) / 2;
2106
- tempLen += mathDistance(points[i - 1], points[i]);
2107
- const w = (tailWidth / 2 - tempLen / allLen * widthDif) / Math.sin(angle);
2108
- const left = getThirdCoord(points[i - 1], points[i], Math.PI - angle, w, true);
2109
- const right = getThirdCoord(points[i - 1], points[i], angle, w, false);
2110
- leftBodyCoords.push(left);
2111
- rightBodyCoords.push(right);
2112
1316
  }
2113
- return leftBodyCoords.concat(rightBodyCoords);
2114
- }
2115
1317
 
2116
1318
  //#endregion
2117
- //#region geom/arrowAttackDirectionTailed.ts
2118
- /**
2119
- * 燕尾尖曲箭头
2120
- */
2121
- function arrowAttackDirectionTailed(coords, options = {}) {
2122
- const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1, swallowTailFactor = 1 } = options;
2123
- const coordLength = coords.length;
2124
- if (coordLength < 3) throw new Error("coords.length must >= 3");
2125
- let [tailLeft, tailRight] = [coords[0], coords[1]];
2126
- if (isClockWise(coords[0], coords[1], coords[2])) {
2127
- tailLeft = coords[1];
2128
- tailRight = coords[0];
1319
+ //#region measure/utils/distance.ts
1320
+ function defaultOptions(original) {
1321
+ const clampToGround = original?.clampToGround ?? false;
1322
+ const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1323
+ const density = Math.floor(original?.density ?? 50);
1324
+ return {
1325
+ scene: original?.scene,
1326
+ clampToGround,
1327
+ classificationType,
1328
+ terrainProvider: original?.terrainProvider,
1329
+ density
1330
+ };
1331
+ }
1332
+ /**
1333
+ * 计算多点位之间的距离
1334
+ * @param positions
1335
+ */
1336
+ async function distance(positions, options) {
1337
+ if (positions.length < 2) throw new Error("positions.length must >= 2");
1338
+ const _options = defaultOptions(options);
1339
+ const stages = [];
1340
+ let count = 0;
1341
+ positions.forEach((position, index) => {
1342
+ if (index !== positions.length - 1) {
1343
+ const next = positions[index + 1];
1344
+ const distance$1 = cesium.Cartesian3.distance(position, next);
1345
+ stages.push(distance$1);
1346
+ count += distance$1;
1347
+ }
1348
+ });
1349
+ if (!_options.clampToGround) return {
1350
+ stages,
1351
+ count
1352
+ };
1353
+ const density = _options.density;
1354
+ if (density <= 0) throw new Error("options.density must > 0");
1355
+ const densities = stages.map((stage) => {
1356
+ return Math.floor(stage / count * density);
1357
+ });
1358
+ const diff = density - densities.reduce((count$1, current) => count$1 += current, 0);
1359
+ if (diff) densities[densities.length - 1] += diff;
1360
+ const positionListPromises = densities.map((density$1, i) => {
1361
+ return lerpArray({
1362
+ scene: _options.scene,
1363
+ start: positions[i],
1364
+ end: positions[i + 1],
1365
+ count: density$1,
1366
+ clampToGround: true,
1367
+ classificationType: _options.classificationType,
1368
+ terrainProvider: _options.terrainProvider
1369
+ });
1370
+ });
1371
+ const stagePromises = (await Promise.all(positionListPromises)).map(async (positions$1) => {
1372
+ const { count: count$1 } = await distance(positions$1);
1373
+ return count$1;
1374
+ });
1375
+ const groundStages = await Promise.all(stagePromises);
1376
+ return {
1377
+ stages: groundStages,
1378
+ count: groundStages.reduce((count$1, current) => count$1 += current, 0)
1379
+ };
2129
1380
  }
2130
- const midTail = mid(tailLeft, tailRight);
2131
- const boneCoords = [midTail].concat(coords.slice(2));
2132
- const headCoords = getArrowHeadCoords(boneCoords, {
2133
- tailLeft,
2134
- tailRight,
2135
- headHeightFactor,
2136
- headWidthFactor,
2137
- neckWidthFactor,
2138
- neckHeightFactor
2139
- });
2140
- if (headCoords && headCoords.length > 4) {
2141
- const [neckLeft, neckRight] = [headCoords[0], headCoords[4]];
2142
- const tailWidth = mathDistance(tailLeft, tailRight);
2143
- const allLen = getBaseLength(boneCoords);
2144
- const len = allLen * tailWidthFactor * swallowTailFactor;
2145
- const swallowTailCoord = getThirdCoord(boneCoords[1], boneCoords[0], 0, len, true);
2146
- const factor = tailWidth / allLen;
2147
- const bodyCoords = getArrowBodyCoords(boneCoords, neckLeft, neckRight, factor);
2148
- const coordlength = bodyCoords.length;
2149
- let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength / 2));
2150
- leftCoords.push(neckLeft);
2151
- let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength / 2, coordlength));
2152
- rightCoords.push(neckRight);
2153
- leftCoords = getQBSplineCoords(leftCoords);
2154
- rightCoords = getQBSplineCoords(rightCoords);
2155
- return leftCoords.concat(headCoords, rightCoords.reverse(), [swallowTailCoord, leftCoords[0]]);
2156
- } else return [];
2157
- }
2158
1381
 
2159
1382
  //#endregion
2160
- //#region geom/arrowClamped.ts
2161
- /**
2162
- * 钳击箭头 有效点位长度3,4,5
2163
- */
2164
- function arrowClamped(coords) {
2165
- const options = {
2166
- headHeightFactor: .25,
2167
- headWidthFactor: .3,
2168
- neckHeightFactor: .85,
2169
- neckWidthFactor: .15
2170
- };
2171
- if (coords.length < 3) throw new Error(`coords.length must >= 3`);
2172
- const [coord1, coord2, coord3] = coords;
2173
- let tempCoord4, connCoord;
2174
- if (coords.length === 3) {
2175
- tempCoord4 = getTempCoord4(coord1, coord2, coord3);
2176
- connCoord = mid(coord1, coord2);
2177
- } else if (coords.length === 4) {
2178
- tempCoord4 = coords[3];
2179
- connCoord = mid(coord1, coord2);
2180
- } else {
2181
- tempCoord4 = coords[3];
2182
- connCoord = coords[4];
2183
- }
2184
- let leftArrowCoords;
2185
- let rightArrowCoords;
2186
- if (isClockWise(coord1, coord2, coord3)) {
2187
- leftArrowCoords = getArrowCoords(coord1, connCoord, tempCoord4, false, options);
2188
- rightArrowCoords = getArrowCoords(connCoord, coord2, coord3, true, options);
2189
- } else {
2190
- leftArrowCoords = getArrowCoords(coord2, connCoord, coord3, false, options);
2191
- rightArrowCoords = getArrowCoords(connCoord, coord1, tempCoord4, true, options);
2192
- }
2193
- const m = leftArrowCoords.length;
2194
- const t = (m - 5) / 2;
2195
- const llBodyCoords = leftArrowCoords.slice(0, t);
2196
- const lArrowCoords = leftArrowCoords.slice(t, t + 5);
2197
- let lrBodyCoords = leftArrowCoords.slice(t + 5, m);
2198
- let rlBodyCoords = rightArrowCoords.slice(0, t);
2199
- const rArrowCoords = rightArrowCoords.slice(t, t + 5);
2200
- const rrBodyCoords = rightArrowCoords.slice(t + 5, m);
2201
- rlBodyCoords = getBezierCoords(rlBodyCoords);
2202
- const bodyCoords = getBezierCoords(rrBodyCoords.concat(llBodyCoords.slice(1)));
2203
- lrBodyCoords = getBezierCoords(lrBodyCoords);
2204
- return rlBodyCoords.concat(rArrowCoords, bodyCoords, lArrowCoords, lrBodyCoords);
2205
- }
2206
- /**
2207
- * 插值箭形上的点
2208
- * @param coord1 - Wgs84坐标
2209
- * @param coord2 - Wgs84坐标
2210
- * @param coord3 - Wgs84坐标
2211
- * @param clockWise - 是否顺时针
2212
- */
2213
- function getArrowCoords(coord1, coord2, coord3, clockWise, options) {
2214
- const midCoord = mid(coord1, coord2);
2215
- const len = mathDistance(midCoord, coord3);
2216
- let midCoord1 = getThirdCoord(coord3, midCoord, 0, len * .3, true);
2217
- let midCoord2 = getThirdCoord(coord3, midCoord, 0, len * .5, true);
2218
- midCoord1 = getThirdCoord(midCoord, midCoord1, HALF_PI, len / 5, clockWise);
2219
- midCoord2 = getThirdCoord(midCoord, midCoord2, HALF_PI, len / 4, clockWise);
2220
- const coords = [
2221
- midCoord,
2222
- midCoord1,
2223
- midCoord2,
2224
- coord3
2225
- ];
2226
- const arrowCoords = getArrowHeadCoords$1(coords, options);
2227
- if (arrowCoords && Array.isArray(arrowCoords) && arrowCoords.length > 0) {
2228
- const [neckLeftCoord, neckRightCoord] = [arrowCoords[0], arrowCoords[4]];
2229
- const tailWidthFactor = mathDistance(coord1, coord2) / getBaseLength(coords) / 2;
2230
- const bodyCoords = getArrowBodyCoords$1(coords, neckLeftCoord, neckRightCoord, tailWidthFactor);
2231
- const n = bodyCoords.length;
2232
- let lCoords = bodyCoords.slice(0, n / 2);
2233
- let rCoords = bodyCoords.slice(n / 2, n);
2234
- lCoords.push(neckLeftCoord);
2235
- rCoords.push(neckRightCoord);
2236
- lCoords = lCoords.reverse();
2237
- lCoords.push(coord2);
2238
- rCoords = rCoords.reverse();
2239
- rCoords.push(coord1);
2240
- return lCoords.reverse().concat(arrowCoords, rCoords);
2241
- } else throw new Error("插值出错");
2242
- }
2243
- /**
2244
- * 插值头部点
2245
- * @param coords
2246
- */
2247
- function getArrowHeadCoords$1(coords, options) {
2248
- const { headHeightFactor, headWidthFactor, neckWidthFactor, neckHeightFactor } = options;
2249
- const len = getBaseLength(coords);
2250
- const headHeight = len * headHeightFactor;
2251
- const headCoord = coords.at(-1);
2252
- const headWidth = headHeight * headWidthFactor;
2253
- const neckWidth = headHeight * neckWidthFactor;
2254
- const neckHeight = headHeight * neckHeightFactor;
2255
- const headEndCoord = getThirdCoord(coords.at(-2), headCoord, 0, headHeight, true);
2256
- const neckEndCoord = getThirdCoord(coords.at(-2), headCoord, 0, neckHeight, true);
2257
- const headLeft = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, false);
2258
- const headRight = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, true);
2259
- const neckLeft = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, false);
2260
- const neckRight = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, true);
2261
- return [
2262
- neckLeft,
2263
- headLeft,
2264
- headCoord,
2265
- headRight,
2266
- neckRight
2267
- ];
2268
- }
2269
- /**
2270
- * 插值面部分数据
2271
- * @param coords
2272
- * @param neckLeft
2273
- * @param neckRight
2274
- * @param tailWidthFactor
2275
- */
2276
- function getArrowBodyCoords$1(coords, neckLeft, neckRight, tailWidthFactor) {
2277
- const allLen = wholeDistance(coords);
2278
- const len = getBaseLength(coords);
2279
- const tailWidth = len * tailWidthFactor;
2280
- const neckWidth = mathDistance(neckLeft, neckRight);
2281
- const widthDif = (tailWidth - neckWidth) / 2;
2282
- let tempLen = 0;
2283
- const leftBodyCoords = [];
2284
- const rightBodyCoords = [];
2285
- for (let i = 1; i < coords.length - 1; i++) {
2286
- const angle = getAngleOfThreeCoords(coords[i - 1], coords[i], coords[i + 1]) / 2;
2287
- tempLen += mathDistance(coords[i - 1], coords[i]);
2288
- const w = (tailWidth / 2 - tempLen / allLen * widthDif) / Math.sin(angle);
2289
- const left = getThirdCoord(coords[i - 1], coords[i], Math.PI - angle, w, true);
2290
- const right = getThirdCoord(coords[i - 1], coords[i], angle, w, false);
2291
- leftBodyCoords.push(left);
2292
- rightBodyCoords.push(right);
2293
- }
2294
- return leftBodyCoords.concat(rightBodyCoords);
2295
- }
2296
- /**
2297
- * 获取对称点
2298
- * @param lineCoord1
2299
- * @param lineCoord2
2300
- * @param coord
2301
- */
2302
- function getTempCoord4(lineCoord1, lineCoord2, coord) {
2303
- const midCoord = mid(lineCoord1, lineCoord2);
2304
- const len = mathDistance(midCoord, coord);
2305
- const angle = getAngleOfThreeCoords(lineCoord1, midCoord, coord);
2306
- if (angle < HALF_PI) {
2307
- const distance1 = len * Math.sin(angle);
2308
- const distance2 = len * Math.cos(angle);
2309
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, false);
2310
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, true);
2311
- } else if (angle >= HALF_PI && angle < Math.PI) {
2312
- const distance1 = len * Math.sin(Math.PI - angle);
2313
- const distance2 = len * Math.cos(Math.PI - angle);
2314
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, false);
2315
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, false);
2316
- } else if (angle >= Math.PI && angle < Math.PI * 1.5) {
2317
- const distance1 = len * Math.sin(angle - Math.PI);
2318
- const distance2 = len * Math.cos(angle - Math.PI);
2319
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true);
2320
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, true);
2321
- } else {
2322
- const distance1 = len * Math.sin(Math.PI * 2 - angle);
2323
- const distance2 = len * Math.cos(Math.PI * 2 - angle);
2324
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true);
2325
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, false);
2326
- }
2327
- }
1383
+ //#region measure/measureArea.ts
1384
+ const schemeMeasureArea = new PlotScheme({
1385
+ type: "MeasureArea",
1386
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1387
+ skeletons: [control, interval],
1388
+ initRender() {
1389
+ return { entities: [new cesium.Entity({
1390
+ label: { font: "14pt" },
1391
+ polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
1392
+ polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
1393
+ })] };
1394
+ },
1395
+ render(context) {
1396
+ const entity = context.previous.entities[0];
1397
+ const { mouse, packable } = context;
1398
+ const positions = [...packable.positions ?? []];
1399
+ mouse && positions.push(mouse);
1400
+ if (positions.length === 2) {
1401
+ entity.position = void 0;
1402
+ entity.label.text = void 0;
1403
+ entity.polygon.hierarchy = void 0;
1404
+ entity.polyline.positions = new cesium.CallbackProperty(() => positions, false);
1405
+ } else if (positions.length >= 3) {
1406
+ positions.push(positions[0]);
1407
+ entity.position = new cesium.ConstantPositionProperty((0, vesium.toCartesian3)(cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions))));
1408
+ entity.label.text = new cesium.ConstantProperty("");
1409
+ area(positions).then((e) => {
1410
+ let text = "";
1411
+ if (e / 1e3 / 1e3 > 10) text = `${(e / 1e3 / 1e3).toFixed(2)}km²`;
1412
+ else text = `${(+e).toFixed(2)}m²`;
1413
+ entity.label.text = new cesium.ConstantProperty(text);
1414
+ });
1415
+ entity.polyline.positions = void 0;
1416
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => {
1417
+ return positions.length >= 3 ? new cesium.PolygonHierarchy([...positions]) : void 0;
1418
+ }, false);
1419
+ } else {
1420
+ entity.position = void 0;
1421
+ entity.polygon.hierarchy = void 0;
1422
+ entity.polyline.positions = void 0;
1423
+ }
1424
+ return { entities: [entity] };
1425
+ }
1426
+ });
2328
1427
 
2329
1428
  //#endregion
2330
- //#region geom/arrowStraightSharp.ts
2331
- /**
2332
- * 尖箭头
2333
- *
2334
- */
2335
- function arrowStraightSharp(coords, options = {}) {
2336
- const { tailWidthFactor = .1, neckWidthFactor = .2, headWidthFactor = .25, headAngle = Math.PI / 8.5, neckAngle = Math.PI / 13 } = options;
2337
- const coordlength = coords.length;
2338
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2339
- const [coord1, coord2] = [coords[0], coords[1]];
2340
- const len = getBaseLength(coords);
2341
- const tailWidth = len * tailWidthFactor;
2342
- const neckWidth = len * neckWidthFactor;
2343
- const headWidth = len * headWidthFactor;
2344
- const tailLeft = getThirdCoord(coord2, coord1, HALF_PI, tailWidth, true);
2345
- const tailRight = getThirdCoord(coord2, coord1, HALF_PI, tailWidth, false);
2346
- const headLeft = getThirdCoord(coord1, coord2, headAngle, headWidth, false);
2347
- const headRight = getThirdCoord(coord1, coord2, headAngle, headWidth, true);
2348
- const neckLeft = getThirdCoord(coord1, coord2, neckAngle, neckWidth, false);
2349
- const neckRight = getThirdCoord(coord1, coord2, neckAngle, neckWidth, true);
2350
- const pList = [
2351
- tailLeft,
2352
- neckLeft,
2353
- headLeft,
2354
- coord2,
2355
- headRight,
2356
- neckRight,
2357
- tailRight
2358
- ];
2359
- return pList;
2360
- }
1429
+ //#region measure/measureDistance.ts
1430
+ const schemeMeasureDistance = new PlotScheme({
1431
+ type: "MeasureDistance",
1432
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1433
+ skeletons: [control],
1434
+ initRender() {
1435
+ return { entities: [new cesium.Entity({ polyline: {
1436
+ width: 2,
1437
+ material: cesium.Color.YELLOW.withAlpha(.5)
1438
+ } })] };
1439
+ },
1440
+ render(context) {
1441
+ context.previous.entities[0];
1442
+ const { mouse, packable, previous } = context;
1443
+ const entities = previous.entities;
1444
+ const positions = [...packable.positions ?? []];
1445
+ mouse && positions.push(mouse);
1446
+ if (positions.length < 2) return { entities };
1447
+ const pl = entities[0];
1448
+ pl.polyline ??= new cesium.PolylineGraphics();
1449
+ pl.polyline.positions = new cesium.CallbackProperty(() => positions, false);
1450
+ positions.forEach((item, index) => {
1451
+ if (!entities[index + 1]) entities[index + 1] = new cesium.Entity({
1452
+ position: item,
1453
+ label: new cesium.LabelGraphics({
1454
+ backgroundColor: cesium.Color.fromCssColorString("#fff"),
1455
+ font: "12pt sans-serif"
1456
+ })
1457
+ });
1458
+ });
1459
+ entities.splice(positions.length, entities.length - positions.length - 1);
1460
+ distance(positions).then(({ count, stages }) => {
1461
+ stages.forEach((stage, index) => {
1462
+ entities[index + 1].position = new cesium.CallbackPositionProperty(() => cesium.Cartesian3.midpoint(positions[index], positions[index + 1], new cesium.Cartesian3()), false);
1463
+ entities[index + 1].label.text = new cesium.CallbackProperty(() => `${stage.toFixed(2)} m`, false);
1464
+ });
1465
+ if (stages.length > 1) {
1466
+ entities[entities.length - 1].position = new cesium.CallbackPositionProperty(() => positions[positions.length - 1], false);
1467
+ entities[entities.length - 1].label.text = new cesium.CallbackProperty(() => `${count.toFixed(2)} m`, false);
1468
+ } else {
1469
+ entities[entities.length - 1].position = void 0;
1470
+ entities[entities.length - 1].label.text = void 0;
1471
+ }
1472
+ });
1473
+ return { entities };
1474
+ }
1475
+ });
2361
1476
 
2362
1477
  //#endregion
2363
- //#region geom/arrowStraight.ts
1478
+ //#region scheme/Billboard.ts
2364
1479
  /**
2365
- * 直箭头
2366
- */
2367
- function arrowStraight(coords) {
2368
- const tailWidthFactor = .05;
2369
- const neckWidthFactor = .1;
2370
- const headWidthFactor = .15;
2371
- const headAngle = Math.PI / 4;
2372
- const neckAngle = Math.PI * .17741;
2373
- return arrowStraightSharp(coords, {
2374
- tailWidthFactor,
2375
- neckWidthFactor,
2376
- headWidthFactor,
2377
- headAngle,
2378
- neckAngle
1480
+ * billboard标绘配置
1481
+ */
1482
+ const PlotSchemeBillboard = new PlotScheme({
1483
+ type: "Billboard",
1484
+ complete: (packable) => packable.positions.length >= 1,
1485
+ skeletons: [moved],
1486
+ initRender: () => {
1487
+ return { entities: [new cesium.Entity({ billboard: {
1488
+ image: "/favicon.svg",
1489
+ width: 32,
1490
+ height: 32
1491
+ } })] };
1492
+ },
1493
+ render(options) {
1494
+ const { mouse, packable } = options;
1495
+ const entity = options.previous.entities?.[0] ?? new cesium.Entity({ billboard: {} });
1496
+ const position = packable.positions?.[0] ?? mouse;
1497
+ entity.position = new cesium.CallbackPositionProperty(() => position, true);
1498
+ return { entities: [entity] };
1499
+ }
2379
1500
  });
2380
- }
2381
1501
 
2382
1502
  //#endregion
2383
- //#region geom/arrowUnitCombatOperation.ts
1503
+ //#region scheme/BillboardPinBuilder.ts
2384
1504
  /**
2385
- * 分队战斗行动(尖曲箭头)
2386
- */
2387
- function arrowUnitCombatOperation(coords, options = {}) {
2388
- const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1 } = options;
2389
- const coordlength = coords.length;
2390
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2391
- else {
2392
- const allLen = getBaseLength(coords);
2393
- const tailWidth = allLen * tailWidthFactor;
2394
- const tailLeft = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, false);
2395
- const tailRight = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, true);
2396
- const headCoords = getArrowHeadCoords(coords, {
2397
- tailLeft,
2398
- tailRight,
2399
- headHeightFactor,
2400
- headWidthFactor,
2401
- neckWidthFactor,
2402
- neckHeightFactor
2403
- });
2404
- if (headCoords && headCoords.length > 4) {
2405
- const neckLeft = headCoords[0];
2406
- const neckRight = headCoords[4];
2407
- const bodyCoords = getArrowBodyCoords(coords, neckLeft, neckRight, tailWidthFactor);
2408
- const coordlength$1 = bodyCoords.length;
2409
- let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength$1 / 2));
2410
- leftCoords.push(neckLeft);
2411
- let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength$1 / 2, coordlength$1));
2412
- rightCoords.push(neckRight);
2413
- leftCoords = getQBSplineCoords(leftCoords);
2414
- rightCoords = getQBSplineCoords(rightCoords);
2415
- return leftCoords.concat(headCoords, rightCoords.reverse());
2416
- } else return [];
2417
- }
2418
- }
1505
+ * billboard-pin-builder标绘配置
1506
+ */
1507
+ const PlotSchemeBillboardPinBuilder = new PlotScheme({
1508
+ type: "BillboardPinBuilder",
1509
+ complete: (packable) => packable.positions.length >= 1,
1510
+ skeletons: [moved],
1511
+ initRender() {
1512
+ return { entities: [new cesium.Entity({ billboard: {} })] };
1513
+ },
1514
+ render(context) {
1515
+ const entity = context.previous.entities[0];
1516
+ const position = context.packable.positions[0] ?? context.mouse;
1517
+ entity.position = new cesium.CallbackPositionProperty(() => position, true);
1518
+ return { entities: [entity] };
1519
+ }
1520
+ });
2419
1521
 
2420
1522
  //#endregion
2421
- //#region geom/arrowUnitCombatOperationTailed.ts
1523
+ //#region scheme/Cylinder.ts
2422
1524
  /**
2423
- * 燕尾尖箭头
2424
- */
2425
- function arrowUnitCombatOperationTailed(coords, options = {}) {
2426
- const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1, swallowTailFactor = 1 } = options;
2427
- const coordlength = coords.length;
2428
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2429
- const allLen = getBaseLength(coords);
2430
- const tailWidth = allLen * tailWidthFactor;
2431
- const tailLeft = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, false);
2432
- const tailRight = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, true);
2433
- const len = tailWidth * swallowTailFactor;
2434
- const swallowTailCoord = getThirdCoord(coords[1], coords[0], 0, len, true);
2435
- const tailCoords = [
2436
- tailLeft,
2437
- swallowTailCoord,
2438
- tailRight
2439
- ];
2440
- const headCoords = getArrowHeadCoords(coords, {
2441
- tailLeft: tailCoords[0],
2442
- tailRight: tailCoords[2],
2443
- headHeightFactor,
2444
- headWidthFactor,
2445
- neckWidthFactor,
2446
- neckHeightFactor
1525
+ * cylinder标绘配置
1526
+ */
1527
+ const PlotSchemeCylinder = new PlotScheme({
1528
+ type: "Cylinder",
1529
+ complete: (packable) => packable.positions.length >= 2,
1530
+ skeletons: [moved, control],
1531
+ initRender() {
1532
+ return { entities: [new cesium.Entity({ cylinder: {} })] };
1533
+ },
1534
+ render(context) {
1535
+ const entity = context.previous.entities[0];
1536
+ const positions = [...context.packable.positions];
1537
+ if (positions.length === 0) return context.previous;
1538
+ if (positions.length === 1) {
1539
+ const position = context.mouse;
1540
+ position && positions.push(position);
1541
+ }
1542
+ if (positions.length < 2) return context.previous;
1543
+ entity.position = new cesium.ConstantPositionProperty(positions[0]);
1544
+ const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
1545
+ entity.cylinder.bottomRadius = new cesium.CallbackProperty(() => radius, false);
1546
+ if (context.defining || !(0, vesium.toPropertyValue)(entity.cylinder.length)) entity.cylinder.length = (0, vesium.toProperty)(radius * 2);
1547
+ return { entities: [entity] };
1548
+ }
2447
1549
  });
2448
- if (headCoords && headCoords.length > 4) {
2449
- const neckLeft = headCoords[0];
2450
- const neckRight = headCoords[4];
2451
- const bodyCoords = getArrowBodyCoords(coords, neckLeft, neckRight, tailWidthFactor);
2452
- const coordlength$1 = bodyCoords.length;
2453
- let leftCoords = [tailCoords[0]].concat(bodyCoords.slice(0, coordlength$1 / 2));
2454
- leftCoords.push(neckLeft);
2455
- let rightCoords = [tailCoords[2]].concat(bodyCoords.slice(coordlength$1 / 2, coordlength$1));
2456
- rightCoords.push(neckRight);
2457
- leftCoords = getQBSplineCoords(leftCoords);
2458
- rightCoords = getQBSplineCoords(rightCoords);
2459
- return leftCoords.concat(headCoords, rightCoords.reverse(), [tailCoords[1], leftCoords[0]]);
2460
- }
2461
- return [];
2462
- }
2463
1550
 
2464
1551
  //#endregion
2465
- //#region geom/assemblingPlace.ts
1552
+ //#region scheme/Ellipse.ts
2466
1553
  /**
2467
- * 集结地
2468
- *
2469
- */
2470
- function assemblingPlace(coords) {
2471
- if (coords.length < 3) throw new Error(`coords.length must >= 3`);
2472
- const t = .4;
2473
- const midCoord = mid(coords[0], coords[2]);
2474
- coords.push(midCoord, coords[0], coords[1]);
2475
- let normals = [];
2476
- const pList = [];
2477
- for (let i = 0; i < coords.length - 2; i++) {
2478
- const coord1 = coords[i];
2479
- const coord2 = coords[i + 1];
2480
- const coord3 = coords[i + 2];
2481
- const normalCoords = getBisectorNormals(t, coord1, coord2, coord3);
2482
- normals = normals.concat(normalCoords);
2483
- }
2484
- const count = normals.length;
2485
- normals = [normals[count - 1]].concat(normals.slice(0, count - 1));
2486
- for (let i = 0; i < coords.length - 2; i++) {
2487
- const coord1 = coords[i];
2488
- const coord2 = coords[i + 1];
2489
- pList.push(coord1);
2490
- for (let t$1 = 0; t$1 <= FITTING_COUNT; t$1++) {
2491
- const coord = getCubicValue(t$1 / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
2492
- pList.push(coord);
1554
+ * ellipse标绘配置 圆形扩散波
1555
+ */
1556
+ const PlotSchemeEllipse = new PlotScheme({
1557
+ type: "Ellipse",
1558
+ complete: (packable) => packable.positions.length >= 2,
1559
+ skeletons: [moved, control],
1560
+ initRender() {
1561
+ return { entities: [new cesium.Entity({ ellipse: {} })] };
1562
+ },
1563
+ render(context) {
1564
+ const entity = context.previous.entities[0];
1565
+ const positions = [...context.packable.positions];
1566
+ if (positions.length === 0) return context.previous;
1567
+ if (positions.length === 1) {
1568
+ const position = context.mouse;
1569
+ position && positions.push(position);
1570
+ }
1571
+ if (positions.length < 2) return context.previous;
1572
+ entity.position = new cesium.ConstantPositionProperty(positions[0]);
1573
+ const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
1574
+ entity.ellipse.semiMinorAxis = new cesium.CallbackProperty(() => radius || 1, false);
1575
+ entity.ellipse.semiMajorAxis = entity.ellipse.semiMinorAxis;
1576
+ return { entities: [entity] };
2493
1577
  }
2494
- pList.push(coord2);
2495
- }
2496
- return pList;
2497
- }
1578
+ });
2498
1579
 
2499
1580
  //#endregion
2500
- //#region geom/flagCurve.ts
2501
- /**
2502
- * 曲线旗标
2503
- */
2504
- function flagCurve(coords) {
2505
- const coordlength = coords.length;
2506
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2507
- return calculatePonits(coords);
2508
- }
1581
+ //#region scheme/Label.ts
2509
1582
  /**
2510
- * 插值点数据
2511
- * @param coords
2512
- */
2513
- function calculatePonits(coords) {
2514
- let components = [];
2515
- if (coords.length > 1) {
2516
- const startCoord = coords[0];
2517
- const endCoord = coords.at(-1);
2518
- const coord1 = startCoord;
2519
- const coord2 = [(endCoord[0] - startCoord[0]) / 4 + startCoord[0], (endCoord[1] - startCoord[1]) / 8 + startCoord[1]];
2520
- const coord3 = [(startCoord[0] + endCoord[0]) / 2, startCoord[1]];
2521
- const coord4 = [(endCoord[0] - startCoord[0]) * 3 / 4 + startCoord[0], -(endCoord[1] - startCoord[1]) / 8 + startCoord[1]];
2522
- const coord5 = [endCoord[0], startCoord[1]];
2523
- const coord6 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
2524
- const coord7 = [(endCoord[0] - startCoord[0]) * 3 / 4 + startCoord[0], (endCoord[1] - startCoord[1]) * 3 / 8 + startCoord[1]];
2525
- const coord8 = [(startCoord[0] + endCoord[0]) / 2, (startCoord[1] + endCoord[1]) / 2];
2526
- const coord9 = [(endCoord[0] - startCoord[0]) / 4 + startCoord[0], (endCoord[1] - startCoord[1]) * 5 / 8 + startCoord[1]];
2527
- const coord10 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
2528
- const coord11 = [startCoord[0], endCoord[1]];
2529
- const curve1 = getBezierCoords([
2530
- coord1,
2531
- coord2,
2532
- coord3,
2533
- coord4,
2534
- coord5
2535
- ]);
2536
- const curve2 = getBezierCoords([
2537
- coord6,
2538
- coord7,
2539
- coord8,
2540
- coord9,
2541
- coord10
2542
- ]);
2543
- components = curve1.concat(curve2);
2544
- components.push(coord11);
2545
- }
2546
- return components;
2547
- }
1583
+ * 基础label标绘配置
1584
+ */
1585
+ const PlotSchemeLabel = new PlotScheme({
1586
+ type: "Label",
1587
+ complete: (packable) => packable.positions.length >= 1,
1588
+ skeletons: [moved],
1589
+ initRender() {
1590
+ return { entities: [new cesium.Entity({ label: { text: "Label" } })] };
1591
+ },
1592
+ render(context) {
1593
+ const entity = context.previous.entities[0];
1594
+ const position = context.packable.positions[0] ?? context.mouse;
1595
+ entity.position = new cesium.CallbackPositionProperty(() => position, true);
1596
+ return { entities: [entity] };
1597
+ }
1598
+ });
2548
1599
 
2549
1600
  //#endregion
2550
- //#region geom/flagRect.ts
1601
+ //#region scheme/Point.ts
2551
1602
  /**
2552
- * 直角旗标(使用两个控制点直接创建直角旗标)
2553
- */
2554
- function flagRect(coords) {
2555
- if (coords.length < 2) throw new Error("coords.length must >= 2");
2556
- const [startCoord, endCoord] = coords;
2557
- const coord1 = [endCoord[0], startCoord[1]];
2558
- const coord2 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
2559
- const coord3 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
2560
- const coord4 = [startCoord[0], endCoord[1]];
2561
- return [
2562
- startCoord,
2563
- coord1,
2564
- coord2,
2565
- coord3,
2566
- coord4
2567
- ];
2568
- }
1603
+ * 基础point标绘配置
1604
+ */
1605
+ const PlotSchemePoint = new PlotScheme({
1606
+ type: "Point",
1607
+ complete: (packable) => packable.positions.length >= 1,
1608
+ skeletons: [moved],
1609
+ initRender() {
1610
+ return { entities: [new cesium.Entity({ point: {
1611
+ pixelSize: 10,
1612
+ color: cesium.Color.RED
1613
+ } })] };
1614
+ },
1615
+ render(context) {
1616
+ const entity = context.previous.entities[0];
1617
+ const position = context.packable.positions[0] ?? context.mouse;
1618
+ entity.position = new cesium.CallbackPositionProperty(() => position, true);
1619
+ return { entities: [entity] };
1620
+ }
1621
+ });
2569
1622
 
2570
1623
  //#endregion
2571
- //#region geom/flagTriangle.ts
1624
+ //#region scheme/Polygon.ts
2572
1625
  /**
2573
- * 三角旗标(使用两个控制点直接创建三角旗标)
2574
- */
2575
- function flagTriangle(coords) {
2576
- const coordlength = coords.length;
2577
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2578
- const [startCoord, endCoord] = coords;
2579
- const coord1 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
2580
- const coord2 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
2581
- const coord3 = [startCoord[0], endCoord[1]];
2582
- return [
2583
- startCoord,
2584
- coord1,
2585
- coord2,
2586
- coord3
2587
- ];
2588
- }
1626
+ * 基础Polygon标绘配置
1627
+ */
1628
+ const PlotSchemePolygon = new PlotScheme({
1629
+ type: "Polygon",
1630
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1631
+ skeletons: [
1632
+ moved,
1633
+ control,
1634
+ interval
1635
+ ],
1636
+ initRender: () => {
1637
+ return { entities: [new cesium.Entity({
1638
+ polyline: {},
1639
+ polygon: {}
1640
+ })] };
1641
+ },
1642
+ render(options) {
1643
+ const { mouse, packable } = options;
1644
+ const entity = options.previous.entities[0];
1645
+ const positions = [...packable.positions ?? []];
1646
+ mouse && positions.push(mouse);
1647
+ if (positions.length === 2) {
1648
+ entity.polygon.hierarchy = void 0;
1649
+ entity.polyline.positions = new cesium.CallbackProperty(() => positions, false);
1650
+ } else if (positions.length >= 3) {
1651
+ entity.polyline.positions = void 0;
1652
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => {
1653
+ positions.push(positions[0]);
1654
+ return positions.length >= 3 ? new cesium.PolygonHierarchy([...positions]) : void 0;
1655
+ }, false);
1656
+ } else {
1657
+ entity.polygon.hierarchy = void 0;
1658
+ entity.polyline.positions = void 0;
1659
+ }
1660
+ return { entities: [entity] };
1661
+ }
1662
+ });
2589
1663
 
2590
1664
  //#endregion
2591
1665
  //#region scheme/PolygonArc.ts
2592
- const PlotSchemePolygonArc = new PlotScheme({
2593
- type: "PolygonArc",
2594
- complete: (packable) => packable.positions.length >= 3,
2595
- skeletons: [moved, control],
2596
- initRender() {
2597
- return { entities: [new cesium.Entity({ polygon: {} })] };
2598
- },
2599
- render(context) {
2600
- const entity = context.previous.entities[0];
2601
- const points = context.packable.positions;
2602
- if (points.length < 3) context.mouse && points.push(context.mouse.clone());
2603
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2604
- if (coords.length < 3) {
2605
- entity.polygon.hierarchy = void 0;
2606
- return context.previous;
1666
+ /**
1667
+ * 弓形
1668
+ */
1669
+ const PlotSchemePolygonArc = new PlotScheme({
1670
+ type: "PolygonArc",
1671
+ complete: (packable) => packable.positions.length >= 3,
1672
+ skeletons: [moved, control],
1673
+ initRender() {
1674
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1675
+ },
1676
+ render(context) {
1677
+ const entity = context.previous.entities[0];
1678
+ const points = context.packable.positions;
1679
+ if (points.length < 3) context.mouse && points.push(context.mouse.clone());
1680
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1681
+ if (coords.length < 3) {
1682
+ entity.polygon.hierarchy = void 0;
1683
+ return context.previous;
1684
+ }
1685
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arc)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1686
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1687
+ return { entities: [entity] };
2607
1688
  }
2608
- const positions = arc(coords).map((item) => (0, vesium.toCartesian3)(item));
2609
- const hierarchy = new cesium.PolygonHierarchy(positions);
2610
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2611
- return { entities: [entity] };
2612
- }
2613
- });
1689
+ });
2614
1690
 
2615
1691
  //#endregion
2616
1692
  //#region scheme/PolygonArrowAttackDirection.ts
2617
- const PlotSchemePolygonArrowAttackDirection = new PlotScheme({
2618
- type: "PolygonArrowAttackDirection",
2619
- allowManualComplete: (packable) => packable.positions.length >= 3,
2620
- skeletons: [
2621
- moved,
2622
- control,
2623
- intervalNonclosed
2624
- ],
2625
- initRender() {
2626
- return { entities: [new cesium.Entity({ polygon: {} })] };
2627
- },
2628
- render(context) {
2629
- const entity = context.previous.entities[0];
2630
- const points = context.packable.positions;
2631
- context.mouse && points.push(context.mouse.clone());
2632
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2633
- if (coords.length < 3) {
2634
- entity.polygon.hierarchy = void 0;
2635
- return context.previous;
1693
+ const PlotSchemePolygonArrowAttackDirection = new PlotScheme({
1694
+ type: "PolygonArrowAttackDirection",
1695
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1696
+ skeletons: [
1697
+ moved,
1698
+ control,
1699
+ intervalNonclosed
1700
+ ],
1701
+ initRender() {
1702
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1703
+ },
1704
+ render(context) {
1705
+ const entity = context.previous.entities[0];
1706
+ const points = context.packable.positions;
1707
+ context.mouse && points.push(context.mouse.clone());
1708
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1709
+ if (coords.length < 3) {
1710
+ entity.polygon.hierarchy = void 0;
1711
+ return context.previous;
1712
+ }
1713
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowAttackDirection)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1714
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1715
+ return { entities: [entity] };
2636
1716
  }
2637
- const positions = arrowAttackDirection(coords).map((item) => (0, vesium.toCartesian3)(item));
2638
- const hierarchy = new cesium.PolygonHierarchy(positions);
2639
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2640
- return { entities: [entity] };
2641
- }
2642
- });
1717
+ });
2643
1718
 
2644
1719
  //#endregion
2645
1720
  //#region scheme/PolygonArrowAttackDirectionTailed.ts
2646
- const PlotSchemePolygonArrowAttackDirectionTailed = new PlotScheme({
2647
- type: "PolygonArrowAttackDirectionTailed",
2648
- allowManualComplete: (packable) => packable.positions.length >= 3,
2649
- skeletons: [
2650
- moved,
2651
- control,
2652
- intervalNonclosed
2653
- ],
2654
- initRender() {
2655
- return { entities: [new cesium.Entity({ polygon: {} })] };
2656
- },
2657
- render(context) {
2658
- const entity = context.previous.entities[0];
2659
- const points = context.packable.positions;
2660
- context.mouse && points.push(context.mouse.clone());
2661
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2662
- if (coords.length < 3) {
2663
- entity.polygon.hierarchy = void 0;
2664
- return context.previous;
1721
+ const PlotSchemePolygonArrowAttackDirectionTailed = new PlotScheme({
1722
+ type: "PolygonArrowAttackDirectionTailed",
1723
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1724
+ skeletons: [
1725
+ moved,
1726
+ control,
1727
+ intervalNonclosed
1728
+ ],
1729
+ initRender() {
1730
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1731
+ },
1732
+ render(context) {
1733
+ const entity = context.previous.entities[0];
1734
+ const points = context.packable.positions;
1735
+ context.mouse && points.push(context.mouse.clone());
1736
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1737
+ if (coords.length < 3) {
1738
+ entity.polygon.hierarchy = void 0;
1739
+ return context.previous;
1740
+ }
1741
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowAttackDirectionTailed)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1742
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1743
+ return { entities: [entity] };
2665
1744
  }
2666
- const positions = arrowAttackDirectionTailed(coords).map((item) => (0, vesium.toCartesian3)(item));
2667
- const hierarchy = new cesium.PolygonHierarchy(positions);
2668
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2669
- return { entities: [entity] };
2670
- }
2671
- });
1745
+ });
2672
1746
 
2673
1747
  //#endregion
2674
1748
  //#region scheme/PolygonArrowClamped.ts
2675
- const PlotSchemePolygonArrowClamped = new PlotScheme({
2676
- type: "PolygonArrowClamped",
2677
- complete: (packable) => packable.positions.length >= 5,
2678
- skeletons: [moved, control],
2679
- initRender() {
2680
- return { entities: [new cesium.Entity({ polygon: {} })] };
2681
- },
2682
- render(context) {
2683
- const entity = context.previous.entities[0];
2684
- const points = context.packable.positions;
2685
- if (points.length < 5) {
2686
- const mouse = context.mouse;
2687
- mouse && points.push(mouse.clone());
1749
+ const PlotSchemePolygonArrowClamped = new PlotScheme({
1750
+ type: "PolygonArrowClamped",
1751
+ complete: (packable) => packable.positions.length >= 5,
1752
+ skeletons: [moved, control],
1753
+ initRender() {
1754
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1755
+ },
1756
+ render(context) {
1757
+ const entity = context.previous.entities[0];
1758
+ const points = context.packable.positions;
1759
+ if (points.length < 5) {
1760
+ const mouse = context.mouse;
1761
+ mouse && points.push(mouse.clone());
1762
+ }
1763
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1764
+ if (coords.length >= 3) {
1765
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowClamped)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1766
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1767
+ } else entity.polygon.hierarchy = void 0;
1768
+ return { entities: [entity] };
2688
1769
  }
2689
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2690
- if (coords.length >= 3) {
2691
- const positions = arrowClamped(coords);
2692
- const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
2693
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2694
- } else entity.polygon.hierarchy = void 0;
2695
- return { entities: [entity] };
2696
- }
2697
- });
1770
+ });
2698
1771
 
2699
1772
  //#endregion
2700
1773
  //#region scheme/PolygonArrowStraight.ts
2701
- const PlotSchemePolygonArrowStraight = new PlotScheme({
2702
- type: "PolygonArrowStraight",
2703
- complete: (packable) => packable.positions.length >= 2,
2704
- skeletons: [moved, control],
2705
- initRender() {
2706
- return { entities: [new cesium.Entity({ polygon: {} })] };
2707
- },
2708
- render(context) {
2709
- const entity = context.previous.entities[0];
2710
- const points = context.packable.positions;
2711
- if (points.length < 2) {
2712
- const mouse = context.mouse;
2713
- mouse && points.push(mouse.clone());
1774
+ const PlotSchemePolygonArrowStraight = new PlotScheme({
1775
+ type: "PolygonArrowStraight",
1776
+ complete: (packable) => packable.positions.length >= 2,
1777
+ skeletons: [moved, control],
1778
+ initRender() {
1779
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1780
+ },
1781
+ render(context) {
1782
+ const entity = context.previous.entities[0];
1783
+ const points = context.packable.positions;
1784
+ if (points.length < 2) {
1785
+ const mouse = context.mouse;
1786
+ mouse && points.push(mouse.clone());
1787
+ }
1788
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1789
+ if (coords.length >= 2) {
1790
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowStraight)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1791
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1792
+ } else entity.polygon.hierarchy = void 0;
1793
+ return { entities: [entity] };
2714
1794
  }
2715
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2716
- if (coords.length >= 2) {
2717
- const positions = arrowStraight(coords);
2718
- const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
2719
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2720
- } else entity.polygon.hierarchy = void 0;
2721
- return { entities: [entity] };
2722
- }
2723
- });
1795
+ });
2724
1796
 
2725
1797
  //#endregion
2726
1798
  //#region scheme/PolygonArrowStraightSharp.ts
2727
- const PlotSchemePolygonArrowStraightSharp = new PlotScheme({
2728
- type: "PolygonArrowStraightSharp",
2729
- complete: (packable) => packable.positions.length >= 2,
2730
- skeletons: [moved, control],
2731
- initRender() {
2732
- return { entities: [new cesium.Entity({ polygon: {} })] };
2733
- },
2734
- render(context) {
2735
- const entity = context.previous.entities[0];
2736
- const points = context.packable.positions;
2737
- if (points.length < 2) {
2738
- const mouse = context.mouse;
2739
- mouse && points.push(mouse.clone());
1799
+ const PlotSchemePolygonArrowStraightSharp = new PlotScheme({
1800
+ type: "PolygonArrowStraightSharp",
1801
+ complete: (packable) => packable.positions.length >= 2,
1802
+ skeletons: [moved, control],
1803
+ initRender() {
1804
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1805
+ },
1806
+ render(context) {
1807
+ const entity = context.previous.entities[0];
1808
+ const points = context.packable.positions;
1809
+ if (points.length < 2) {
1810
+ const mouse = context.mouse;
1811
+ mouse && points.push(mouse.clone());
1812
+ }
1813
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1814
+ if (coords.length >= 2) {
1815
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowStraightSharp)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1816
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1817
+ } else entity.polygon.hierarchy = void 0;
1818
+ return { entities: [entity] };
2740
1819
  }
2741
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2742
- if (coords.length >= 2) {
2743
- const positions = arrowStraightSharp(coords);
2744
- const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
2745
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2746
- } else entity.polygon.hierarchy = void 0;
2747
- return { entities: [entity] };
2748
- }
2749
- });
1820
+ });
2750
1821
 
2751
1822
  //#endregion
2752
1823
  //#region scheme/PolygonArrowUnitCombatOperation.ts
2753
- const PlotSchemePolygonArrowUnitCombatOperation = new PlotScheme({
2754
- type: "PolygonArrowUnitCombatOperation",
2755
- allowManualComplete: (packable) => packable.positions.length >= 2,
2756
- skeletons: [
2757
- moved,
2758
- control,
2759
- intervalNonclosed
2760
- ],
2761
- initRender() {
2762
- return { entities: [new cesium.Entity({ polygon: {} })] };
2763
- },
2764
- render(context) {
2765
- const entity = context.previous.entities[0];
2766
- const points = context.packable.positions;
2767
- context.mouse && points.push(context.mouse.clone());
2768
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2769
- if (coords.length < 2) {
2770
- entity.polygon.hierarchy = void 0;
2771
- return context.previous;
1824
+ const PlotSchemePolygonArrowUnitCombatOperation = new PlotScheme({
1825
+ type: "PolygonArrowUnitCombatOperation",
1826
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1827
+ skeletons: [
1828
+ moved,
1829
+ control,
1830
+ intervalNonclosed
1831
+ ],
1832
+ initRender() {
1833
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1834
+ },
1835
+ render(context) {
1836
+ const entity = context.previous.entities[0];
1837
+ const points = context.packable.positions;
1838
+ context.mouse && points.push(context.mouse.clone());
1839
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1840
+ if (coords.length < 2) {
1841
+ entity.polygon.hierarchy = void 0;
1842
+ return context.previous;
1843
+ }
1844
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowUnitCombatOperation)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1845
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1846
+ return { entities: [entity] };
2772
1847
  }
2773
- const positions = arrowUnitCombatOperation(coords).map((item) => (0, vesium.toCartesian3)(item));
2774
- const hierarchy = new cesium.PolygonHierarchy(positions);
2775
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2776
- return { entities: [entity] };
2777
- }
2778
- });
1848
+ });
2779
1849
 
2780
1850
  //#endregion
2781
1851
  //#region scheme/PolygonArrowUnitCombatOperationTailed.ts
2782
- const PlotSchemePolygonArrowUnitCombatOperationTailed = new PlotScheme({
2783
- type: "PolygonArrowUnitCombatOperationTailed",
2784
- allowManualComplete: (packable) => packable.positions.length >= 2,
2785
- skeletons: [
2786
- moved,
2787
- control,
2788
- interval
2789
- ],
2790
- initRender() {
2791
- return { entities: [new cesium.Entity({ polygon: {} })] };
2792
- },
2793
- render(context) {
2794
- const entity = context.previous.entities[0];
2795
- const points = context.packable.positions;
2796
- context.mouse && points.push(context.mouse.clone());
2797
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2798
- if (coords.length < 2) {
2799
- entity.polygon.hierarchy = void 0;
2800
- return context.previous;
1852
+ const PlotSchemePolygonArrowUnitCombatOperationTailed = new PlotScheme({
1853
+ type: "PolygonArrowUnitCombatOperationTailed",
1854
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1855
+ skeletons: [
1856
+ moved,
1857
+ control,
1858
+ interval
1859
+ ],
1860
+ initRender() {
1861
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1862
+ },
1863
+ render(context) {
1864
+ const entity = context.previous.entities[0];
1865
+ const points = context.packable.positions;
1866
+ context.mouse && points.push(context.mouse.clone());
1867
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1868
+ if (coords.length < 2) {
1869
+ entity.polygon.hierarchy = void 0;
1870
+ return context.previous;
1871
+ }
1872
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowUnitCombatOperationTailed)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1873
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1874
+ return { entities: [entity] };
2801
1875
  }
2802
- const positions = arrowUnitCombatOperationTailed(coords).map((item) => (0, vesium.toCartesian3)(item));
2803
- const hierarchy = new cesium.PolygonHierarchy(positions);
2804
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2805
- return { entities: [entity] };
2806
- }
2807
- });
1876
+ });
2808
1877
 
2809
1878
  //#endregion
2810
1879
  //#region scheme/PolygonAssemblingPlace.ts
2811
- const PlotSchemePolygonAssemblingPlace = new PlotScheme({
2812
- type: "PolygonAssemblingPlace",
2813
- complete: (packable) => packable.positions.length >= 3,
2814
- skeletons: [
2815
- moved,
2816
- control,
2817
- interval
2818
- ],
2819
- initRender() {
2820
- return { entities: [new cesium.Entity({ polygon: {} })] };
2821
- },
2822
- render(context) {
2823
- const entity = context.previous.entities[0];
2824
- const points = context.packable.positions;
2825
- context.mouse && points.push(context.mouse.clone());
2826
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2827
- if (coords.length < 2) {
2828
- entity.polygon.hierarchy = void 0;
2829
- return context.previous;
2830
- }
2831
- const positions = assemblingPlace(coords).map((item) => (0, vesium.toCartesian3)(item));
2832
- const hierarchy = new cesium.PolygonHierarchy(positions);
2833
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2834
- return { entities: [entity] };
2835
- }
2836
- });
2837
-
2838
- //#endregion
2839
- //#region scheme/PolygonFlagCurve.ts
2840
- const PlotSchemePolygonFlagCurve = new PlotScheme({
2841
- type: "PolygonFlagCurve",
2842
- complete: (packable) => packable.positions.length >= 2,
2843
- skeletons: [moved, control],
2844
- initRender() {
2845
- return { entities: [new cesium.Entity({ polygon: {} })] };
2846
- },
2847
- render(context) {
2848
- const entity = context.previous.entities[0];
2849
- const points = context.packable.positions;
2850
- context.mouse && points.push(context.mouse.clone());
2851
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2852
- if (coords.length < 2) {
2853
- entity.polygon.hierarchy = void 0;
2854
- return context.previous;
2855
- }
2856
- const positions = flagCurve(coords).map((item) => (0, vesium.toCartesian3)(item));
2857
- const hierarchy = new cesium.PolygonHierarchy(positions);
2858
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2859
- return { entities: [entity] };
2860
- }
2861
- });
2862
-
2863
- //#endregion
2864
- //#region scheme/PolygonFlagRect.ts
2865
- const PlotSchemePolygonFlagRect = new PlotScheme({
2866
- type: "PolygonFlagRect",
2867
- complete: (packable) => packable.positions.length >= 2,
2868
- skeletons: [moved, control],
2869
- initRender() {
2870
- return { entities: [new cesium.Entity({ polygon: {} })] };
2871
- },
2872
- render(context) {
2873
- const entity = context.previous.entities[0];
2874
- const points = context.packable.positions;
2875
- context.mouse && points.push(context.mouse.clone());
2876
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2877
- if (coords.length < 2) {
2878
- entity.polygon.hierarchy = void 0;
2879
- return context.previous;
2880
- }
2881
- const positions = flagRect(coords).map((item) => (0, vesium.toCartesian3)(item));
2882
- const hierarchy = new cesium.PolygonHierarchy(positions);
2883
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2884
- return { entities: [entity] };
2885
- }
2886
- });
2887
-
2888
- //#endregion
2889
- //#region scheme/PolygonFlagTriangle.ts
2890
- const PlotSchemePolygonFlagTriangle = new PlotScheme({
2891
- type: "PolygonFlagTriangle",
2892
- complete: (packable) => packable.positions.length >= 2,
2893
- skeletons: [moved, control],
2894
- initRender() {
2895
- return { entities: [new cesium.Entity({ polygon: {} })] };
2896
- },
2897
- render(context) {
2898
- const entity = context.previous.entities[0];
2899
- const points = context.packable.positions;
2900
- context.mouse && points.push(context.mouse.clone());
2901
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2902
- if (coords.length < 2) {
2903
- entity.polygon.hierarchy = void 0;
2904
- return context.previous;
1880
+ const PlotSchemePolygonAssemblingPlace = new PlotScheme({
1881
+ type: "PolygonAssemblingPlace",
1882
+ complete: (packable) => packable.positions.length >= 3,
1883
+ skeletons: [
1884
+ moved,
1885
+ control,
1886
+ interval
1887
+ ],
1888
+ initRender() {
1889
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1890
+ },
1891
+ render(context) {
1892
+ const entity = context.previous.entities[0];
1893
+ const points = context.packable.positions;
1894
+ context.mouse && points.push(context.mouse.clone());
1895
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1896
+ if (coords.length < 2) {
1897
+ entity.polygon.hierarchy = void 0;
1898
+ return context.previous;
1899
+ }
1900
+ if (coords.length === 2) {
1901
+ const c0 = (0, vesium.toCartographic)(coords[0]);
1902
+ const c1 = (0, vesium.toCartographic)(coords[1]);
1903
+ const latitude = c0.latitude;
1904
+ const height = c0.height;
1905
+ const longitude = c1.longitude - (c0.longitude - c1.longitude);
1906
+ coords.push((0, vesium.toCoord)(new cesium.Cartographic(longitude, latitude, height)));
1907
+ }
1908
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.assemblingPlace)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1909
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1910
+ return { entities: [entity] };
2905
1911
  }
2906
- const positions = flagTriangle(coords).map((item) => (0, vesium.toCartesian3)(item));
2907
- const hierarchy = new cesium.PolygonHierarchy(positions);
2908
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2909
- return { entities: [entity] };
2910
- }
2911
- });
1912
+ });
2912
1913
 
2913
1914
  //#endregion
2914
1915
  //#region scheme/PolygonSmooth.ts
2915
- const PlotSchemePolygonSmooth = new PlotScheme({
2916
- type: "PolygonSmooth",
2917
- allowManualComplete: (packable) => packable.positions.length >= 3,
2918
- skeletons: [
2919
- moved,
2920
- control,
2921
- intervalNonclosed
2922
- ],
2923
- initRender() {
2924
- return { entities: [new cesium.Entity({ polygon: {} })] };
2925
- },
2926
- render(context) {
2927
- const entity = context.previous.entities[0];
2928
- const positions = context.packable.positions;
2929
- const mousePosition = context.mouse;
2930
- mousePosition && positions.push(mousePosition.clone());
2931
- if (positions.length <= 2) {
2932
- entity.polygon.hierarchy = void 0;
2933
- return context.previous;
1916
+ /**
1917
+ * polygon-smooth 标绘配置 平滑闭合面
1918
+ */
1919
+ const PlotSchemePolygonSmooth = new PlotScheme({
1920
+ type: "PolygonSmooth",
1921
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1922
+ skeletons: [
1923
+ moved,
1924
+ control,
1925
+ intervalNonclosed
1926
+ ],
1927
+ initRender() {
1928
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1929
+ },
1930
+ render(context) {
1931
+ const entity = context.previous.entities[0];
1932
+ const positions = context.packable.positions;
1933
+ const mousePosition = context.mouse;
1934
+ mousePosition && positions.push(mousePosition.clone());
1935
+ if (positions.length <= 2) {
1936
+ entity.polygon.hierarchy = void 0;
1937
+ return context.previous;
1938
+ }
1939
+ const wgs84s = positions.map((e) => (0, vesium.toCoord)(e));
1940
+ wgs84s.push(wgs84s[0]);
1941
+ const { features } = __turf_turf.polygonSmooth(__turf_turf.polygon([wgs84s]), { iterations: 3 });
1942
+ const hierarchy = new cesium.PolygonHierarchy(features[0].geometry.coordinates[0].map((item) => (0, vesium.toCartesian3)(item)).filter((e) => !!e));
1943
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1944
+ return { entities: [entity] };
2934
1945
  }
2935
- const wgs84s = positions.map((e) => (0, vesium.toCoord)(e));
2936
- wgs84s.push(wgs84s[0]);
2937
- const { features } = __turf_turf.polygonSmooth(__turf_turf.polygon([wgs84s]), { iterations: 3 });
2938
- const cartesians = features[0].geometry.coordinates[0].map((item) => (0, vesium.toCartesian3)(item)).filter((e) => !!e);
2939
- const hierarchy = new cesium.PolygonHierarchy(cartesians);
2940
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2941
- return { entities: [entity] };
2942
- }
2943
- });
1946
+ });
2944
1947
 
2945
1948
  //#endregion
2946
1949
  //#region scheme/Polyline.ts
2947
- const PlotSchemePolyline = new PlotScheme({
2948
- type: "Polyline",
2949
- allowManualComplete: (packable) => packable.positions.length > 1,
2950
- skeletons: [
2951
- moved,
2952
- control,
2953
- intervalNonclosed
2954
- ],
2955
- initRender() {
2956
- return { entities: [new cesium.Entity({ polyline: {
2957
- material: cesium.Color.RED,
2958
- width: 2
2959
- } })] };
2960
- },
2961
- render(context) {
2962
- const entity = context.previous.entities[0];
2963
- const positions = [...context.packable.positions];
2964
- const mouse = context.mouse;
2965
- mouse && positions.push(mouse.clone());
2966
- const cache = positions.length >= 2 ? positions : [];
2967
- entity.polyline.positions = new cesium.CallbackProperty(() => cache, false);
2968
- return { entities: [entity] };
2969
- }
2970
- });
1950
+ /**
1951
+ * polyline
1952
+ */
1953
+ const PlotSchemePolyline = new PlotScheme({
1954
+ type: "Polyline",
1955
+ allowManualComplete: (packable) => packable.positions.length > 1,
1956
+ skeletons: [
1957
+ moved,
1958
+ control,
1959
+ intervalNonclosed
1960
+ ],
1961
+ initRender() {
1962
+ return { entities: [new cesium.Entity({ polyline: {
1963
+ material: cesium.Color.RED,
1964
+ width: 2
1965
+ } })] };
1966
+ },
1967
+ render(context) {
1968
+ const entity = context.previous.entities[0];
1969
+ const positions = [...context.packable.positions];
1970
+ const mouse = context.mouse;
1971
+ mouse && positions.push(mouse.clone());
1972
+ const cache = positions.length >= 2 ? positions : [];
1973
+ entity.polyline.positions = new cesium.CallbackProperty(() => cache, false);
1974
+ return { entities: [entity] };
1975
+ }
1976
+ });
2971
1977
 
2972
1978
  //#endregion
2973
1979
  //#region scheme/PolylineCurve.ts
2974
- const PlotSchemePolylineCurve = new PlotScheme({
2975
- type: "PolylineCurve",
2976
- allowManualComplete: (packable) => packable.positions.length > 1,
2977
- skeletons: [
2978
- moved,
2979
- control,
2980
- intervalNonclosed
2981
- ],
2982
- initRender() {
2983
- return { entities: [new cesium.Entity({ polyline: {
2984
- material: cesium.Color.RED,
2985
- width: 2
2986
- } })] };
2987
- },
2988
- render(context) {
2989
- const entity = context.previous.entities[0];
2990
- const positions = [...context.packable.positions];
2991
- const mouse = context.mouse;
2992
- mouse && positions.push(mouse.clone());
2993
- if (positions.length < 2) {
2994
- entity.polyline.positions = void 0;
2995
- return context.previous;
1980
+ /**
1981
+ * polyline-Curve
1982
+ */
1983
+ const PlotSchemePolylineCurve = new PlotScheme({
1984
+ type: "PolylineCurve",
1985
+ allowManualComplete: (packable) => packable.positions.length > 1,
1986
+ skeletons: [
1987
+ moved,
1988
+ control,
1989
+ intervalNonclosed
1990
+ ],
1991
+ initRender() {
1992
+ return { entities: [new cesium.Entity({ polyline: {
1993
+ material: cesium.Color.RED,
1994
+ width: 2
1995
+ } })] };
1996
+ },
1997
+ render(context) {
1998
+ const entity = context.previous.entities[0];
1999
+ const positions = [...context.packable.positions];
2000
+ const mouse = context.mouse;
2001
+ mouse && positions.push(mouse.clone());
2002
+ if (positions.length < 2) {
2003
+ entity.polyline.positions = void 0;
2004
+ return context.previous;
2005
+ }
2006
+ const coords = positions.map((position) => (0, vesium.toCoord)(position));
2007
+ const { geometry: { coordinates } } = __turf_turf.bezierSpline(__turf_turf.lineString(coords));
2008
+ entity.polyline.positions = new cesium.CallbackProperty(() => coordinates.map(vesium.toCartesian3), false);
2009
+ return { entities: [entity] };
2996
2010
  }
2997
- const coords = positions.map((position) => (0, vesium.toCoord)(position));
2998
- const { geometry: { coordinates } } = __turf_turf.bezierSpline(__turf_turf.lineString(coords));
2999
- entity.polyline.positions = new cesium.CallbackProperty(() => coordinates.map(vesium.toCartesian3), false);
3000
- return { entities: [entity] };
3001
- }
3002
- });
2011
+ });
3003
2012
 
3004
2013
  //#endregion
3005
2014
  //#region scheme/Rectangle.ts
3006
- const PlotSchemeRectangle = new PlotScheme({
3007
- type: "Rectangle",
3008
- complete: (packable) => packable.positions.length >= 2,
3009
- skeletons: [moved, control],
3010
- initRender() {
3011
- return { entities: [new cesium.Entity({ rectangle: {} })] };
3012
- },
3013
- render(context) {
3014
- const entity = context.previous.entities[0];
3015
- const positions = [...context.packable.positions];
3016
- const mouse = context.mouse;
3017
- mouse && positions.push(mouse.clone());
3018
- if (positions.length < 2) {
3019
- entity.rectangle.coordinates = void 0;
3020
- return context.previous;
2015
+ /**
2016
+ * rectangle
2017
+ */
2018
+ const PlotSchemeRectangle = new PlotScheme({
2019
+ type: "Rectangle",
2020
+ complete: (packable) => packable.positions.length >= 2,
2021
+ skeletons: [moved, control],
2022
+ initRender() {
2023
+ return { entities: [new cesium.Entity({ rectangle: {} })] };
2024
+ },
2025
+ render(context) {
2026
+ const entity = context.previous.entities[0];
2027
+ const positions = [...context.packable.positions];
2028
+ const mouse = context.mouse;
2029
+ mouse && positions.push(mouse.clone());
2030
+ if (positions.length < 2) {
2031
+ entity.rectangle.coordinates = void 0;
2032
+ return context.previous;
2033
+ }
2034
+ const coordinates = cesium.Rectangle.fromCartesianArray(positions ?? []);
2035
+ entity.rectangle.coordinates = new cesium.CallbackProperty(() => coordinates, false);
2036
+ return { entities: [entity] };
3021
2037
  }
3022
- const coordinates = cesium.Rectangle.fromCartesianArray(positions ?? []);
3023
- entity.rectangle.coordinates = new cesium.CallbackProperty(() => coordinates, false);
3024
- return { entities: [entity] };
3025
- }
3026
- });
2038
+ });
3027
2039
 
3028
2040
  //#endregion
3029
2041
  exports.PlotAction = PlotAction;
@@ -3045,9 +2057,6 @@ exports.PlotSchemePolygonArrowStraightSharp = PlotSchemePolygonArrowStraightShar
3045
2057
  exports.PlotSchemePolygonArrowUnitCombatOperation = PlotSchemePolygonArrowUnitCombatOperation;
3046
2058
  exports.PlotSchemePolygonArrowUnitCombatOperationTailed = PlotSchemePolygonArrowUnitCombatOperationTailed;
3047
2059
  exports.PlotSchemePolygonAssemblingPlace = PlotSchemePolygonAssemblingPlace;
3048
- exports.PlotSchemePolygonFlagCurve = PlotSchemePolygonFlagCurve;
3049
- exports.PlotSchemePolygonFlagRect = PlotSchemePolygonFlagRect;
3050
- exports.PlotSchemePolygonFlagTriangle = PlotSchemePolygonFlagTriangle;
3051
2060
  exports.PlotSchemePolygonSmooth = PlotSchemePolygonSmooth;
3052
2061
  exports.PlotSchemePolyline = PlotSchemePolyline;
3053
2062
  exports.PlotSchemePolylineCurve = PlotSchemePolylineCurve;
@@ -3062,5 +2071,5 @@ exports.moved = moved;
3062
2071
  exports.schemeMeasureArea = schemeMeasureArea;
3063
2072
  exports.schemeMeasureDistance = schemeMeasureDistance;
3064
2073
  exports.usePlot = usePlot;
3065
- })(this.Vesium = this.Vesium || {}, Cesium, Vesium, VueUse, Vue, turf);
2074
+ })(this.Vesium = this.Vesium || {}, Cesium, Vesium, VueUse, Vue, Vesium, turf);
3066
2075
  //# sourceMappingURL=index.iife.js.map