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