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

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