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

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