@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.mjs CHANGED
@@ -1,7 +1,9 @@
1
- import { CallbackPositionProperty, CallbackProperty, Cartesian3, Cartographic, ClassificationType, Color, ConstantPositionProperty, ConstantProperty, CoplanarPolygonGeometry, CustomDataSource, Ellipsoid, Entity, Event, HorizontalOrigin, JulianDate, PerInstanceColorAppearance, PolygonGeometry, PolygonHierarchy, PrimitiveCollection, Rectangle, ScreenSpaceEventType, TimeInterval, VertexFormat, VerticalOrigin, createGuid, sampleTerrainMostDetailed } from "cesium";
2
- import { arrayDiff, assertError, canvasCoordToCartesian, isFunction, pickHitGraphic, toCartesian3, toCartographic, useCesiumEventListener, useDataSource, useEntityScope, useGraphicEvent, usePrimitive, usePrimitiveScope, useScreenSpaceEventHandler, useViewer } from "vesium";
1
+ import { CallbackPositionProperty, CallbackProperty, Cartesian3, Cartographic, ClassificationType, Color, ConstantPositionProperty, ConstantProperty, CoplanarPolygonGeometry, CustomDataSource, Ellipsoid, Entity, Event, HorizontalOrigin, JulianDate, LabelGraphics, PerInstanceColorAppearance, PolygonGeometry, PolygonHierarchy, PolylineGraphics, PrimitiveCollection, Rectangle, ScreenSpaceEventType, TimeInterval, VertexFormat, VerticalOrigin, createGuid, sampleTerrainMostDetailed } from "cesium";
2
+ import { arrayDiff, assertError, canvasCoordToCartesian, isFunction, pickHitGraphic, toCartesian3, toCartographic, toCoord, toProperty, toPropertyValue, useCesiumEventListener, useDataSource, useEntityScope, useGraphicEvent, usePrimitive, usePrimitiveScope, useScreenSpaceEventHandler, useViewer } from "vesium";
3
3
  import { assert, onKeyStroke, promiseTimeout, watchArray } from "@vueuse/core";
4
4
  import { computed, nextTick, ref, shallowReactive, shallowRef, toValue, watch, watchEffect } from "vue";
5
+ import { arc, arrowAttackDirection, arrowAttackDirectionTailed, arrowClamped, arrowStraight, arrowStraightSharp, arrowUnitCombatOperation, arrowUnitCombatOperationTailed, assemblingPlace } from "@vesium/geometry";
6
+ import * as turf from "@turf/turf";
5
7
 
6
8
  //#region usePlot/PlotScheme.ts
