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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -21,10 +21,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
- const cesium = __toESM(require("cesium"));
25
- const vesium = __toESM(require("vesium"));
26
- const __vueuse_core = __toESM(require("@vueuse/core"));
27
- const vue = __toESM(require("vue"));
24
+ let cesium = require("cesium");
25
+ cesium = __toESM(cesium);
26
+ let vesium = require("vesium");
27
+ vesium = __toESM(vesium);
28
+ let __vueuse_core = require("@vueuse/core");
29
+ __vueuse_core = __toESM(__vueuse_core);
30
+ let vue = require("vue");
31
+ vue = __toESM(vue);
32
+ let __vesium_geometry = require("@vesium/geometry");
33
+ __vesium_geometry = __toESM(__vesium_geometry);
34
+ let __turf_turf = require("@turf/turf");
35
+ __turf_turf = __toESM(__turf_turf);
28
36
 
29
37
  //#region usePlot/PlotScheme.ts
30
38
  var PlotScheme = class PlotScheme {
@@ -34,9 +42,7 @@ var PlotScheme = class PlotScheme {
34
42
  this.allowManualComplete = options.allowManualComplete;
35
43
  this.definingCursor = options.definingCursor ?? "crosshair";
36
44
  this.skeletons = options.skeletons?.map((item) => item()) ?? [];
37
- this.initEntites = options.initEntites;
38
- this.initPrimitives = options.initPrimitives;
39
- this.initGroundPrimitives = options.initGroundPrimitives;
45
+ this.initRender = options.initRender;
40
46
  this.render = options.render;
41
47
  }
42
48
  /**
@@ -63,17 +69,9 @@ var PlotScheme = class PlotScheme {
63
69
  */
64
70
  skeletons;
65
71
  /**
66
- * 初始化时创建`Entity`的函数,创建后的`Entity`会作为配置项传入`render`中
67
- */
68
- initEntites;
69
- /**
70
- * 初始化时创建`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
71
- */
72
- initPrimitives;
73
- /**
74
72
  * 初始化时创建贴地`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
75
73
  */
76
- initGroundPrimitives;
74
+ initRender;
77
75
  /**
78
76
  * 当标绘数据变化时,会触发`render`回调,返回的数据会被添加到cesium中
79
77
  */
@@ -213,16 +211,13 @@ var SampledPlotProperty = class SampledPlotProperty {
213
211
  const end = this._times[this._times.length - 1];
214
212
  if (cesium.JulianDate.lessThan(time, start) || cesium.JulianDate.greaterThan(time, end)) switch (this.strategy) {
215
213
  case SampledPlotStrategy.STRICT: return;
216
- case SampledPlotStrategy.NEAR: {
214
+ case SampledPlotStrategy.NEAR:
217
215
  time = cesium.JulianDate.lessThan(time, this._times[0]) ? this._times[0].clone() : this._times[this._times.length - 1].clone();
218
216
  break;
219
- }
220
217
  case SampledPlotStrategy.CYCLE: {
221
218
  const startMS = cesium.JulianDate.toDate(this._times[0]).getTime();
222
- const endMS = cesium.JulianDate.toDate(this._times[this._times.length - 1]).getTime();
223
- const duration = endMS - startMS;
224
- const timeMS = cesium.JulianDate.toDate(time).getTime();
225
- const diff = (timeMS - startMS) % duration;
219
+ const duration = cesium.JulianDate.toDate(this._times[this._times.length - 1]).getTime() - startMS;
220
+ const diff = (cesium.JulianDate.toDate(time).getTime() - startMS) % duration;
226
221
  const dete = new Date(startMS + diff);
227
222
  time = cesium.JulianDate.fromDate(dete);
228
223
  break;
@@ -232,11 +227,10 @@ var SampledPlotProperty = class SampledPlotProperty {
232
227
  const nextIndex = Math.min(prevIndex, this._times.length - 1);
233
228
  const prevMs = cesium.JulianDate.toDate(this._times[prevIndex]).getTime();
234
229
  const nextMs = cesium.JulianDate.toDate(this._times[nextIndex]).getTime();
235
- const ms = cesium.JulianDate.toDate(time).getTime();
236
230
  return {
237
231
  prevIndex,
238
232
  nextIndex,
239
- proportion: (ms - prevMs) / (nextMs - prevMs) || 0
233
+ proportion: (cesium.JulianDate.toDate(time).getTime() - prevMs) / (nextMs - prevMs) || 0
240
234
  };
241
235
  }
242
236
  /**
@@ -248,10 +242,13 @@ var SampledPlotProperty = class SampledPlotProperty {
248
242
  * @template D 数据类型。
249
243
  */
250
244
  getValue(time, result) {
251
- result ??= { time };
245
+ result ??= {
246
+ time,
247
+ positions: []
248
+ };
252
249
  Object.assign(result, {
253
250
  time: time?.clone(),
254
- positions: void 0,
251
+ positions: [],
255
252
  derivative: void 0
256
253
  });
257
254
  if (!time) {
@@ -325,8 +322,7 @@ var SampledPlotProperty = class SampledPlotProperty {
325
322
  if (index !== -1) {
326
323
  this._sampleds.splice(index, 1);
327
324
  this._derivatives.splice(index, 1);
328
- const removed = this._times.splice(index, 1);
329
- if (removed.length) {
325
+ if (this._times.splice(index, 1).length) {
330
326
  this._definitionChanged.raiseEvent(this);
331
327
  return true;
332
328
  }
@@ -367,9 +363,10 @@ var PlotFeature = class {
367
363
  this._disabled = disabled;
368
364
  this._sampled = sampled instanceof SampledPlotProperty ? sampled : new SampledPlotProperty(sampled);
369
365
  this._sampled.definitionChanged.addEventListener((property) => this._definitionChanged.raiseEvent(this, "sampled", property, property), this);
370
- this._entities = [...this._scheme.initEntites?.() ?? []];
371
- this._primitives = [...this._scheme.initPrimitives?.() ?? []];
372
- this._groundPrimitives = [...this._scheme.initGroundPrimitives?.() ?? []];
366
+ const init = this._scheme.initRender?.() ?? {};
367
+ this._entities = [...init.entities ?? []];
368
+ this._primitives = [...init.primitives ?? []];
369
+ this._groundPrimitives = [...init.groundPrimitives ?? []];
373
370
  this._skeletons = [];
374
371
  }
375
372
  /**
@@ -555,19 +552,27 @@ function useRender(plots, current, getCurrentTime) {
555
552
  }
556
553
  });
557
554
  const update = async (plot) => {
558
- const reslut = await plot.scheme.render?.({
559
- packable: plot.sampled.getValue(getCurrentTime()),
560
- mouse: plot.defining ? mouseCartesian.value : void 0,
555
+ await (0, vue.nextTick)();
556
+ const packable = plot.sampled.getValue(getCurrentTime());
557
+ const mouse = plot.defining ? mouseCartesian.value : void 0;
558
+ const result = await plot.scheme.render?.({
559
+ packable,
560
+ mouse,
561
561
  defining: plot.defining,
562
562
  previous: {
563
563
  entities: plot.entities,
564
564
  primitives: plot.primitives,
565
565
  groundPrimitives: plot.groundPrimitives
566
+ },
567
+ getPositions() {
568
+ const points = packable.positions;
569
+ mouse && points.push(mouse);
570
+ return points;
566
571
  }
567
572
  });
568
- plot.entities = reslut?.entities ?? [];
569
- plot.primitives = reslut?.primitives ?? [];
570
- plot.groundPrimitives = reslut?.groundPrimitives ?? [];
573
+ plot.entities = result?.entities ?? [];
574
+ plot.primitives = result?.primitives ?? [];
575
+ plot.groundPrimitives = result?.groundPrimitives ?? [];
571
576
  };
572
577
  (0, vue.watch)(current, (plot, previous) => {
573
578
  previous && update(previous);
@@ -610,8 +615,7 @@ function useSampled(current, getCurrentTime) {
610
615
  packable.value.positions ??= [];
611
616
  packable.value.positions.push(position);
612
617
  sampled.setSample(packable.value);
613
- const completed = scheme.complete?.(packable.value);
614
- completed && PlotFeature.setDefining(current.value, false);
618
+ scheme.complete?.(packable.value) && PlotFeature.setDefining(current.value, false);
615
619
  });
616
620
  (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, async (ctx) => {
617
621
  if (!current.value || !packable.value) return;
@@ -620,10 +624,8 @@ function useSampled(current, getCurrentTime) {
620
624
  doubleClicking.value = false;
621
625
  const { scheme, defining } = current.value;
622
626
  if (!defining) return;
623
- const position = (0, vesium.canvasCoordToCartesian)(ctx.position, viewer.value.scene);
624
- if (!position) return;
625
- const completed = scheme.allowManualComplete?.(packable.value);
626
- completed && PlotFeature.setDefining(current.value, false);
627
+ if (!(0, vesium.canvasCoordToCartesian)(ctx.position, viewer.value.scene)) return;
628
+ scheme.allowManualComplete?.(packable.value) && PlotFeature.setDefining(current.value, false);
627
629
  });
628
630
  (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.RIGHT_CLICK, async () => {
629
631
  if (!current.value || !packable.value) return;
@@ -673,13 +675,11 @@ function useSkeleton(plots, current, getCurrentTime) {
673
675
  const packable = plot.sampled.getValue(getCurrentTime());
674
676
  const defining = plot.defining;
675
677
  const active = current.value === plot;
676
- const skeletons = plot.scheme.skeletons;
677
- skeletons.forEach((skeleton) => {
678
- const disabled = (0, vesium.isFunction)(skeleton.disabled) ? skeleton.disabled({
678
+ plot.scheme.skeletons.forEach((skeleton) => {
679
+ if ((0, vesium.isFunction)(skeleton.disabled) ? skeleton.disabled({
679
680
  active,
680
681
  defining
681
- }) : skeleton.disabled;
682
- if (disabled) return;
682
+ }) : skeleton.disabled) return;
683
683
  const positions = skeleton.format?.(packable) ?? packable?.positions ?? [];
684
684
  positions.forEach((position, index) => {
685
685
  let entity = oldEntities.find((item) => item.index === index && item.skeleton === skeleton);
@@ -706,9 +706,9 @@ function useSkeleton(plots, current, getCurrentTime) {
706
706
  }
707
707
  plot.skeletons = entities;
708
708
  };
709
- const { addGraphicEvent } = (0, vesium.useGraphicEvent)();
709
+ const graphicEvent = (0, vesium.useGraphicEvent)();
710
710
  (0, vue.watchEffect)((onCleanup) => {
711
- const remove = addGraphicEvent("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
711
+ onCleanup(graphicEvent.add("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
712
712
  if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
713
713
  const entity = pick.id;
714
714
  const plot = entity.plot;
@@ -741,8 +741,7 @@ function useSkeleton(plots, current, getCurrentTime) {
741
741
  return (0, vesium.isFunction)(skeleton?.dragCursor) ? skeleton.dragCursor(pick) : (0, vue.toValue)(skeleton?.dragCursor);
742
742
  }
743
743
  }
744
- });
745
- onCleanup(remove);
744
+ }));
746
745
  });
747
746
  (0, __vueuse_core.onKeyStroke)((keyEvent) => {
748
747
  if (activeEntity.value) {
@@ -761,16 +760,13 @@ function useSkeleton(plots, current, getCurrentTime) {
761
760
  }
762
761
  });
763
762
  (0, vue.watchEffect)((onCleanup) => {
764
- const remove = addGraphicEvent("global", "HOVER", ({ hovering, pick }) => {
765
- if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
766
- const entity = pick.id;
767
- hoverEntity.value = entity;
768
- } else hoverEntity.value = void 0;
769
- });
770
- onCleanup(remove);
763
+ onCleanup(graphicEvent.add("global", "HOVER", ({ hovering, pick }) => {
764
+ if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) hoverEntity.value = pick.id;
765
+ else hoverEntity.value = void 0;
766
+ }));
771
767
  });
772
768
  (0, vue.watchEffect)((onCleanup) => {
773
- const remove = addGraphicEvent("global", "LEFT_CLICK", ({ event, pick }) => {
769
+ onCleanup(graphicEvent.add("global", "LEFT_CLICK", ({ event, pick }) => {
774
770
  if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
775
771
  const entity = pick.id;
776
772
  activeEntity.value = entity;
@@ -788,8 +784,7 @@ function useSkeleton(plots, current, getCurrentTime) {
788
784
  event
789
785
  });
790
786
  } else activeEntity.value = void 0;
791
- });
792
- onCleanup(remove);
787
+ }));
793
788
  });
794
789
  (0, __vueuse_core.watchArray)(plots, (value, oldValue, added, removed = []) => {
795
790
  added.forEach((plot) => update(plot));
@@ -854,8 +849,7 @@ function usePlot(options) {
854
849
  if (previous) {
855
850
  if (previous.defining) {
856
851
  const packable$1 = previous.sampled.getValue(getCurrentTime());
857
- const completed = previous.scheme.allowManualComplete?.(packable$1);
858
- if (completed) {
852
+ if (previous.scheme.allowManualComplete?.(packable$1)) {
859
853
  PlotFeature.setDefining(previous, false);
860
854
  operateResolve?.(previous);
861
855
  } else collection.delete(previous);
@@ -939,10 +933,9 @@ function control() {
939
933
  const newHeading = (viewer.camera.heading + headingAdjust) % (2 * Math.PI);
940
934
  const positions = [...packable.positions ?? []];
941
935
  const cartographic = (0, vesium.toCartographic)(positions[index]);
942
- const r = height / 1e5;
943
- const distance = r * Math.PI / 180 / 1e3;
944
- cartographic.latitude += distance * Math.cos(newHeading);
945
- cartographic.longitude += distance * Math.sin(newHeading);
936
+ const distance$1 = height / 1e5 * Math.PI / 180 / 1e3;
937
+ cartographic.latitude += distance$1 * Math.cos(newHeading);
938
+ cartographic.longitude += distance$1 * Math.sin(newHeading);
946
939
  positions[index] = (0, vesium.toCartesian3)(cartographic);
947
940
  sampled.setSample({
948
941
  time: packable.time,
@@ -951,16 +944,15 @@ function control() {
951
944
  });
952
945
  },
953
946
  render: ({ position, action }) => {
954
- const colors = {
955
- [PlotAction.IDLE]: cesium.Color.BLUE.withAlpha(.4),
956
- [PlotAction.HOVER]: cesium.Color.BLUE.withAlpha(.6),
957
- [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
958
- };
959
947
  return {
960
948
  position,
961
949
  point: {
962
950
  pixelSize: 8,
963
- color: colors[action],
951
+ color: {
952
+ [PlotAction.IDLE]: cesium.Color.BLUE.withAlpha(.4),
953
+ [PlotAction.HOVER]: cesium.Color.BLUE.withAlpha(.6),
954
+ [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
955
+ }[action],
964
956
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
965
957
  outlineWidth: 1,
966
958
  outlineColor: cesium.Color.WHITE.withAlpha(.4)
@@ -1007,16 +999,15 @@ function interval() {
1007
999
  },
1008
1000
  render: ({ position, action, active }) => {
1009
1001
  if (!active) return;
1010
- const colors = {
1011
- [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1012
- [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1013
- [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1014
- };
1015
1002
  return {
1016
1003
  position,
1017
1004
  point: {
1018
1005
  pixelSize: 6,
1019
- color: colors[action],
1006
+ color: {
1007
+ [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1008
+ [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1009
+ [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1010
+ }[action],
1020
1011
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
1021
1012
  outlineWidth: 1,
1022
1013
  outlineColor: cesium.Color.WHITE.withAlpha(.4)
@@ -1061,16 +1052,15 @@ function intervalNonclosed() {
1061
1052
  });
1062
1053
  },
1063
1054
  render: ({ position, action }) => {
1064
- const colors = {
1065
- [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1066
- [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1067
- [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1068
- };
1069
1055
  return {
1070
1056
  position,
1071
1057
  point: {
1072
1058
  pixelSize: 6,
1073
- color: colors[action],
1059
+ color: {
1060
+ [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1061
+ [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1062
+ [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1063
+ }[action],
1074
1064
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
1075
1065
  outlineWidth: 1,
1076
1066
  outlineColor: cesium.Color.WHITE.withAlpha(.4)
@@ -1095,10 +1085,7 @@ function moved() {
1095
1085
  const positions = packable.positions ?? [];
1096
1086
  if (positions.length === 0) return [];
1097
1087
  else if (positions.length === 1) return [positions[0]];
1098
- else {
1099
- const center = cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions));
1100
- return [(0, vesium.toCartesian3)(center)];
1101
- }
1088
+ else return [(0, vesium.toCartesian3)(cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions)))];
1102
1089
  },
1103
1090
  onDrag({ viewer, sampled, packable, event, lockCamera, dragging }) {
1104
1091
  dragging && lockCamera();
@@ -1114,18 +1101,17 @@ function moved() {
1114
1101
  });
1115
1102
  },
1116
1103
  render: ({ position, action }) => {
1117
- const colors = {
1118
- [PlotAction.IDLE]: cesium.Color.WHITE,
1119
- [PlotAction.HOVER]: cesium.Color.WHITE,
1120
- [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
1121
- };
1122
1104
  return {
1123
1105
  position,
1124
1106
  billboard: {
1125
1107
  image: svg,
1126
1108
  width: 20,
1127
1109
  height: 20,
1128
- color: colors[action],
1110
+ color: {
1111
+ [PlotAction.IDLE]: cesium.Color.WHITE,
1112
+ [PlotAction.HOVER]: cesium.Color.WHITE,
1113
+ [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
1114
+ }[action],
1129
1115
  pixelOffset: new cesium.Cartesian3(0, -20),
1130
1116
  horizontalOrigin: cesium.HorizontalOrigin.CENTER,
1131
1117
  verticalOrigin: cesium.VerticalOrigin.BOTTOM,
@@ -1195,17 +1181,17 @@ async function clampToHeightMostDetailedByTilesetOrTerrain(options) {
1195
1181
  else resolve([]);
1196
1182
  });
1197
1183
  const [tilesetPositions, terrainPositions] = await Promise.all([tilesetPromise, terrainPromise]);
1198
- const resluts = [];
1184
+ const results = [];
1199
1185
  positions.forEach((item, index) => {
1200
1186
  const position = tilesetPositions[index] || terrainPositions[index] ? cesium.Ellipsoid.WGS84.cartographicToCartesian(terrainPositions[index]) : item.clone();
1201
- resluts.push(position);
1187
+ results.push(position);
1202
1188
  });
1203
- return resluts;
1189
+ return results;
1204
1190
  }
1205
1191
 
1206
1192
  //#endregion
1207
1193
  //#region measure/utils/triangleGrid.ts
1208
- function defaultOptions$1(original) {
1194
+ function defaultOptions$2(original) {
1209
1195
  const clampToGround = original?.clampToGround ?? false;
1210
1196
  const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1211
1197
  const density = Math.floor(original?.density ?? 10);
@@ -1224,13 +1210,12 @@ function defaultOptions$1(original) {
1224
1210
  */
1225
1211
  async function triangleGrid(positions, options) {
1226
1212
  if (positions.length < 3) throw new Error("positions must >= 3");
1227
- const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1213
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$2(options);
1228
1214
  if (density <= 0) throw new Error("options.density must > 0");
1229
1215
  const bbox = cesium.Rectangle.fromCartesianArray(positions);
1230
1216
  const vertical = bbox.north - bbox.south;
1231
1217
  const horizontal = bbox.east - bbox.west;
1232
- const max = Math.max(horizontal, vertical);
1233
- const granularity = max / density;
1218
+ const granularity = Math.max(horizontal, vertical) / density;
1234
1219
  const polygonGeometry = cesium.PolygonGeometry.fromPositions({
1235
1220
  positions,
1236
1221
  vertexFormat: cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
@@ -1249,13 +1234,12 @@ async function triangleGrid(positions, options) {
1249
1234
  }
1250
1235
  if (clampToGround) {
1251
1236
  if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1252
- const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
1237
+ cartesian3List = await clampToHeightMostDetailedByTilesetOrTerrain({
1253
1238
  scene,
1254
1239
  terrainProvider,
1255
1240
  positions: cartesian3List,
1256
1241
  classificationType
1257
1242
  });
1258
- cartesian3List = detaileds;
1259
1243
  }
1260
1244
  const grid = [];
1261
1245
  while (cartesian3List?.length) {
@@ -1283,7 +1267,7 @@ function triangleArea(p0, p1, p2) {
1283
1267
  const cross = cesium.Cartesian3.cross(v0, v1, v0);
1284
1268
  return cesium.Cartesian3.magnitude(cross) * .5;
1285
1269
  }
1286
- function defaultOptions(original) {
1270
+ function defaultOptions$1(original) {
1287
1271
  const clampToGround = original?.clampToGround ?? false;
1288
1272
  const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1289
1273
  const density = Math.floor(original?.density ?? 10);
@@ -1301,40 +1285,121 @@ function defaultOptions(original) {
1301
1285
  */
1302
1286
  async function area(positions, options) {
1303
1287
  if (positions.length < 2) throw new Error("positions.length must >= 2");
1304
- const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions(options);
1288
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1305
1289
  if (density <= 0) throw new Error("options.density must > 0");
1306
- if (!clampToGround) {
1307
- const triangles$1 = tesselate(positions);
1308
- return triangles$1.reduce((count, current) => count += triangleArea(...current), 0);
1309
- }
1310
- const triangles = await triangleGrid(positions, {
1290
+ if (!clampToGround) return tesselate(positions).reduce((count, current) => count += triangleArea(...current), 0);
1291
+ return (await triangleGrid(positions, {
1311
1292
  density,
1312
1293
  scene,
1313
1294
  clampToGround,
1314
1295
  classificationType,
1315
1296
  terrainProvider
1297
+ })).reduce((count, current) => count += triangleArea(...current), 0);
1298
+ }
1299
+
1300
+ //#endregion
1301
+ //#region measure/utils/lerpArray.ts
1302
+ /**
1303
+ * 在起点和终点间进行插值, 返回的数组包括起点和终点,数组长度为 count+1
1304
+ */
1305
+ async function lerpArray(options) {
1306
+ const { start, end, count, scene, clampToGround, classificationType, terrainProvider } = options;
1307
+ const result = [];
1308
+ for (let i = 0; i < count; i++) {
1309
+ const position = cesium.Cartesian3.lerp(start, end, 1 / count, new cesium.Cartesian3());
1310
+ result.push(position);
1311
+ }
1312
+ result.push(end.clone());
1313
+ if (!clampToGround) return result;
1314
+ if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1315
+ return await clampToHeightMostDetailedByTilesetOrTerrain({
1316
+ scene,
1317
+ terrainProvider,
1318
+ positions: result,
1319
+ classificationType
1320
+ });
1321
+ }
1322
+
1323
+ //#endregion
1324
+ //#region measure/utils/distance.ts
1325
+ function defaultOptions(original) {
1326
+ const clampToGround = original?.clampToGround ?? false;
1327
+ const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
1328
+ const density = Math.floor(original?.density ?? 50);
1329
+ return {
1330
+ scene: original?.scene,
1331
+ clampToGround,
1332
+ classificationType,
1333
+ terrainProvider: original?.terrainProvider,
1334
+ density
1335
+ };
1336
+ }
1337
+ /**
1338
+ * 计算多点位之间的距离
1339
+ * @param positions
1340
+ */
1341
+ async function distance(positions, options) {
1342
+ if (positions.length < 2) throw new Error("positions.length must >= 2");
1343
+ const _options = defaultOptions(options);
1344
+ const stages = [];
1345
+ let count = 0;
1346
+ positions.forEach((position, index) => {
1347
+ if (index !== positions.length - 1) {
1348
+ const next = positions[index + 1];
1349
+ const distance$1 = cesium.Cartesian3.distance(position, next);
1350
+ stages.push(distance$1);
1351
+ count += distance$1;
1352
+ }
1353
+ });
1354
+ if (!_options.clampToGround) return {
1355
+ stages,
1356
+ count
1357
+ };
1358
+ const density = _options.density;
1359
+ if (density <= 0) throw new Error("options.density must > 0");
1360
+ const densities = stages.map((stage) => {
1361
+ return Math.floor(stage / count * density);
1362
+ });
1363
+ const diff = density - densities.reduce((count$1, current) => count$1 += current, 0);
1364
+ if (diff) densities[densities.length - 1] += diff;
1365
+ const positionListPromises = densities.map((density$1, i) => {
1366
+ return lerpArray({
1367
+ scene: _options.scene,
1368
+ start: positions[i],
1369
+ end: positions[i + 1],
1370
+ count: density$1,
1371
+ clampToGround: true,
1372
+ classificationType: _options.classificationType,
1373
+ terrainProvider: _options.terrainProvider
1374
+ });
1316
1375
  });
1317
- return triangles.reduce((count, current) => count += triangleArea(...current), 0);
1376
+ const stagePromises = (await Promise.all(positionListPromises)).map(async (positions$1) => {
1377
+ const { count: count$1 } = await distance(positions$1);
1378
+ return count$1;
1379
+ });
1380
+ const groundStages = await Promise.all(stagePromises);
1381
+ return {
1382
+ stages: groundStages,
1383
+ count: groundStages.reduce((count$1, current) => count$1 += current, 0)
1384
+ };
1318
1385
  }
1319
1386
 
1320
1387
  //#endregion
1321
1388
  //#region measure/measureArea.ts
1322
1389
  const schemeMeasureArea = new PlotScheme({
1323
- type: "measureArea",
1390
+ type: "MeasureArea",
1324
1391
  allowManualComplete: (packable) => packable.positions.length >= 3,
1325
1392
  skeletons: [control, interval],
1326
- initEntites: () => [new cesium.Entity({
1327
- label: { font: "14pt" },
1328
- polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
1329
- polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
1330
- })],
1331
- render(options) {
1332
- const { mouse, packable } = options;
1333
- const entity = options.previous.entities?.[0] ?? new cesium.Entity({
1393
+ initRender() {
1394
+ return { entities: [new cesium.Entity({
1334
1395
  label: { font: "14pt" },
1335
1396
  polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
1336
1397
  polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
1337
- });
1398
+ })] };
1399
+ },
1400
+ render(context) {
1401
+ const entity = context.previous.entities[0];
1402
+ const { mouse, packable } = context;
1338
1403
  const positions = [...packable.positions ?? []];
1339
1404
  mouse && positions.push(mouse);
1340
1405
  if (positions.length === 2) {
@@ -1366,19 +1431,67 @@ const schemeMeasureArea = new PlotScheme({
1366
1431
  });
1367
1432
 
1368
1433
  //#endregion
1369
- //#region scheme/billboard.ts
1370
- /**
1371
- * 广告牌标绘方案
1372
- */
1373
- const schemeBillboard = new PlotScheme({
1374
- type: "billboard",
1434
+ //#region measure/measureDistance.ts
1435
+ const schemeMeasureDistance = new PlotScheme({
1436
+ type: "MeasureDistance",
1437
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1438
+ skeletons: [control],
1439
+ initRender() {
1440
+ return { entities: [new cesium.Entity({ polyline: {
1441
+ width: 2,
1442
+ material: cesium.Color.YELLOW.withAlpha(.5)
1443
+ } })] };
1444
+ },
1445
+ render(context) {
1446
+ context.previous.entities[0];
1447
+ const { mouse, packable, previous } = context;
1448
+ const entities = previous.entities;
1449
+ const positions = [...packable.positions ?? []];
1450
+ mouse && positions.push(mouse);
1451
+ if (positions.length < 2) return { entities };
1452
+ const pl = entities[0];
1453
+ pl.polyline ??= new cesium.PolylineGraphics();
1454
+ pl.polyline.positions = new cesium.CallbackProperty(() => positions, false);
1455
+ positions.forEach((item, index) => {
1456
+ if (!entities[index + 1]) entities[index + 1] = new cesium.Entity({
1457
+ position: item,
1458
+ label: new cesium.LabelGraphics({
1459
+ backgroundColor: cesium.Color.fromCssColorString("#fff"),
1460
+ font: "12pt sans-serif"
1461
+ })
1462
+ });
1463
+ });
1464
+ entities.splice(positions.length, entities.length - positions.length - 1);
1465
+ distance(positions).then(({ count, stages }) => {
1466
+ stages.forEach((stage, index) => {
1467
+ entities[index + 1].position = new cesium.CallbackPositionProperty(() => cesium.Cartesian3.midpoint(positions[index], positions[index + 1], new cesium.Cartesian3()), false);
1468
+ entities[index + 1].label.text = new cesium.CallbackProperty(() => `${stage.toFixed(2)} m`, false);
1469
+ });
1470
+ if (stages.length > 1) {
1471
+ entities[entities.length - 1].position = new cesium.CallbackPositionProperty(() => positions[positions.length - 1], false);
1472
+ entities[entities.length - 1].label.text = new cesium.CallbackProperty(() => `${count.toFixed(2)} m`, false);
1473
+ } else {
1474
+ entities[entities.length - 1].position = void 0;
1475
+ entities[entities.length - 1].label.text = void 0;
1476
+ }
1477
+ });
1478
+ return { entities };
1479
+ }
1480
+ });
1481
+
1482
+ //#endregion
1483
+ //#region scheme/Billboard.ts
1484
+ const PlotSchemeBillboard = new PlotScheme({
1485
+ type: "Billboard",
1375
1486
  complete: (packable) => packable.positions.length >= 1,
1376
1487
  skeletons: [moved],
1377
- initEntites: () => [new cesium.Entity({ billboard: {
1378
- image: "/favicon.svg",
1379
- width: 32,
1380
- height: 32
1381
- } })],
1488
+ initRender: () => {
1489
+ return { entities: [new cesium.Entity({ billboard: {
1490
+ image: "/favicon.svg",
1491
+ width: 32,
1492
+ height: 32
1493
+ } })] };
1494
+ },
1382
1495
  render(options) {
1383
1496
  const { mouse, packable } = options;
1384
1497
  const entity = options.previous.entities?.[0] ?? new cesium.Entity({ billboard: {} });
@@ -1389,47 +1502,130 @@ const schemeBillboard = new PlotScheme({
1389
1502
  });
1390
1503
 
1391
1504
  //#endregion
1392
- //#region scheme/label.ts
1393
- /**
1394
- * 标签文字标绘方案
1395
- */
1396
- const schemeLabel = new PlotScheme({
1397
- type: "label",
1505
+ //#region scheme/BillboardPinBuilder.ts
1506
+ const PlotSchemeBillboardPinBuilder = new PlotScheme({
1507
+ type: "BillboardPinBuilder",
1398
1508
  complete: (packable) => packable.positions.length >= 1,
1399
1509
  skeletons: [moved],
1400
- initEntites: () => [new cesium.Entity({ label: { text: "Label" } })],
1401
- render(options) {
1402
- const { mouse, packable } = options;
1403
- const entity = options.previous.entities?.[0] ?? new cesium.Entity({ label: {} });
1404
- const position = packable.positions?.[0] ?? mouse;
1510
+ initRender() {
1511
+ return { entities: [new cesium.Entity({ billboard: {} })] };
1512
+ },
1513
+ render(context) {
1514
+ const entity = context.previous.entities[0];
1515
+ const position = context.packable.positions[0] ?? context.mouse;
1405
1516
  entity.position = new cesium.CallbackPositionProperty(() => position, true);
1406
1517
  return { entities: [entity] };
1407
1518
  }
1408
1519
  });
1409
1520
 
1410
1521
  //#endregion
1411
- //#region scheme/polygon.ts
1412
- /**
1413
- * 内置的多边形标绘方案
1414
- */
1415
- const schemePolygon = new PlotScheme({
1416
- type: "polygon",
1417
- allowManualComplete: (packable) => packable.positions.length >= 3,
1522
+ //#region scheme/Cylinder.ts
1523
+ const PlotSchemeCylinder = new PlotScheme({
1524
+ type: "Cylinder",
1525
+ complete: (packable) => packable.positions.length >= 2,
1526
+ skeletons: [moved, control],
1527
+ initRender() {
1528
+ return { entities: [new cesium.Entity({ cylinder: {} })] };
1529
+ },
1530
+ render(context) {
1531
+ const entity = context.previous.entities[0];
1532
+ const positions = [...context.packable.positions];
1533
+ if (positions.length === 0) return context.previous;
1534
+ if (positions.length === 1) {
1535
+ const position = context.mouse;
1536
+ position && positions.push(position);
1537
+ }
1538
+ if (positions.length < 2) return context.previous;
1539
+ entity.position = new cesium.ConstantPositionProperty(positions[0]);
1540
+ const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
1541
+ entity.cylinder.bottomRadius = new cesium.CallbackProperty(() => radius, false);
1542
+ if (context.defining || !(0, vesium.toPropertyValue)(entity.cylinder.length)) entity.cylinder.length = (0, vesium.toProperty)(radius * 2);
1543
+ return { entities: [entity] };
1544
+ }
1545
+ });
1546
+
1547
+ //#endregion
1548
+ //#region scheme/Ellipse.ts
1549
+ const PlotSchemeEllipse = new PlotScheme({
1550
+ type: "Ellipse",
1551
+ complete: (packable) => packable.positions.length >= 2,
1552
+ skeletons: [moved, control],
1553
+ initRender() {
1554
+ return { entities: [new cesium.Entity({ ellipse: {} })] };
1555
+ },
1556
+ render(context) {
1557
+ const entity = context.previous.entities[0];
1558
+ const positions = [...context.packable.positions];
1559
+ if (positions.length === 0) return context.previous;
1560
+ if (positions.length === 1) {
1561
+ const position = context.mouse;
1562
+ position && positions.push(position);
1563
+ }
1564
+ if (positions.length < 2) return context.previous;
1565
+ entity.position = new cesium.ConstantPositionProperty(positions[0]);
1566
+ const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
1567
+ entity.ellipse.semiMinorAxis = new cesium.CallbackProperty(() => radius || 1, false);
1568
+ entity.ellipse.semiMajorAxis = entity.ellipse.semiMinorAxis;
1569
+ return { entities: [entity] };
1570
+ }
1571
+ });
1572
+
1573
+ //#endregion
1574
+ //#region scheme/Label.ts
1575
+ const PlotSchemeLabel = new PlotScheme({
1576
+ type: "Label",
1577
+ complete: (packable) => packable.positions.length >= 1,
1578
+ skeletons: [moved],
1579
+ initRender() {
1580
+ return { entities: [new cesium.Entity({ label: { text: "Label" } })] };
1581
+ },
1582
+ render(context) {
1583
+ const entity = context.previous.entities[0];
1584
+ const position = context.packable.positions[0] ?? context.mouse;
1585
+ entity.position = new cesium.CallbackPositionProperty(() => position, true);
1586
+ return { entities: [entity] };
1587
+ }
1588
+ });
1589
+
1590
+ //#endregion
1591
+ //#region scheme/Point.ts
1592
+ const PlotSchemePoint = new PlotScheme({
1593
+ type: "Point",
1594
+ complete: (packable) => packable.positions.length >= 1,
1595
+ skeletons: [moved],
1596
+ initRender() {
1597
+ return { entities: [new cesium.Entity({ point: {
1598
+ pixelSize: 10,
1599
+ color: cesium.Color.RED
1600
+ } })] };
1601
+ },
1602
+ render(context) {
1603
+ const entity = context.previous.entities[0];
1604
+ const position = context.packable.positions[0] ?? context.mouse;
1605
+ entity.position = new cesium.CallbackPositionProperty(() => position, true);
1606
+ return { entities: [entity] };
1607
+ }
1608
+ });
1609
+
1610
+ //#endregion
1611
+ //#region scheme/Polygon.ts
1612
+ const PlotSchemePolygon = new PlotScheme({
1613
+ type: "Polygon",
1614
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1418
1615
  skeletons: [
1616
+ moved,
1419
1617
  control,
1420
- interval,
1421
- moved
1618
+ interval
1422
1619
  ],
1423
- initEntites: () => [new cesium.Entity({
1424
- polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
1425
- polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
1426
- })],
1620
+ initRender: () => {
1621
+ return { entities: [new cesium.Entity({
1622
+ polyline: {},
1623
+ polygon: {}
1624
+ })] };
1625
+ },
1427
1626
  render(options) {
1428
1627
  const { mouse, packable } = options;
1429
- const entity = options.previous.entities?.[0] ?? new cesium.Entity({
1430
- polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
1431
- polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
1432
- });
1628
+ const entity = options.previous.entities[0];
1433
1629
  const positions = [...packable.positions ?? []];
1434
1630
  mouse && positions.push(mouse);
1435
1631
  if (positions.length === 2) {
@@ -1450,51 +1646,362 @@ const schemePolygon = new PlotScheme({
1450
1646
  });
1451
1647
 
1452
1648
  //#endregion
1453
- //#region scheme/polyline.ts
1454
- /**
1455
- * 内置的线段标绘方案
1456
- */
1457
- const schemePolyline = new PlotScheme({
1458
- type: "polyline",
1459
- allowManualComplete: (packable) => packable.positions.length >= 2,
1649
+ //#region scheme/PolygonArc.ts
1650
+ const PlotSchemePolygonArc = new PlotScheme({
1651
+ type: "PolygonArc",
1652
+ complete: (packable) => packable.positions.length >= 3,
1653
+ skeletons: [moved, control],
1654
+ initRender() {
1655
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1656
+ },
1657
+ render(context) {
1658
+ const entity = context.previous.entities[0];
1659
+ const points = context.packable.positions;
1660
+ if (points.length < 3) context.mouse && points.push(context.mouse.clone());
1661
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1662
+ if (coords.length < 3) {
1663
+ entity.polygon.hierarchy = void 0;
1664
+ return context.previous;
1665
+ }
1666
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arc)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1667
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1668
+ return { entities: [entity] };
1669
+ }
1670
+ });
1671
+
1672
+ //#endregion
1673
+ //#region scheme/PolygonArrowAttackDirection.ts
1674
+ const PlotSchemePolygonArrowAttackDirection = new PlotScheme({
1675
+ type: "PolygonArrowAttackDirection",
1676
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1460
1677
  skeletons: [
1678
+ moved,
1461
1679
  control,
1462
- intervalNonclosed,
1463
- moved
1680
+ intervalNonclosed
1464
1681
  ],
1465
- initEntites: () => [new cesium.Entity({ polyline: { width: 1 } })],
1466
- render(options) {
1467
- const { mouse, packable } = options;
1468
- const entity = options.previous.entities?.[0] ?? new cesium.Entity({ polyline: {} });
1469
- entity.polyline.positions = new cesium.CallbackProperty(() => {
1470
- const positions = [...packable.positions ?? []].concat(mouse ? [mouse] : []);
1471
- return positions.length >= 2 ? positions : [];
1472
- }, false);
1682
+ initRender() {
1683
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1684
+ },
1685
+ render(context) {
1686
+ const entity = context.previous.entities[0];
1687
+ const points = context.packable.positions;
1688
+ context.mouse && points.push(context.mouse.clone());
1689
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1690
+ if (coords.length < 3) {
1691
+ entity.polygon.hierarchy = void 0;
1692
+ return context.previous;
1693
+ }
1694
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowAttackDirection)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1695
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1473
1696
  return { entities: [entity] };
1474
1697
  }
1475
1698
  });
1476
1699
 
1477
1700
  //#endregion
1478
- //#region scheme/rectangle.ts
1479
- /**
1480
- * 内置的多边形标绘方案
1481
- */
1482
- const schemeRectangle = new PlotScheme({
1483
- type: "rectangle",
1701
+ //#region scheme/PolygonArrowAttackDirectionTailed.ts
1702
+ const PlotSchemePolygonArrowAttackDirectionTailed = new PlotScheme({
1703
+ type: "PolygonArrowAttackDirectionTailed",
1704
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1705
+ skeletons: [
1706
+ moved,
1707
+ control,
1708
+ intervalNonclosed
1709
+ ],
1710
+ initRender() {
1711
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1712
+ },
1713
+ render(context) {
1714
+ const entity = context.previous.entities[0];
1715
+ const points = context.packable.positions;
1716
+ context.mouse && points.push(context.mouse.clone());
1717
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1718
+ if (coords.length < 3) {
1719
+ entity.polygon.hierarchy = void 0;
1720
+ return context.previous;
1721
+ }
1722
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowAttackDirectionTailed)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1723
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1724
+ return { entities: [entity] };
1725
+ }
1726
+ });
1727
+
1728
+ //#endregion
1729
+ //#region scheme/PolygonArrowClamped.ts
1730
+ const PlotSchemePolygonArrowClamped = new PlotScheme({
1731
+ type: "PolygonArrowClamped",
1732
+ complete: (packable) => packable.positions.length >= 5,
1733
+ skeletons: [moved, control],
1734
+ initRender() {
1735
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1736
+ },
1737
+ render(context) {
1738
+ const entity = context.previous.entities[0];
1739
+ const points = context.packable.positions;
1740
+ if (points.length < 5) {
1741
+ const mouse = context.mouse;
1742
+ mouse && points.push(mouse.clone());
1743
+ }
1744
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1745
+ if (coords.length >= 3) {
1746
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowClamped)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1747
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1748
+ } else entity.polygon.hierarchy = void 0;
1749
+ return { entities: [entity] };
1750
+ }
1751
+ });
1752
+
1753
+ //#endregion
1754
+ //#region scheme/PolygonArrowStraight.ts
1755
+ const PlotSchemePolygonArrowStraight = new PlotScheme({
1756
+ type: "PolygonArrowStraight",
1484
1757
  complete: (packable) => packable.positions.length >= 2,
1758
+ skeletons: [moved, control],
1759
+ initRender() {
1760
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1761
+ },
1762
+ render(context) {
1763
+ const entity = context.previous.entities[0];
1764
+ const points = context.packable.positions;
1765
+ if (points.length < 2) {
1766
+ const mouse = context.mouse;
1767
+ mouse && points.push(mouse.clone());
1768
+ }
1769
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1770
+ if (coords.length >= 2) {
1771
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowStraight)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1772
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1773
+ } else entity.polygon.hierarchy = void 0;
1774
+ return { entities: [entity] };
1775
+ }
1776
+ });
1777
+
1778
+ //#endregion
1779
+ //#region scheme/PolygonArrowStraightSharp.ts
1780
+ const PlotSchemePolygonArrowStraightSharp = new PlotScheme({
1781
+ type: "PolygonArrowStraightSharp",
1782
+ complete: (packable) => packable.positions.length >= 2,
1783
+ skeletons: [moved, control],
1784
+ initRender() {
1785
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1786
+ },
1787
+ render(context) {
1788
+ const entity = context.previous.entities[0];
1789
+ const points = context.packable.positions;
1790
+ if (points.length < 2) {
1791
+ const mouse = context.mouse;
1792
+ mouse && points.push(mouse.clone());
1793
+ }
1794
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1795
+ if (coords.length >= 2) {
1796
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowStraightSharp)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1797
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1798
+ } else entity.polygon.hierarchy = void 0;
1799
+ return { entities: [entity] };
1800
+ }
1801
+ });
1802
+
1803
+ //#endregion
1804
+ //#region scheme/PolygonArrowUnitCombatOperation.ts
1805
+ const PlotSchemePolygonArrowUnitCombatOperation = new PlotScheme({
1806
+ type: "PolygonArrowUnitCombatOperation",
1807
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1485
1808
  skeletons: [
1809
+ moved,
1486
1810
  control,
1487
- interval,
1488
- moved
1811
+ intervalNonclosed
1489
1812
  ],
1490
- initEntites: () => [new cesium.Entity({ rectangle: { material: cesium.Color.YELLOW.withAlpha(.5) } })],
1491
- render(options) {
1492
- const { mouse, packable } = options;
1493
- const entity = options.previous.entities?.[0] ?? new cesium.Entity({ rectangle: { material: cesium.Color.YELLOW.withAlpha(.5) } });
1494
- const positions = [...packable.positions ?? []];
1495
- mouse && positions.push(mouse);
1496
- if (positions.length >= 2) entity.rectangle.coordinates = new cesium.CallbackProperty(() => cesium.Rectangle.fromCartesianArray(positions), false);
1497
- else entity.rectangle.coordinates = void 0;
1813
+ initRender() {
1814
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1815
+ },
1816
+ render(context) {
1817
+ const entity = context.previous.entities[0];
1818
+ const points = context.packable.positions;
1819
+ context.mouse && points.push(context.mouse.clone());
1820
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1821
+ if (coords.length < 2) {
1822
+ entity.polygon.hierarchy = void 0;
1823
+ return context.previous;
1824
+ }
1825
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowUnitCombatOperation)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1826
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1827
+ return { entities: [entity] };
1828
+ }
1829
+ });
1830
+
1831
+ //#endregion
1832
+ //#region scheme/PolygonArrowUnitCombatOperationTailed.ts
1833
+ const PlotSchemePolygonArrowUnitCombatOperationTailed = new PlotScheme({
1834
+ type: "PolygonArrowUnitCombatOperationTailed",
1835
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1836
+ skeletons: [
1837
+ moved,
1838
+ control,
1839
+ interval
1840
+ ],
1841
+ initRender() {
1842
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1843
+ },
1844
+ render(context) {
1845
+ const entity = context.previous.entities[0];
1846
+ const points = context.packable.positions;
1847
+ context.mouse && points.push(context.mouse.clone());
1848
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1849
+ if (coords.length < 2) {
1850
+ entity.polygon.hierarchy = void 0;
1851
+ return context.previous;
1852
+ }
1853
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowUnitCombatOperationTailed)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1854
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1855
+ return { entities: [entity] };
1856
+ }
1857
+ });
1858
+
1859
+ //#endregion
1860
+ //#region scheme/PolygonAssemblingPlace.ts
1861
+ const PlotSchemePolygonAssemblingPlace = new PlotScheme({
1862
+ type: "PolygonAssemblingPlace",
1863
+ complete: (packable) => packable.positions.length >= 3,
1864
+ skeletons: [
1865
+ moved,
1866
+ control,
1867
+ interval
1868
+ ],
1869
+ initRender() {
1870
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1871
+ },
1872
+ render(context) {
1873
+ const entity = context.previous.entities[0];
1874
+ const points = context.packable.positions;
1875
+ context.mouse && points.push(context.mouse.clone());
1876
+ const coords = points.map((e) => (0, vesium.toCoord)(e));
1877
+ if (coords.length < 2) {
1878
+ entity.polygon.hierarchy = void 0;
1879
+ return context.previous;
1880
+ }
1881
+ if (coords.length === 2) {
1882
+ const c0 = (0, vesium.toCartographic)(coords[0]);
1883
+ const c1 = (0, vesium.toCartographic)(coords[1]);
1884
+ const latitude = c0.latitude;
1885
+ const height = c0.height;
1886
+ const longitude = c1.longitude - (c0.longitude - c1.longitude);
1887
+ coords.push((0, vesium.toCoord)(new cesium.Cartographic(longitude, latitude, height)));
1888
+ }
1889
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.assemblingPlace)(coords).map((item) => (0, vesium.toCartesian3)(item)));
1890
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1891
+ return { entities: [entity] };
1892
+ }
1893
+ });
1894
+
1895
+ //#endregion
1896
+ //#region scheme/PolygonSmooth.ts
1897
+ const PlotSchemePolygonSmooth = new PlotScheme({
1898
+ type: "PolygonSmooth",
1899
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1900
+ skeletons: [
1901
+ moved,
1902
+ control,
1903
+ intervalNonclosed
1904
+ ],
1905
+ initRender() {
1906
+ return { entities: [new cesium.Entity({ polygon: {} })] };
1907
+ },
1908
+ render(context) {
1909
+ const entity = context.previous.entities[0];
1910
+ const positions = context.packable.positions;
1911
+ const mousePosition = context.mouse;
1912
+ mousePosition && positions.push(mousePosition.clone());
1913
+ if (positions.length <= 2) {
1914
+ entity.polygon.hierarchy = void 0;
1915
+ return context.previous;
1916
+ }
1917
+ const wgs84s = positions.map((e) => (0, vesium.toCoord)(e));
1918
+ wgs84s.push(wgs84s[0]);
1919
+ const { features } = __turf_turf.polygonSmooth(__turf_turf.polygon([wgs84s]), { iterations: 3 });
1920
+ const hierarchy = new cesium.PolygonHierarchy(features[0].geometry.coordinates[0].map((item) => (0, vesium.toCartesian3)(item)).filter((e) => !!e));
1921
+ entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
1922
+ return { entities: [entity] };
1923
+ }
1924
+ });
1925
+
1926
+ //#endregion
1927
+ //#region scheme/Polyline.ts
1928
+ const PlotSchemePolyline = new PlotScheme({
1929
+ type: "Polyline",
1930
+ allowManualComplete: (packable) => packable.positions.length > 1,
1931
+ skeletons: [
1932
+ moved,
1933
+ control,
1934
+ intervalNonclosed
1935
+ ],
1936
+ initRender() {
1937
+ return { entities: [new cesium.Entity({ polyline: {
1938
+ material: cesium.Color.RED,
1939
+ width: 2
1940
+ } })] };
1941
+ },
1942
+ render(context) {
1943
+ const entity = context.previous.entities[0];
1944
+ const positions = [...context.packable.positions];
1945
+ const mouse = context.mouse;
1946
+ mouse && positions.push(mouse.clone());
1947
+ const cache = positions.length >= 2 ? positions : [];
1948
+ entity.polyline.positions = new cesium.CallbackProperty(() => cache, false);
1949
+ return { entities: [entity] };
1950
+ }
1951
+ });
1952
+
1953
+ //#endregion
1954
+ //#region scheme/PolylineCurve.ts
1955
+ const PlotSchemePolylineCurve = new PlotScheme({
1956
+ type: "PolylineCurve",
1957
+ allowManualComplete: (packable) => packable.positions.length > 1,
1958
+ skeletons: [
1959
+ moved,
1960
+ control,
1961
+ intervalNonclosed
1962
+ ],
1963
+ initRender() {
1964
+ return { entities: [new cesium.Entity({ polyline: {
1965
+ material: cesium.Color.RED,
1966
+ width: 2
1967
+ } })] };
1968
+ },
1969
+ render(context) {
1970
+ const entity = context.previous.entities[0];
1971
+ const positions = [...context.packable.positions];
1972
+ const mouse = context.mouse;
1973
+ mouse && positions.push(mouse.clone());
1974
+ if (positions.length < 2) {
1975
+ entity.polyline.positions = void 0;
1976
+ return context.previous;
1977
+ }
1978
+ const coords = positions.map((position) => (0, vesium.toCoord)(position));
1979
+ const { geometry: { coordinates } } = __turf_turf.bezierSpline(__turf_turf.lineString(coords));
1980
+ entity.polyline.positions = new cesium.CallbackProperty(() => coordinates.map(vesium.toCartesian3), false);
1981
+ return { entities: [entity] };
1982
+ }
1983
+ });
1984
+
1985
+ //#endregion
1986
+ //#region scheme/Rectangle.ts
1987
+ const PlotSchemeRectangle = new PlotScheme({
1988
+ type: "Rectangle",
1989
+ complete: (packable) => packable.positions.length >= 2,
1990
+ skeletons: [moved, control],
1991
+ initRender() {
1992
+ return { entities: [new cesium.Entity({ rectangle: {} })] };
1993
+ },
1994
+ render(context) {
1995
+ const entity = context.previous.entities[0];
1996
+ const positions = [...context.packable.positions];
1997
+ const mouse = context.mouse;
1998
+ mouse && positions.push(mouse.clone());
1999
+ if (positions.length < 2) {
2000
+ entity.rectangle.coordinates = void 0;
2001
+ return context.previous;
2002
+ }
2003
+ const coordinates = cesium.Rectangle.fromCartesianArray(positions ?? []);
2004
+ entity.rectangle.coordinates = new cesium.CallbackProperty(() => coordinates, false);
1498
2005
  return { entities: [entity] };
1499
2006
  }
1500
2007
  });
@@ -1503,6 +2010,26 @@ const schemeRectangle = new PlotScheme({
1503
2010
  exports.PlotAction = PlotAction;
1504
2011
  exports.PlotFeature = PlotFeature;
1505
2012
  exports.PlotScheme = PlotScheme;
2013
+ exports.PlotSchemeBillboard = PlotSchemeBillboard;
2014
+ exports.PlotSchemeBillboardPinBuilder = PlotSchemeBillboardPinBuilder;
2015
+ exports.PlotSchemeCylinder = PlotSchemeCylinder;
2016
+ exports.PlotSchemeEllipse = PlotSchemeEllipse;
2017
+ exports.PlotSchemeLabel = PlotSchemeLabel;
2018
+ exports.PlotSchemePoint = PlotSchemePoint;
2019
+ exports.PlotSchemePolygon = PlotSchemePolygon;
2020
+ exports.PlotSchemePolygonArc = PlotSchemePolygonArc;
2021
+ exports.PlotSchemePolygonArrowAttackDirection = PlotSchemePolygonArrowAttackDirection;
2022
+ exports.PlotSchemePolygonArrowAttackDirectionTailed = PlotSchemePolygonArrowAttackDirectionTailed;
2023
+ exports.PlotSchemePolygonArrowClamped = PlotSchemePolygonArrowClamped;
2024
+ exports.PlotSchemePolygonArrowStraight = PlotSchemePolygonArrowStraight;
2025
+ exports.PlotSchemePolygonArrowStraightSharp = PlotSchemePolygonArrowStraightSharp;
2026
+ exports.PlotSchemePolygonArrowUnitCombatOperation = PlotSchemePolygonArrowUnitCombatOperation;
2027
+ exports.PlotSchemePolygonArrowUnitCombatOperationTailed = PlotSchemePolygonArrowUnitCombatOperationTailed;
2028
+ exports.PlotSchemePolygonAssemblingPlace = PlotSchemePolygonAssemblingPlace;
2029
+ exports.PlotSchemePolygonSmooth = PlotSchemePolygonSmooth;
2030
+ exports.PlotSchemePolyline = PlotSchemePolyline;
2031
+ exports.PlotSchemePolylineCurve = PlotSchemePolylineCurve;
2032
+ exports.PlotSchemeRectangle = PlotSchemeRectangle;
1506
2033
  exports.PlotSkeletonEntity = PlotSkeletonEntity;
1507
2034
  exports.SampledPlotProperty = SampledPlotProperty;
1508
2035
  exports.SampledPlotStrategy = SampledPlotStrategy;
@@ -1510,11 +2037,7 @@ exports.control = control;
1510
2037
  exports.interval = interval;
1511
2038
  exports.intervalNonclosed = intervalNonclosed;
1512
2039
  exports.moved = moved;
1513
- exports.schemeBillboard = schemeBillboard;
1514
- exports.schemeLabel = schemeLabel;
1515
2040
  exports.schemeMeasureArea = schemeMeasureArea;
1516
- exports.schemePolygon = schemePolygon;
1517
- exports.schemePolyline = schemePolyline;
1518
- exports.schemeRectangle = schemeRectangle;
2041
+ exports.schemeMeasureDistance = schemeMeasureDistance;
1519
2042
  exports.usePlot = usePlot;
1520
2043
  //# sourceMappingURL=index.cjs.map