7
9
  var PlotScheme = class PlotScheme {
@@ -11,9 +13,7 @@ var PlotScheme = class PlotScheme {
11
13
  this.allowManualComplete = options.allowManualComplete;
12
14
  this.definingCursor = options.definingCursor ?? "crosshair";
13
15
  this.skeletons = options.skeletons?.map((item) => item()) ?? [];
14
- this.initEntites = options.initEntites;
15
- this.initPrimitives = options.initPrimitives;
16
- this.initGroundPrimitives = options.initGroundPrimitives;
16
+ this.initRender = options.initRender;
17
17
  this.render = options.render;
18
18
  }
19
19
  /**
@@ -40,17 +40,9 @@ var PlotScheme = class PlotScheme {
40
40
  */
41
41
  skeletons;
42
42
  /**
43
- * 初始化时创建`Entity`的函数,创建后的`Entity`会作为配置项传入`render`中
44
- */
45
- initEntites;
46
- /**
47
- * 初始化时创建`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
48
- */
49
- initPrimitives;
50
- /**
51
43
  * 初始化时创建贴地`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
52
44
  */
53
- initGroundPrimitives;
45
+ initRender;
54
46
  /**
55
47
  * 当标绘数据变化时,会触发`render`回调,返回的数据会被添加到cesium中
56
48
  */
@@ -190,16 +182,13 @@ var SampledPlotProperty = class SampledPlotProperty {
190
182
  const end = this._times[this._times.length - 1];
191
183
  if (JulianDate.lessThan(time, start) || JulianDate.greaterThan(time, end)) switch (this.strategy) {
192
184
  case SampledPlotStrategy.STRICT: return;
193
- case SampledPlotStrategy.NEAR: {
185
+ case SampledPlotStrategy.NEAR:
194
186
  time = JulianDate.lessThan(time, this._times[0]) ? this._times[0].clone() : this._times[this._times.length - 1].clone();
195
187
  break;
196
- }
197
188
  case SampledPlotStrategy.CYCLE: {
198
189
  const startMS = JulianDate.toDate(this._times[0]).getTime();
199
- const endMS = JulianDate.toDate(this._times[this._times.length - 1]).getTime();
200
- const duration = endMS - startMS;
201
- const timeMS = JulianDate.toDate(time).getTime();
202
- const diff = (timeMS - startMS) % duration;
190
+ const duration = JulianDate.toDate(this._times[this._times.length - 1]).getTime() - startMS;
191
+ const diff = (JulianDate.toDate(time).getTime() - startMS) % duration;
203
192
  const dete = new Date(startMS + diff);
204
193
  time = JulianDate.fromDate(dete);
205
194
  break;
@@ -209,11 +198,10 @@ var SampledPlotProperty = class SampledPlotProperty {
209
198
  const nextIndex = Math.min(prevIndex, this._times.length - 1);
210
199
  const prevMs = JulianDate.toDate(this._times[prevIndex]).getTime();
211
200
  const nextMs = JulianDate.toDate(this._times[nextIndex]).getTime();
212
- const ms = JulianDate.toDate(time).getTime();
213
201
  return {
214
202
  prevIndex,
215
203
  nextIndex,
216
- proportion: (ms - prevMs) / (nextMs - prevMs) || 0
204
+ proportion: (JulianDate.toDate(time).getTime() - prevMs) / (nextMs - prevMs) || 0
217
205
  };
218
206
  }
219
207
  /**
@@ -225,10 +213,13 @@ var SampledPlotProperty = class SampledPlotProperty {
225
213
  * @template D 数据类型。
226
214
  */
227
215
  getValue(time, result) {
228
- result ??= { time };
216
+ result ??= {
217
+ time,
218
+ positions: []
219
+ };
229
220
  Object.assign(result, {
230
221
  time: time?.clone(),
231
- positions: void 0,
222
+ positions: [],
232
223
  derivative: void 0
233
224
  });
234
225
  if (!time) {
@@ -302,8 +293,7 @@ var SampledPlotProperty = class SampledPlotProperty {
302
293
  if (index !== -1) {
303
294
  this._sampleds.splice(index, 1);
304
295
  this._derivatives.splice(index, 1);
305
- const removed = this._times.splice(index, 1);
306
- if (removed.length) {
296
+ if (this._times.splice(index, 1).length) {
307
297
  this._definitionChanged.raiseEvent(this);
308
298
  return true;
309
299
  }
@@ -344,9 +334,10 @@ var PlotFeature = class {
344
334
  this._disabled = disabled;
345
335
  this._sampled = sampled instanceof SampledPlotProperty ? sampled : new SampledPlotProperty(sampled);
346
336
  this._sampled.definitionChanged.addEventListener((property) => this._definitionChanged.raiseEvent(this, "sampled", property, property), this);
347
- this._entities = [...this._scheme.initEntites?.() ?? []];
348
- this._primitives = [...this._scheme.initPrimitives?.() ?? []];
349
- this._groundPrimitives = [...this._scheme.initGroundPrimitives?.() ?? []];
337
+ const init = this._scheme.initRender?.() ?? {};
338
+ this._entities = [...init.entities ?? []];
339
+ this._primitives = [...init.primitives ?? []];
340
+ this._groundPrimitives = [...init.groundPrimitives ?? []];
350
341
  this._skeletons = [];
351
342
  }
352
343
  /**
@@ -532,19 +523,27 @@ function useRender(plots, current, getCurrentTime) {
532
523
  }
533
524
  });
534
525
  const update = async (plot) => {
535
- const reslut = await plot.scheme.render?.({
536
- packable: plot.sampled.getValue(getCurrentTime()),
537
- mouse: plot.defining ? mouseCartesian.value : void 0,
526
+ await nextTick();
527
+ const packable = plot.sampled.getValue(getCurrentTime());
528
+ const mouse = plot.defining ? mouseCartesian.value : void 0;
529
+ const result = await plot.scheme.render?.({
530
+ packable,
531
+ mouse,
538
532
  defining: plot.defining,
539
533
  previous: {
540
534
  entities: plot.entities,
541
535
  primitives: plot.primitives,
542
536
  groundPrimitives: plot.groundPrimitives
537
+ },
538
+ getPositions() {
539
+ const points = packable.positions;
540
+ mouse && points.push(mouse);
541
+ return points;
543
542
  }
544
543
  });
545
- plot.entities = reslut?.entities ?? [];
546
- plot.primitives = reslut?.primitives ?? [];
547
- plot.groundPrimitives = reslut?.groundPrimitives ?? [];
544
+ plot.entities = result?.entities ?? [];
545
+ plot.primitives = result?.primitives ?? [];
546
+ plot.groundPrimitives = result?.groundPrimitives ?? [];
548
547
  };
549
548
  watch(current, (plot, previous) => {
550
549
  previous && update(previous);
@@ -587,8 +586,7 @@ function useSampled(current, getCurrentTime) {
587
586
  packable.value.positions ??= [];
588
587
  packable.value.positions.push(position);
589
588
  sampled.setSample(packable.value);
590
- const completed = scheme.complete?.(packable.value);
591
- completed && PlotFeature.setDefining(current.value, false);
589
+ scheme.complete?.(packable.value) && PlotFeature.setDefining(current.value, false);
592
590
  });
593
591
  useScreenSpaceEventHandler(ScreenSpaceEventType.LEFT_DOUBLE_CLICK, async (ctx) => {
594
592
  if (!current.value || !packable.value) return;
@@ -597,10 +595,8 @@ function useSampled(current, getCurrentTime) {
597
595
  doubleClicking.value = false;
598
596
  const { scheme, defining } = current.value;
599
597
  if (!defining) return;
600
- const position = canvasCoordToCartesian(ctx.position, viewer.value.scene);
601
- if (!position) return;
602
- const completed = scheme.allowManualComplete?.(packable.value);
603
- completed && PlotFeature.setDefining(current.value, false);
598
+ if (!canvasCoordToCartesian(ctx.position, viewer.value.scene)) return;
599
+ scheme.allowManualComplete?.(packable.value) && PlotFeature.setDefining(current.value, false);
604
600
  });
605
601
  useScreenSpaceEventHandler(ScreenSpaceEventType.RIGHT_CLICK, async () => {
606
602
  if (!current.value || !packable.value) return;
@@ -650,13 +646,11 @@ function useSkeleton(plots, current, getCurrentTime) {
650
646
  const packable = plot.sampled.getValue(getCurrentTime());
651
647
  const defining = plot.defining;
652
648
  const active = current.value === plot;
653
- const skeletons = plot.scheme.skeletons;
654
- skeletons.forEach((skeleton) => {
655
- const disabled = isFunction(skeleton.disabled) ? skeleton.disabled({
649
+ plot.scheme.skeletons.forEach((skeleton) => {
650
+ if (isFunction(skeleton.disabled) ? skeleton.disabled({
656
651
  active,
657
652
  defining
658
- }) : skeleton.disabled;
659
- if (disabled) return;
653
+ }) : skeleton.disabled) return;
660
654
  const positions = skeleton.format?.(packable) ?? packable?.positions ?? [];
661
655
  positions.forEach((position, index) => {
662
656
  let entity = oldEntities.find((item) => item.index === index && item.skeleton === skeleton);
@@ -683,9 +677,9 @@ function useSkeleton(plots, current, getCurrentTime) {
683
677
  }
684
678
  plot.skeletons = entities;
685
679
  };
686
- const { addGraphicEvent } = useGraphicEvent();
680
+ const graphicEvent = useGraphicEvent();
687
681
  watchEffect((onCleanup) => {
688
- const remove = addGraphicEvent("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
682
+ onCleanup(graphicEvent.add("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
689
683
  if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
690
684
  const entity = pick.id;
691
685
  const plot = entity.plot;
@@ -718,8 +712,7 @@ function useSkeleton(plots, current, getCurrentTime) {
718
712
  return isFunction(skeleton?.dragCursor) ? skeleton.dragCursor(pick) : toValue(skeleton?.dragCursor);
719
713
  }
720
714
  }
721
- });
722
- onCleanup(remove);
715
+ }));
723
716
  });
724
717
  onKeyStroke((keyEvent) => {
725
718
  if (activeEntity.value) {
@@ -738,16 +731,13 @@ function useSkeleton(plots, current, getCurrentTime) {
738
731
  }
739
732
  });
740
733
  watchEffect((onCleanup) => {
741
- const remove = addGraphicEvent("global", "HOVER", ({ hovering, pick }) => {
742
- if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
743
- const entity = pick.id;
744
- hoverEntity.value = entity;
745
- } else hoverEntity.value = void 0;
746
- });
747
- onCleanup(remove);
734
+ onCleanup(graphicEvent.add("global", "HOVER", ({ hovering, pick }) => {
735
+ if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) hoverEntity.value = pick.id;
736
+ else hoverEntity.value = void 0;
737
+ }));
748
738
  });
749
739
  watchEffect((onCleanup) => {
750
- const remove = addGraphicEvent("global", "LEFT_CLICK", ({ event, pick }) => {
740
+ onCleanup(graphicEvent.add("global", "LEFT_CLICK", ({ event, pick }) => {
751
741
  if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
752
742
  const entity = pick.id;
753
743
  activeEntity.value = entity;
@@ -765,8 +755,7 @@ function useSkeleton(plots, current, getCurrentTime) {
765
755
  event
766
756
  });
767
757
  } else activeEntity.value = void 0;
768
- });
769
- onCleanup(remove);
758
+ }));
770
759
  });
771
760
  watchArray(plots, (value, oldValue, added, removed = []) => {
772
761
  added.forEach((plot) => update(plot));
@@ -831,8 +820,7 @@ function usePlot(options) {
831
820
  if (previous) {
832
821
  if (previous.defining) {
833
822
  const packable$1 = previous.sampled.getValue(getCurrentTime());
834
- const completed = previous.scheme.allowManualComplete?.(packable$1);
835
- if (completed) {
823
+ if (previous.scheme.allowManualComplete?.(packable$1)) {
836
824
  PlotFeature.setDefining(previous, false);
837
825
  operateResolve?.(previous);
838
826
  } else collection.delete(previous);
@@ -916,10 +904,9 @@ function control() {
916
904
  const newHeading = (viewer.camera.heading + headingAdjust) % (2 * Math.PI);
917
905
  const positions = [...packable.positions ?? []];
918
906
  const cartographic = toCartographic(positions[index]);
919
- const r = height / 1e5;
920
- const distance = r * Math.PI / 180 / 1e3;
921
- cartographic.latitude += distance * Math.cos(newHeading);
922
- cartographic.longitude += distance * Math.sin(newHeading);
907
+ const distance$1 = height / 1e5 * Math.PI / 180 / 1e3;
908
+ cartographic.latitude += distance$1 * Math.cos(newHeading);
909
+ cartographic.longitude += distance$1 * Math.sin(newHeading);
923
910
  positions[index] = toCartesian3(cartographic);
924
911
  sampled.setSample({
925
912
  time: packable.time,
@@ -928,16 +915,15 @@ function control() {
928
915
  });
929
916
  },
930
917
  render: ({ position, action }) => {
931
- const colors = {
932
- [PlotAction.IDLE]: Color.BLUE.withAlpha(.4),
933
- [PlotAction.HOVER]: Color.BLUE.withAlpha(.6),
934
- [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
935
- };
936
918
  return {
937
919
  position,
938
920
  point: {
939
921
  pixelSize: 8,
940
- color: colors[action],
922
+ color: {
923
+ [PlotAction.IDLE]: Color.BLUE.withAlpha(.4),
924
+ [PlotAction.HOVER]: Color.BLUE.withAlpha(.6),
925
+ [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
926
+ }[action],
941
927
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
942
928
  outlineWidth: 1,
943
929
  outlineColor: Color.WHITE.withAlpha(.4)
@@ -984,16 +970,15 @@ function interval() {
984
970
  },
985
971
  render: ({ position, action, active }) => {
986
972
  if (!active) return;
987
- const colors = {
988
- [PlotAction.IDLE]: Color.GREEN.withAlpha(.4),
989
- [PlotAction.HOVER]: Color.GREEN.withAlpha(.6),
990
- [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
991
- };
992
973
  return {
993
974
  position,
994
975
  point: {
995
976
  pixelSize: 6,
996
- color: colors[action],
977
+ color: {
978
+ [PlotAction.IDLE]: Color.GREEN.withAlpha(.4),
979
+ [PlotAction.HOVER]: Color.GREEN.withAlpha(.6),
980
+ [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
981
+ }[action],
997
982
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
998
983
  outlineWidth: 1,
999
984
  outlineColor: Color.WHITE.withAlpha(.4)
@@ -1038,16 +1023,15 @@ function intervalNonclosed() {
1038
1023
  });
1039
1024
  },
1040
1025
  render: ({ position, action }) => {
1041
- const colors = {
1042
- [PlotAction.IDLE]: Color.GREEN.withAlpha(.4),
1043
- [PlotAction.HOVER]: Color.GREEN.withAlpha(.6),
1044
- [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
1045
- };
1046
1026
  return {
1047
1027
  position,
1048
1028
  point: {
1049
1029
  pixelSize: 6,
1050
- color: colors[action],
1030
+ color: {
1031
+ [PlotAction.IDLE]: Color.GREEN.withAlpha(.4),
1032
+ [PlotAction.HOVER]: Color.GREEN.withAlpha(.6),
1033
+ [PlotAction.ACTIVE]: Color.GREEN.withAlpha(1)
1034
+ }[action],
1051
1035
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
1052
1036
  outlineWidth: 1,
1053
1037
  outlineColor: Color.WHITE.withAlpha(.4)
@@ -1072,10 +1056,7 @@ function moved() {
1072
1056
  const positions = packable.positions ?? [];
1073
1057
  if (positions.length === 0) return [];
1074
1058
  else if (positions.length === 1) return [positions[0]];
1075
- else {
1076
- const center = Rectangle.center(Rectangle.fromCartesianArray(positions));
1077
- return [toCartesian3(center)];
1078
- }
1059
+ else return [toCartesian3(Rectangle.center(Rectangle.fromCartesianArray(positions)))];
1079
1060
  },
1080
1061
  onDrag({ viewer, sampled, packable, event, lockCamera, dragging }) {
1081
1062
  dragging && lockCamera();
@@ -1091,18 +1072,17 @@ function moved() {
1091
1072
  });
1092
1073
  },
1093
1074
  render: ({ position, action }) => {
1094
- const colors = {
1095
- [PlotAction.IDLE]: Color.WHITE,
1096
- [PlotAction.HOVER]: Color.WHITE,
1097
- [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
1098
- };
1099
1075
  return {
1100
1076
  position,
1101
1077
  billboard: {
1102
1078
  image: svg,
1103
1079
  width: 20,
1104
1080
  height: 20,
1105
- color: colors[action],
1081
+ color: {
1082
+ [PlotAction.IDLE]: Color.WHITE,
1083
+ [PlotAction.HOVER]: Color.WHITE,
1084
+ [PlotAction.ACTIVE]: Color.AQUA.withAlpha(1)
1085
+ }[action],
1106
1086
  pixelOffset: new Cartesian3(0, -20),
1107
1087
  horizontalOrigin: HorizontalOrigin.CENTER,
1108
1088
  verticalOrigin: VerticalOrigin.BOTTOM,
@@ -1172,17 +1152,17 @@ async function clampToHeightMostDetailedByTilesetOrTerrain(options) {
1172
1152
  else resolve([]);
1173
1153
  });
1174
1154
  const [tilesetPositions, terrainPositions] = await Promise.all([tilesetPromise, terrainPromise]);
1175
- const resluts = [];
1155
+ const results = [];
1176
1156
  positions.forEach((item, index) => {
1177
1157
  const position = tilesetPositions[index] || terrainPositions[index] ? Ellipsoid.WGS84.cartographicToCartesian(terrainPositions[index]) : item.clone();
1178
- resluts.push(position);
1158
+ results.push(position);
1179
1159
  });
1180
- return resluts;
1160
+ return results;
1181
1161
  }
1182
1162
 
1183
1163
  //#endregion
1184
1164
  //#region measure/utils/triangleGrid.ts
1185
- function defaultOptions$1(original) {
1165
+ function defaultOptions$2(original) {
1186
1166
  const clampToGround = original?.clampToGround ?? false;
1187
1167
  const classificationType = original?.classificationType ?? ClassificationType.BOTH;
1188
1168
  const density = Math.floor(original?.density ?? 10);
@@ -1201,13 +1181,12 @@ function defaultOptions$1(original) {
1201
1181
  */
1202
1182
  async function triangleGrid(positions, options) {
1203
1183
  if (positions.length < 3) throw new Error("positions must >= 3");
1204
- const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1184
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$2(options);
1205
1185
  if (density <= 0) throw new Error("options.density must > 0");
1206
1186
  const bbox = Rectangle.fromCartesianArray(positions);
1207
1187
  const vertical = bbox.north - bbox.south;
1208
1188
  const horizontal = bbox.east - bbox.west;
1209
- const max = Math.max(horizontal, vertical);
1210
- const granularity = max / density;
1189
+ const granularity = Math.max(horizontal, vertical) / density;
1211
1190
  const polygonGeometry = PolygonGeometry.fromPositions({
1212
1191
  positions,
1213
1192
  vertexFormat: PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
@@ -1226,13 +1205,12 @@ async function triangleGrid(positions, options) {
1226
1205
  }
1227
1206
  if (clampToGround) {
1228
1207
  if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1229
- const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
1208
+ cartesian3List = await clampToHeightMostDetailedByTilesetOrTerrain({
1230
1209
  scene,
1231
1210
  terrainProvider,
1232
1211
  positions: cartesian3List,
1233
1212
  classificationType
1234
1213
  });
1235
- cartesian3List = detaileds;
1236
1214
  }
1237
1215
  const grid = [];
1238
1216
  while (cartesian3List?.length) {
@@ -1260,7 +1238,7 @@ function triangleArea(p0, p1, p2) {
1260
1238
  const cross = Cartesian3.cross(v0, v1, v0);
1261
1239
  return Cartesian3.magnitude(cross) * .5;
1262
1240
  }
1263
- function defaultOptions(original) {
1241
+ function defaultOptions$1(original) {
1264
1242
  const clampToGround = original?.clampToGround ?? false;
1265
1243
  const classificationType = original?.classificationType ?? ClassificationType.BOTH;
1266
1244
  const density = Math.floor(original?.density ?? 10);
@@ -1278,40 +1256,121 @@ function defaultOptions(original) {
1278
1256
  */
1279
1257
  async function area(positions, options) {
1280
1258
  if (positions.length < 2) throw new Error("positions.length must >= 2");
1281
- const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions(options);
1259
+ const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1282
1260
  if (density <= 0) throw new Error("options.density must > 0");
1283
- if (!clampToGround) {
1284
- const triangles$1 = tesselate(positions);
1285
- return triangles$1.reduce((count, current) => count += triangleArea(...current), 0);
1286
- }
1287
- const triangles = await triangleGrid(positions, {
1261
+ if (!clampToGround) return tesselate(positions).reduce((count, current) => count += triangleArea(...current), 0);
1262
+ return (await triangleGrid(positions, {
1288
1263
  density,
1289
1264
  scene,
1290
1265
  clampToGround,
1291
1266
  classificationType,
1292
1267
  terrainProvider
1268
+ })).reduce((count, current) => count += triangleArea(...current), 0);
1269
+ }
1270
+
1271
+ //#endregion
1272
+ //#region measure/utils/lerpArray.ts
1273
+ /**
1274
+ * 在起点和终点间进行插值, 返回的数组包括起点和终点,数组长度为 count+1
1275
+ */
1276
+ async function lerpArray(options) {
1277
+ const { start, end, count, scene, clampToGround, classificationType, terrainProvider } = options;
1278
+ const result = [];
1279
+ for (let i = 0; i < count; i++) {
1280
+ const position = Cartesian3.lerp(start, end, 1 / count, new Cartesian3());
1281
+ result.push(position);
1282
+ }
1283
+ result.push(end.clone());
1284
+ if (!clampToGround) return result;
1285
+ if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1286
+ return await clampToHeightMostDetailedByTilesetOrTerrain({
1287
+ scene,
1288
+ terrainProvider,
1289
+ positions: result,
1290
+ classificationType
1291
+ });
1292
+ }
1293
+
1294
+ //#endregion
1295
+ //#region measure/utils/distance.ts
1296
+ function defaultOptions(original) {
1297
+ const clampToGround = original?.clampToGround ?? false;
1298
+ const classificationType = original?.classificationType ?? ClassificationType.BOTH;
1299
+ const density = Math.floor(original?.density ?? 50);
1300
+ return {
1301
+ scene: original?.scene,
1302
+ clampToGround,
1303
+ classificationType,
1304
+ terrainProvider: original?.terrainProvider,
1305
+ density
1306
+ };
1307
+ }
1308
+ /**
1309
+ * 计算多点位之间的距离
1310
+ * @param positions
1311
+ */
1312
+ async function distance(positions, options) {
1313
+ if (positions.length < 2) throw new Error("positions.length must >= 2");
1314
+ const _options = defaultOptions(options);
1315
+ const stages = [];
1316
+ let count = 0;
1317
+ positions.forEach((position, index) => {
1318
+ if (index !== positions.length - 1) {
1319
+ const next = positions[index + 1];
1320
+ const distance$1 = Cartesian3.distance(position, next);
1321
+ stages.push(distance$1);
1322
+ count += distance$1;
1323
+ }
1324
+ });
1325
+ if (!_options.clampToGround) return {
1326
+ stages,
1327
+ count
1328
+ };
1329
+ const density = _options.density;
1330
+ if (density <= 0) throw new Error("options.density must > 0");
1331
+ const densities = stages.map((stage) => {
1332
+ return Math.floor(stage / count * density);
1333
+ });
1334
+ const diff = density - densities.reduce((count$1, current) => count$1 += current, 0);
1335
+ if (diff) densities[densities.length - 1] += diff;
1336
+ const positionListPromises = densities.map((density$1, i) => {
1337
+ return lerpArray({
1338
+ scene: _options.scene,
1339
+ start: positions[i],
1340
+ end: positions[i + 1],
1341
+ count: density$1,
1342
+ clampToGround: true,
1343
+ classificationType: _options.classificationType,
1344
+ terrainProvider: _options.terrainProvider
1345
+ });
1293
1346
  });
1294
- return triangles.reduce((count, current) => count += triangleArea(...current), 0);
1347
+ const stagePromises = (await Promise.all(positionListPromises)).map(async (positions$1) => {
1348
+ const { count: count$1 } = await distance(positions$1);
1349
+ return count$1;
1350
+ });
1351
+ const groundStages = await Promise.all(stagePromises);
1352
+ return {
1353
+ stages: groundStages,
1354
+ count: groundStages.reduce((count$1, current) => count$1 += current, 0)
1355
+ };
1295
1356
  }
1296
1357
 
1297
1358
  //#endregion
1298
1359
  //#region measure/measureArea.ts
1299
1360
  const schemeMeasureArea = new PlotScheme({
1300
- type: "measureArea",
1361
+ type: "MeasureArea",
1301
1362
  allowManualComplete: (packable) => packable.positions.length >= 3,
1302
1363
  skeletons: [control, interval],
1303
- initEntites: () => [new Entity({
1304
- label: { font: "14pt" },
1305
- polyline: { material: Color.YELLOW.withAlpha(.5) },
1306
- polygon: { material: Color.YELLOW.withAlpha(.5) }
1307
- })],
1308
- render(options) {
1309
- const { mouse, packable } = options;
1310
- const entity = options.previous.entities?.[0] ?? new Entity({
1364
+ initRender() {
1365
+ return { entities: [new Entity({
1311
1366
  label: { font: "14pt" },
1312
1367
  polyline: { material: Color.YELLOW.withAlpha(.5) },
1313
1368
  polygon: { material: Color.YELLOW.withAlpha(.5) }
1314
- });
1369
+ })] };
1370
+ },
1371
+ render(context) {
1372
+ const entity = context.previous.entities[0];
1373
+ const { mouse, packable } = context;
1315
1374
  const positions = [...packable.positions ?? []];
1316
1375
  mouse && positions.push(mouse);
1317
1376
  if (positions.length === 2) {
@@ -1343,19 +1402,67 @@ const schemeMeasureArea = new PlotScheme({
1343
1402
  });
1344
1403
 
1345
1404
  //#endregion
1346
- //#region scheme/billboard.ts
1347
- /**
1348
- * 广告牌标绘方案
1349
- */
1350
- const schemeBillboard = new PlotScheme({
1351
- type: "billboard",
1405
+ //#region measure/measureDistance.ts
1406
+ const schemeMeasureDistance = new PlotScheme({
1407
+ type: "MeasureDistance",
1408
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1409
+ skeletons: [control],
1410
+ initRender() {
1411
+ return { entities: [new Entity({ polyline: {
1412
+ width: 2,
1413
+ material: Color.YELLOW.withAlpha(.5)
1414
+ } })] };
1415
+ },
1416
+ render(context) {
1417
+ context.previous.entities[0];
1418
+ const { mouse, packable, previous } = context;
1419
+ const entities = previous.entities;
1420
+ const positions = [...packable.positions ?? []];
1421
+ mouse && positions.push(mouse);
1422
+ if (positions.length < 2) return { entities };
1423
+ const pl = entities[0];
1424
+ pl.polyline ??= new PolylineGraphics();
1425
+ pl.polyline.positions = new CallbackProperty(() => positions, false);
1426
+ positions.forEach((item, index) => {
1427
+ if (!entities[index + 1]) entities[index + 1] = new Entity({
1428
+ position: item,
1429
+ label: new LabelGraphics({
1430
+ backgroundColor: Color.fromCssColorString("#fff"),
1431
+ font: "12pt sans-serif"
1432
+ })
1433
+ });
1434
+ });
1435
+ entities.splice(positions.length, entities.length - positions.length - 1);
1436
+ distance(positions).then(({ count, stages }) => {
1437
+ stages.forEach((stage, index) => {
1438
+ entities[index + 1].position = new CallbackPositionProperty(() => Cartesian3.midpoint(positions[index], positions[index + 1], new Cartesian3()), false);
1439
+ entities[index + 1].label.text = new CallbackProperty(() => `${stage.toFixed(2)} m`, false);
1440
+ });
1441
+ if (stages.length > 1) {
1442
+ entities[entities.length - 1].position = new CallbackPositionProperty(() => positions[positions.length - 1], false);
1443
+ entities[entities.length - 1].label.text = new CallbackProperty(() => `${count.toFixed(2)} m`, false);
1444
+ } else {
1445
+ entities[entities.length - 1].position = void 0;
1446
+ entities[entities.length - 1].label.text = void 0;
1447
+ }
1448
+ });
1449
+ return { entities };
1450
+ }
1451
+ });
1452
+
1453
+ //#endregion
1454
+ //#region scheme/Billboard.ts
1455
+ const PlotSchemeBillboard = new PlotScheme({
1456
+ type: "Billboard",
1352
1457
  complete: (packable) => packable.positions.length >= 1,
1353
1458
  skeletons: [moved],
1354
- initEntites: () => [new Entity({ billboard: {
1355
- image: "/favicon.svg",
1356
- width: 32,
1357
- height: 32
1358
- } })],
1459
+ initRender: () => {
1460
+ return { entities: [new Entity({ billboard: {
1461
+ image: "/favicon.svg",
1462
+ width: 32,
1463
+ height: 32
1464
+ } })] };
1465
+ },
1359
1466
  render(options) {
1360
1467
  const { mouse, packable } = options;
1361
1468
  const entity = options.previous.entities?.[0] ?? new Entity({ billboard: {} });
@@ -1366,47 +1473,130 @@ const schemeBillboard = new PlotScheme({
1366
1473
  });
1367
1474
 
1368
1475
  //#endregion
1369
- //#region scheme/label.ts
1370
- /**
1371
- * 标签文字标绘方案
1372
- */
1373
- const schemeLabel = new PlotScheme({
1374
- type: "label",
1476
+ //#region scheme/BillboardPinBuilder.ts
1477
+ const PlotSchemeBillboardPinBuilder = new PlotScheme({
1478
+ type: "BillboardPinBuilder",
1375
1479
  complete: (packable) => packable.positions.length >= 1,
1376
1480
  skeletons: [moved],
1377
- initEntites: () => [new Entity({ label: { text: "Label" } })],
1378
- render(options) {
1379
- const { mouse, packable } = options;
1380
- const entity = options.previous.entities?.[0] ?? new Entity({ label: {} });
1381
- const position = packable.positions?.[0] ?? mouse;
1481
+ initRender() {
1482
+ return { entities: [new Entity({ billboard: {} })] };
1483
+ },
1484
+ render(context) {
1485
+ const entity = context.previous.entities[0];
1486
+ const position = context.packable.positions[0] ?? context.mouse;
1382
1487
  entity.position = new CallbackPositionProperty(() => position, true);
1383
1488
  return { entities: [entity] };
1384
1489
  }
1385
1490
  });
1386
1491
 
1387
1492
  //#endregion
1388
- //#region scheme/polygon.ts
1389
- /**
1390
- * 内置的多边形标绘方案
1391
- */
1392
- const schemePolygon = new PlotScheme({
1393
- type: "polygon",
1394
- allowManualComplete: (packable) => packable.positions.length >= 3,
1493
+ //#region scheme/Cylinder.ts
1494
+ const PlotSchemeCylinder = new PlotScheme({
1495
+ type: "Cylinder",
1496
+ complete: (packable) => packable.positions.length >= 2,
1497
+ skeletons: [moved, control],
1498
+ initRender() {
1499
+ return { entities: [new Entity({ cylinder: {} })] };
1500
+ },
1501
+ render(context) {
1502
+ const entity = context.previous.entities[0];
1503
+ const positions = [...context.packable.positions];
1504
+ if (positions.length === 0) return context.previous;
1505
+ if (positions.length === 1) {
1506
+ const position = context.mouse;
1507
+ position && positions.push(position);
1508
+ }
1509
+ if (positions.length < 2) return context.previous;
1510
+ entity.position = new ConstantPositionProperty(positions[0]);
1511
+ const radius = Cartesian3.distance(positions[0], positions[1]);
1512
+ entity.cylinder.bottomRadius = new CallbackProperty(() => radius, false);
1513
+ if (context.defining || !toPropertyValue(entity.cylinder.length)) entity.cylinder.length = toProperty(radius * 2);
1514
+ return { entities: [entity] };
1515
+ }
1516
+ });
1517
+
1518
+ //#endregion
1519
+ //#region scheme/Ellipse.ts
1520
+ const PlotSchemeEllipse = new PlotScheme({
1521
+ type: "Ellipse",
1522
+ complete: (packable) => packable.positions.length >= 2,
1523
+ skeletons: [moved, control],
1524
+ initRender() {
1525
+ return { entities: [new Entity({ ellipse: {} })] };
1526
+ },
1527
+ render(context) {
1528
+ const entity = context.previous.entities[0];
1529
+ const positions = [...context.packable.positions];
1530
+ if (positions.length === 0) return context.previous;
1531
+ if (positions.length === 1) {
1532
+ const position = context.mouse;
1533
+ position && positions.push(position);
1534
+ }
1535
+ if (positions.length < 2) return context.previous;
1536
+ entity.position = new ConstantPositionProperty(positions[0]);
1537
+ const radius = Cartesian3.distance(positions[0], positions[1]);
1538
+ entity.ellipse.semiMinorAxis = new CallbackProperty(() => radius || 1, false);
1539
+ entity.ellipse.semiMajorAxis = entity.ellipse.semiMinorAxis;
1540
+ return { entities: [entity] };
1541
+ }
1542
+ });
1543
+
1544
+ //#endregion
1545
+ //#region scheme/Label.ts
1546
+ const PlotSchemeLabel = new PlotScheme({
1547
+ type: "Label",
1548
+ complete: (packable) => packable.positions.length >= 1,
1549
+ skeletons: [moved],
1550
+ initRender() {
1551
+ return { entities: [new Entity({ label: { text: "Label" } })] };
1552
+ },
1553
+ render(context) {
1554
+ const entity = context.previous.entities[0];
1555
+ const position = context.packable.positions[0] ?? context.mouse;
1556
+ entity.position = new CallbackPositionProperty(() => position, true);
1557
+ return { entities: [entity] };
1558
+ }
1559
+ });
1560
+
1561
+ //#endregion
1562
+ //#region scheme/Point.ts
1563
+ const PlotSchemePoint = new PlotScheme({
1564
+ type: "Point",
1565
+ complete: (packable) => packable.positions.length >= 1,
1566
+ skeletons: [moved],
1567
+ initRender() {
1568
+ return { entities: [new Entity({ point: {
1569
+ pixelSize: 10,
1570
+ color: Color.RED
1571
+ } })] };
1572
+ },
1573
+ render(context) {
1574
+ const entity = context.previous.entities[0];
1575
+ const position = context.packable.positions[0] ?? context.mouse;
1576
+ entity.position = new CallbackPositionProperty(() => position, true);
1577
+ return { entities: [entity] };
1578
+ }
1579
+ });
1580
+
1581
+ //#endregion
1582
+ //#region scheme/Polygon.ts
1583
+ const PlotSchemePolygon = new PlotScheme({
1584
+ type: "Polygon",
1585
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1395
1586
  skeletons: [
1587
+ moved,
1396
1588
  control,
1397
- interval,
1398
- moved
1589
+ interval
1399
1590
  ],
1400
- initEntites: () => [new Entity({
1401
- polyline: { material: Color.YELLOW.withAlpha(.5) },
1402
- polygon: { material: Color.YELLOW.withAlpha(.5) }
1403
- })],
1591
+ initRender: () => {
1592
+ return { entities: [new Entity({
1593
+ polyline: {},
1594
+ polygon: {}
1595
+ })] };
1596
+ },
1404
1597
  render(options) {
1405
1598
  const { mouse, packable } = options;
1406
- const entity = options.previous.entities?.[0] ?? new Entity({
1407
- polyline: { material: Color.YELLOW.withAlpha(.5) },
1408
- polygon: { material: Color.YELLOW.withAlpha(.5) }
1409
- });
1599
+ const entity = options.previous.entities[0];
1410
1600
  const positions = [...packable.positions ?? []];
1411
1601
  mouse && positions.push(mouse);
1412
1602
  if (positions.length === 2) {
@@ -1427,55 +1617,366 @@ const schemePolygon = new PlotScheme({
1427
1617
  });
1428
1618
 
1429
1619
  //#endregion
1430
- //#region scheme/polyline.ts
1431
- /**
1432
- * 内置的线段标绘方案
1433
- */
1434
- const schemePolyline = new PlotScheme({
1435
- type: "polyline",
1436
- allowManualComplete: (packable) => packable.positions.length >= 2,
1620
+ //#region scheme/PolygonArc.ts
1621
+ const PlotSchemePolygonArc = new PlotScheme({
1622
+ type: "PolygonArc",
1623
+ complete: (packable) => packable.positions.length >= 3,
1624
+ skeletons: [moved, control],
1625
+ initRender() {
1626
+ return { entities: [new Entity({ polygon: {} })] };
1627
+ },
1628
+ render(context) {
1629
+ const entity = context.previous.entities[0];
1630
+ const points = context.packable.positions;
1631
+ if (points.length < 3) context.mouse && points.push(context.mouse.clone());
1632
+ const coords = points.map((e) => toCoord(e));
1633
+ if (coords.length < 3) {
1634
+ entity.polygon.hierarchy = void 0;
1635
+ return context.previous;
1636
+ }
1637
+ const hierarchy = new PolygonHierarchy(arc(coords).map((item) => toCartesian3(item)));
1638
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1639
+ return { entities: [entity] };
1640
+ }
1641
+ });
1642
+
1643
+ //#endregion
1644
+ //#region scheme/PolygonArrowAttackDirection.ts
1645
+ const PlotSchemePolygonArrowAttackDirection = new PlotScheme({
1646
+ type: "PolygonArrowAttackDirection",
1647
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1437
1648
  skeletons: [
1649
+ moved,
1438
1650
  control,
1439
- intervalNonclosed,
1440
- moved
1651
+ intervalNonclosed
1441
1652
  ],
1442
- initEntites: () => [new Entity({ polyline: { width: 1 } })],
1443
- render(options) {
1444
- const { mouse, packable } = options;
1445
- const entity = options.previous.entities?.[0] ?? new Entity({ polyline: {} });
1446
- entity.polyline.positions = new CallbackProperty(() => {
1447
- const positions = [...packable.positions ?? []].concat(mouse ? [mouse] : []);
1448
- return positions.length >= 2 ? positions : [];
1449
- }, false);
1653
+ initRender() {
1654
+ return { entities: [new Entity({ polygon: {} })] };
1655
+ },
1656
+ render(context) {
1657
+ const entity = context.previous.entities[0];
1658
+ const points = context.packable.positions;
1659
+ context.mouse && points.push(context.mouse.clone());
1660
+ const coords = points.map((e) => toCoord(e));
1661
+ if (coords.length < 3) {
1662
+ entity.polygon.hierarchy = void 0;
1663
+ return context.previous;
1664
+ }
1665
+ const hierarchy = new PolygonHierarchy(arrowAttackDirection(coords).map((item) => toCartesian3(item)));
1666
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1450
1667
  return { entities: [entity] };
1451
1668
  }
1452
1669
  });
1453
1670
 
1454
1671
  //#endregion
1455
- //#region scheme/rectangle.ts
1456
- /**
1457
- * 内置的多边形标绘方案
1458
- */
1459
- const schemeRectangle = new PlotScheme({
1460
- type: "rectangle",
1672
+ //#region scheme/PolygonArrowAttackDirectionTailed.ts
1673
+ const PlotSchemePolygonArrowAttackDirectionTailed = new PlotScheme({
1674
+ type: "PolygonArrowAttackDirectionTailed",
1675
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1676
+ skeletons: [
1677
+ moved,
1678
+ control,
1679
+ intervalNonclosed
1680
+ ],
1681
+ initRender() {
1682
+ return { entities: [new Entity({ polygon: {} })] };
1683
+ },
1684
+ render(context) {
1685
+ const entity = context.previous.entities[0];
1686
+ const points = context.packable.positions;
1687
+ context.mouse && points.push(context.mouse.clone());
1688
+ const coords = points.map((e) => toCoord(e));
1689
+ if (coords.length < 3) {
1690
+ entity.polygon.hierarchy = void 0;
1691
+ return context.previous;
1692
+ }
1693
+ const hierarchy = new PolygonHierarchy(arrowAttackDirectionTailed(coords).map((item) => toCartesian3(item)));
1694
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1695
+ return { entities: [entity] };
1696
+ }
1697
+ });
1698
+
1699
+ //#endregion
1700
+ //#region scheme/PolygonArrowClamped.ts
1701
+ const PlotSchemePolygonArrowClamped = new PlotScheme({
1702
+ type: "PolygonArrowClamped",
1703
+ complete: (packable) => packable.positions.length >= 5,
1704
+ skeletons: [moved, control],
1705
+ initRender() {
1706
+ return { entities: [new Entity({ polygon: {} })] };
1707
+ },
1708
+ render(context) {
1709
+ const entity = context.previous.entities[0];
1710
+ const points = context.packable.positions;
1711
+ if (points.length < 5) {
1712
+ const mouse = context.mouse;
1713
+ mouse && points.push(mouse.clone());
1714
+ }
1715
+ const coords = points.map((e) => toCoord(e));
1716
+ if (coords.length >= 3) {
1717
+ const hierarchy = new PolygonHierarchy(arrowClamped(coords).map((item) => toCartesian3(item)));
1718
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1719
+ } else entity.polygon.hierarchy = void 0;
1720
+ return { entities: [entity] };
1721
+ }
1722
+ });
1723
+
1724
+ //#endregion
1725
+ //#region scheme/PolygonArrowStraight.ts
1726
+ const PlotSchemePolygonArrowStraight = new PlotScheme({
1727
+ type: "PolygonArrowStraight",
1461
1728
  complete: (packable) => packable.positions.length >= 2,
1729
+ skeletons: [moved, control],
1730
+ initRender() {
1731
+ return { entities: [new Entity({ polygon: {} })] };
1732
+ },
1733
+ render(context) {
1734
+ const entity = context.previous.entities[0];
1735
+ const points = context.packable.positions;
1736
+ if (points.length < 2) {
1737
+ const mouse = context.mouse;
1738
+ mouse && points.push(mouse.clone());
1739
+ }
1740
+ const coords = points.map((e) => toCoord(e));
1741
+ if (coords.length >= 2) {
1742
+ const hierarchy = new PolygonHierarchy(arrowStraight(coords).map((item) => toCartesian3(item)));
1743
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1744
+ } else entity.polygon.hierarchy = void 0;
1745
+ return { entities: [entity] };
1746
+ }
1747
+ });
1748
+
1749
+ //#endregion
1750
+ //#region scheme/PolygonArrowStraightSharp.ts
1751
+ const PlotSchemePolygonArrowStraightSharp = new PlotScheme({
1752
+ type: "PolygonArrowStraightSharp",
1753
+ complete: (packable) => packable.positions.length >= 2,
1754
+ skeletons: [moved, control],
1755
+ initRender() {
1756
+ return { entities: [new Entity({ polygon: {} })] };
1757
+ },
1758
+ render(context) {
1759
+ const entity = context.previous.entities[0];
1760
+ const points = context.packable.positions;
1761
+ if (points.length < 2) {
1762
+ const mouse = context.mouse;
1763
+ mouse && points.push(mouse.clone());
1764
+ }
1765
+ const coords = points.map((e) => toCoord(e));
1766
+ if (coords.length >= 2) {
1767
+ const hierarchy = new PolygonHierarchy(arrowStraightSharp(coords).map((item) => toCartesian3(item)));
1768
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1769
+ } else entity.polygon.hierarchy = void 0;
1770
+ return { entities: [entity] };
1771
+ }
1772
+ });
1773
+
1774
+ //#endregion
1775
+ //#region scheme/PolygonArrowUnitCombatOperation.ts
1776
+ const PlotSchemePolygonArrowUnitCombatOperation = new PlotScheme({
1777
+ type: "PolygonArrowUnitCombatOperation",
1778
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1462
1779
  skeletons: [
1780
+ moved,
1463
1781
  control,
1464
- interval,
1465
- moved
1782
+ intervalNonclosed
1466
1783
  ],
1467
- initEntites: () => [new Entity({ rectangle: { material: Color.YELLOW.withAlpha(.5) } })],
1468
- render(options) {
1469
- const { mouse, packable } = options;
1470
- const entity = options.previous.entities?.[0] ?? new Entity({ rectangle: { material: Color.YELLOW.withAlpha(.5) } });
1471
- const positions = [...packable.positions ?? []];
1472
- mouse && positions.push(mouse);
1473
- if (positions.length >= 2) entity.rectangle.coordinates = new CallbackProperty(() => Rectangle.fromCartesianArray(positions), false);
1474
- else entity.rectangle.coordinates = void 0;
1784
+ initRender() {
1785
+ return { entities: [new Entity({ polygon: {} })] };
1786
+ },
1787
+ render(context) {
1788
+ const entity = context.previous.entities[0];
1789
+ const points = context.packable.positions;
1790
+ context.mouse && points.push(context.mouse.clone());
1791
+ const coords = points.map((e) => toCoord(e));
1792
+ if (coords.length < 2) {
1793
+ entity.polygon.hierarchy = void 0;
1794
+ return context.previous;
1795
+ }
1796
+ const hierarchy = new PolygonHierarchy(arrowUnitCombatOperation(coords).map((item) => toCartesian3(item)));
1797
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1798
+ return { entities: [entity] };
1799
+ }
1800
+ });
1801
+
1802
+ //#endregion
1803
+ //#region scheme/PolygonArrowUnitCombatOperationTailed.ts
1804
+ const PlotSchemePolygonArrowUnitCombatOperationTailed = new PlotScheme({
1805
+ type: "PolygonArrowUnitCombatOperationTailed",
1806
+ allowManualComplete: (packable) => packable.positions.length >= 2,
1807
+ skeletons: [
1808
+ moved,
1809
+ control,
1810
+ interval
1811
+ ],
1812
+ initRender() {
1813
+ return { entities: [new Entity({ polygon: {} })] };
1814
+ },
1815
+ render(context) {
1816
+ const entity = context.previous.entities[0];
1817
+ const points = context.packable.positions;
1818
+ context.mouse && points.push(context.mouse.clone());
1819
+ const coords = points.map((e) => toCoord(e));
1820
+ if (coords.length < 2) {
1821
+ entity.polygon.hierarchy = void 0;
1822
+ return context.previous;
1823
+ }
1824
+ const hierarchy = new PolygonHierarchy(arrowUnitCombatOperationTailed(coords).map((item) => toCartesian3(item)));
1825
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1826
+ return { entities: [entity] };
1827
+ }
1828
+ });
1829
+
1830
+ //#endregion
1831
+ //#region scheme/PolygonAssemblingPlace.ts
1832
+ const PlotSchemePolygonAssemblingPlace = new PlotScheme({
1833
+ type: "PolygonAssemblingPlace",
1834
+ complete: (packable) => packable.positions.length >= 3,
1835
+ skeletons: [
1836
+ moved,
1837
+ control,
1838
+ interval
1839
+ ],
1840
+ initRender() {
1841
+ return { entities: [new Entity({ polygon: {} })] };
1842
+ },
1843
+ render(context) {
1844
+ const entity = context.previous.entities[0];
1845
+ const points = context.packable.positions;
1846
+ context.mouse && points.push(context.mouse.clone());
1847
+ const coords = points.map((e) => toCoord(e));
1848
+ if (coords.length < 2) {
1849
+ entity.polygon.hierarchy = void 0;
1850
+ return context.previous;
1851
+ }
1852
+ if (coords.length === 2) {
1853
+ const c0 = toCartographic(coords[0]);
1854
+ const c1 = toCartographic(coords[1]);
1855
+ const latitude = c0.latitude;
1856
+ const height = c0.height;
1857
+ const longitude = c1.longitude - (c0.longitude - c1.longitude);
1858
+ coords.push(toCoord(new Cartographic(longitude, latitude, height)));
1859
+ }
1860
+ const hierarchy = new PolygonHierarchy(assemblingPlace(coords).map((item) => toCartesian3(item)));
1861
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1862
+ return { entities: [entity] };
1863
+ }
1864
+ });
1865
+
1866
+ //#endregion
1867
+ //#region scheme/PolygonSmooth.ts
1868
+ const PlotSchemePolygonSmooth = new PlotScheme({
1869
+ type: "PolygonSmooth",
1870
+ allowManualComplete: (packable) => packable.positions.length >= 3,
1871
+ skeletons: [
1872
+ moved,
1873
+ control,
1874
+ intervalNonclosed
1875
+ ],
1876
+ initRender() {
1877
+ return { entities: [new Entity({ polygon: {} })] };
1878
+ },
1879
+ render(context) {
1880
+ const entity = context.previous.entities[0];
1881
+ const positions = context.packable.positions;
1882
+ const mousePosition = context.mouse;
1883
+ mousePosition && positions.push(mousePosition.clone());
1884
+ if (positions.length <= 2) {
1885
+ entity.polygon.hierarchy = void 0;
1886
+ return context.previous;
1887
+ }
1888
+ const wgs84s = positions.map((e) => toCoord(e));
1889
+ wgs84s.push(wgs84s[0]);
1890
+ const { features } = turf.polygonSmooth(turf.polygon([wgs84s]), { iterations: 3 });
1891
+ const hierarchy = new PolygonHierarchy(features[0].geometry.coordinates[0].map((item) => toCartesian3(item)).filter((e) => !!e));
1892
+ entity.polygon.hierarchy = new CallbackProperty(() => hierarchy, false);
1893
+ return { entities: [entity] };
1894
+ }
1895
+ });
1896
+
1897
+ //#endregion
1898
+ //#region scheme/Polyline.ts
1899
+ const PlotSchemePolyline = new PlotScheme({
1900
+ type: "Polyline",
1901
+ allowManualComplete: (packable) => packable.positions.length > 1,
1902
+ skeletons: [
1903
+ moved,
1904
+ control,
1905
+ intervalNonclosed
1906
+ ],
1907
+ initRender() {
1908
+ return { entities: [new Entity({ polyline: {
1909
+ material: Color.RED,
1910
+ width: 2
1911
+ } })] };
1912
+ },
1913
+ render(context) {
1914
+ const entity = context.previous.entities[0];
1915
+ const positions = [...context.packable.positions];
1916
+ const mouse = context.mouse;
1917
+ mouse && positions.push(mouse.clone());
1918
+ const cache = positions.length >= 2 ? positions : [];
1919
+ entity.polyline.positions = new CallbackProperty(() => cache, false);
1920
+ return { entities: [entity] };
1921
+ }
1922
+ });
1923
+
1924
+ //#endregion
1925
+ //#region scheme/PolylineCurve.ts
1926
+ const PlotSchemePolylineCurve = new PlotScheme({
1927
+ type: "PolylineCurve",
1928
+ allowManualComplete: (packable) => packable.positions.length > 1,
1929
+ skeletons: [
1930
+ moved,
1931
+ control,
1932
+ intervalNonclosed
1933
+ ],
1934
+ initRender() {
1935
+ return { entities: [new Entity({ polyline: {
1936
+ material: Color.RED,
1937
+ width: 2
1938
+ } })] };
1939
+ },
1940
+ render(context) {
1941
+ const entity = context.previous.entities[0];
1942
+ const positions = [...context.packable.positions];
1943
+ const mouse = context.mouse;
1944
+ mouse && positions.push(mouse.clone());
1945
+ if (positions.length < 2) {
1946
+ entity.polyline.positions = void 0;
1947
+ return context.previous;
1948
+ }
1949
+ const coords = positions.map((position) => toCoord(position));
1950
+ const { geometry: { coordinates } } = turf.bezierSpline(turf.lineString(coords));
1951
+ entity.polyline.positions = new CallbackProperty(() => coordinates.map(toCartesian3), false);
1952
+ return { entities: [entity] };
1953
+ }
1954
+ });
1955
+
1956
+ //#endregion
1957
+ //#region scheme/Rectangle.ts
1958
+ const PlotSchemeRectangle = new PlotScheme({
1959
+ type: "Rectangle",
1960
+ complete: (packable) => packable.positions.length >= 2,
1961
+ skeletons: [moved, control],
1962
+ initRender() {
1963
+ return { entities: [new Entity({ rectangle: {} })] };
1964
+ },
1965
+ render(context) {
1966
+ const entity = context.previous.entities[0];
1967
+ const positions = [...context.packable.positions];
1968
+ const mouse = context.mouse;
1969
+ mouse && positions.push(mouse.clone());
1970
+ if (positions.length < 2) {
1971
+ entity.rectangle.coordinates = void 0;
1972
+ return context.previous;
1973
+ }
1974
+ const coordinates = Rectangle.fromCartesianArray(positions ?? []);
1975
+ entity.rectangle.coordinates = new CallbackProperty(() => coordinates, false);
1475
1976
  return { entities: [entity] };
1476
1977
  }
1477
1978
  });
1478
1979
 
1479
1980
  //#endregion
1480
- export { PlotAction, PlotFeature, PlotScheme, PlotSkeletonEntity, SampledPlotProperty, SampledPlotStrategy, control, interval, intervalNonclosed, moved, schemeBillboard, schemeLabel, schemeMeasureArea, schemePolygon, schemePolyline, schemeRectangle, usePlot };
1981
+ export { PlotAction, PlotFeature, PlotScheme, PlotSchemeBillboard, PlotSchemeBillboardPinBuilder, PlotSchemeCylinder, PlotSchemeEllipse, PlotSchemeLabel, PlotSchemePoint, PlotSchemePolygon, PlotSchemePolygonArc, PlotSchemePolygonArrowAttackDirection, PlotSchemePolygonArrowAttackDirectionTailed, PlotSchemePolygonArrowClamped, PlotSchemePolygonArrowStraight, PlotSchemePolygonArrowStraightSharp, PlotSchemePolygonArrowUnitCombatOperation, PlotSchemePolygonArrowUnitCombatOperationTailed, PlotSchemePolygonAssemblingPlace, PlotSchemePolygonSmooth, PlotSchemePolyline, PlotSchemePolylineCurve, PlotSchemeRectangle, PlotSkeletonEntity, SampledPlotProperty, SampledPlotStrategy, control, interval, intervalNonclosed, moved, schemeMeasureArea, schemeMeasureDistance, usePlot };
1481
1982
  //# sourceMappingURL=index.mjs.map