@vesium/plot 1.0.1-beta.52 → 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,11 +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"));
28
- const __turf_turf = __toESM(require("@turf/turf"));
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);
29
36
 
30
37
  //#region usePlot/PlotScheme.ts
31
38
  var PlotScheme = class PlotScheme {
@@ -204,16 +211,13 @@ var SampledPlotProperty = class SampledPlotProperty {
204
211
  const end = this._times[this._times.length - 1];
205
212
  if (cesium.JulianDate.lessThan(time, start) || cesium.JulianDate.greaterThan(time, end)) switch (this.strategy) {
206
213
  case SampledPlotStrategy.STRICT: return;
207
- case SampledPlotStrategy.NEAR: {
214
+ case SampledPlotStrategy.NEAR:
208
215
  time = cesium.JulianDate.lessThan(time, this._times[0]) ? this._times[0].clone() : this._times[this._times.length - 1].clone();
209
216
  break;
210
- }
211
217
  case SampledPlotStrategy.CYCLE: {
212
218
  const startMS = cesium.JulianDate.toDate(this._times[0]).getTime();
213
- const endMS = cesium.JulianDate.toDate(this._times[this._times.length - 1]).getTime();
214
- const duration = endMS - startMS;
215
- const timeMS = cesium.JulianDate.toDate(time).getTime();
216
- 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;
217
221
  const dete = new Date(startMS + diff);
218
222
  time = cesium.JulianDate.fromDate(dete);
219
223
  break;
@@ -223,11 +227,10 @@ var SampledPlotProperty = class SampledPlotProperty {
223
227
  const nextIndex = Math.min(prevIndex, this._times.length - 1);
224
228
  const prevMs = cesium.JulianDate.toDate(this._times[prevIndex]).getTime();
225
229
  const nextMs = cesium.JulianDate.toDate(this._times[nextIndex]).getTime();
226
- const ms = cesium.JulianDate.toDate(time).getTime();
227
230
  return {
228
231
  prevIndex,
229
232
  nextIndex,
230
- proportion: (ms - prevMs) / (nextMs - prevMs) || 0
233
+ proportion: (cesium.JulianDate.toDate(time).getTime() - prevMs) / (nextMs - prevMs) || 0
231
234
  };
232
235
  }
233
236
  /**
@@ -319,8 +322,7 @@ var SampledPlotProperty = class SampledPlotProperty {
319
322
  if (index !== -1) {
320
323
  this._sampleds.splice(index, 1);
321
324
  this._derivatives.splice(index, 1);
322
- const removed = this._times.splice(index, 1);
323
- if (removed.length) {
325
+ if (this._times.splice(index, 1).length) {
324
326
  this._definitionChanged.raiseEvent(this);
325
327
  return true;
326
328
  }
@@ -550,19 +552,27 @@ function useRender(plots, current, getCurrentTime) {
550
552
  }
551
553
  });
552
554
  const update = async (plot) => {
553
- const reslut = await plot.scheme.render?.({
554
- packable: plot.sampled.getValue(getCurrentTime()),
555
- 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,
556
561
  defining: plot.defining,
557
562
  previous: {
558
563
  entities: plot.entities,
559
564
  primitives: plot.primitives,
560
565
  groundPrimitives: plot.groundPrimitives
566
+ },
567
+ getPositions() {
568
+ const points = packable.positions;
569
+ mouse && points.push(mouse);
570
+ return points;
561
571
  }
562
572
  });
563
- plot.entities = reslut?.entities ?? [];
564
- plot.primitives = reslut?.primitives ?? [];
565
- plot.groundPrimitives = reslut?.groundPrimitives ?? [];
573
+ plot.entities = result?.entities ?? [];
574
+ plot.primitives = result?.primitives ?? [];
575
+ plot.groundPrimitives = result?.groundPrimitives ?? [];
566
576
  };
567
577
  (0, vue.watch)(current, (plot, previous) => {
568
578
  previous && update(previous);
@@ -605,8 +615,7 @@ function useSampled(current, getCurrentTime) {
605
615
  packable.value.positions ??= [];
606
616
  packable.value.positions.push(position);
607
617
  sampled.setSample(packable.value);
608
- const completed = scheme.complete?.(packable.value);
609
- completed && PlotFeature.setDefining(current.value, false);
618
+ scheme.complete?.(packable.value) && PlotFeature.setDefining(current.value, false);
610
619
  });
611
620
  (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK, async (ctx) => {
612
621
  if (!current.value || !packable.value) return;
@@ -615,10 +624,8 @@ function useSampled(current, getCurrentTime) {
615
624
  doubleClicking.value = false;
616
625
  const { scheme, defining } = current.value;
617
626
  if (!defining) return;
618
- const position = (0, vesium.canvasCoordToCartesian)(ctx.position, viewer.value.scene);
619
- if (!position) return;
620
- const completed = scheme.allowManualComplete?.(packable.value);
621
- 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);
622
629
  });
623
630
  (0, vesium.useScreenSpaceEventHandler)(cesium.ScreenSpaceEventType.RIGHT_CLICK, async () => {
624
631
  if (!current.value || !packable.value) return;
@@ -668,13 +675,11 @@ function useSkeleton(plots, current, getCurrentTime) {
668
675
  const packable = plot.sampled.getValue(getCurrentTime());
669
676
  const defining = plot.defining;
670
677
  const active = current.value === plot;
671
- const skeletons = plot.scheme.skeletons;
672
- skeletons.forEach((skeleton) => {
673
- const disabled = (0, vesium.isFunction)(skeleton.disabled) ? skeleton.disabled({
678
+ plot.scheme.skeletons.forEach((skeleton) => {
679
+ if ((0, vesium.isFunction)(skeleton.disabled) ? skeleton.disabled({
674
680
  active,
675
681
  defining
676
- }) : skeleton.disabled;
677
- if (disabled) return;
682
+ }) : skeleton.disabled) return;
678
683
  const positions = skeleton.format?.(packable) ?? packable?.positions ?? [];
679
684
  positions.forEach((position, index) => {
680
685
  let entity = oldEntities.find((item) => item.index === index && item.skeleton === skeleton);
@@ -701,9 +706,9 @@ function useSkeleton(plots, current, getCurrentTime) {
701
706
  }
702
707
  plot.skeletons = entities;
703
708
  };
704
- const { addGraphicEvent } = (0, vesium.useGraphicEvent)();
709
+ const graphicEvent = (0, vesium.useGraphicEvent)();
705
710
  (0, vue.watchEffect)((onCleanup) => {
706
- const remove = addGraphicEvent("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
711
+ onCleanup(graphicEvent.add("global", "DRAG", ({ event, pick, dragging, lockCamera }) => {
707
712
  if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
708
713
  const entity = pick.id;
709
714
  const plot = entity.plot;
@@ -736,8 +741,7 @@ function useSkeleton(plots, current, getCurrentTime) {
736
741
  return (0, vesium.isFunction)(skeleton?.dragCursor) ? skeleton.dragCursor(pick) : (0, vue.toValue)(skeleton?.dragCursor);
737
742
  }
738
743
  }
739
- });
740
- onCleanup(remove);
744
+ }));
741
745
  });
742
746
  (0, __vueuse_core.onKeyStroke)((keyEvent) => {
743
747
  if (activeEntity.value) {
@@ -756,16 +760,13 @@ function useSkeleton(plots, current, getCurrentTime) {
756
760
  }
757
761
  });
758
762
  (0, vue.watchEffect)((onCleanup) => {
759
- const remove = addGraphicEvent("global", "HOVER", ({ hovering, pick }) => {
760
- if (hovering && pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
761
- const entity = pick.id;
762
- hoverEntity.value = entity;
763
- } else hoverEntity.value = void 0;
764
- });
765
- 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
+ }));
766
767
  });
767
768
  (0, vue.watchEffect)((onCleanup) => {
768
- const remove = addGraphicEvent("global", "LEFT_CLICK", ({ event, pick }) => {
769
+ onCleanup(graphicEvent.add("global", "LEFT_CLICK", ({ event, pick }) => {
769
770
  if (pick.id instanceof PlotSkeletonEntity && entityScope.scope.has(pick.id)) {
770
771
  const entity = pick.id;
771
772
  activeEntity.value = entity;
@@ -783,8 +784,7 @@ function useSkeleton(plots, current, getCurrentTime) {
783
784
  event
784
785
  });
785
786
  } else activeEntity.value = void 0;
786
- });
787
- onCleanup(remove);
787
+ }));
788
788
  });
789
789
  (0, __vueuse_core.watchArray)(plots, (value, oldValue, added, removed = []) => {
790
790
  added.forEach((plot) => update(plot));
@@ -849,8 +849,7 @@ function usePlot(options) {
849
849
  if (previous) {
850
850
  if (previous.defining) {
851
851
  const packable$1 = previous.sampled.getValue(getCurrentTime());
852
- const completed = previous.scheme.allowManualComplete?.(packable$1);
853
- if (completed) {
852
+ if (previous.scheme.allowManualComplete?.(packable$1)) {
854
853
  PlotFeature.setDefining(previous, false);
855
854
  operateResolve?.(previous);
856
855
  } else collection.delete(previous);
@@ -934,8 +933,7 @@ function control() {
934
933
  const newHeading = (viewer.camera.heading + headingAdjust) % (2 * Math.PI);
935
934
  const positions = [...packable.positions ?? []];
936
935
  const cartographic = (0, vesium.toCartographic)(positions[index]);
937
- const r = height / 1e5;
938
- const distance$1 = r * Math.PI / 180 / 1e3;
936
+ const distance$1 = height / 1e5 * Math.PI / 180 / 1e3;
939
937
  cartographic.latitude += distance$1 * Math.cos(newHeading);
940
938
  cartographic.longitude += distance$1 * Math.sin(newHeading);
941
939
  positions[index] = (0, vesium.toCartesian3)(cartographic);
@@ -946,16 +944,15 @@ function control() {
946
944
  });
947
945
  },
948
946
  render: ({ position, action }) => {
949
- const colors = {
950
- [PlotAction.IDLE]: cesium.Color.BLUE.withAlpha(.4),
951
- [PlotAction.HOVER]: cesium.Color.BLUE.withAlpha(.6),
952
- [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
953
- };
954
947
  return {
955
948
  position,
956
949
  point: {
957
950
  pixelSize: 8,
958
- 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],
959
956
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
960
957
  outlineWidth: 1,
961
958
  outlineColor: cesium.Color.WHITE.withAlpha(.4)
@@ -1002,16 +999,15 @@ function interval() {
1002
999
  },
1003
1000
  render: ({ position, action, active }) => {
1004
1001
  if (!active) return;
1005
- const colors = {
1006
- [PlotAction.IDLE]: cesium.Color.GREEN.withAlpha(.4),
1007
- [PlotAction.HOVER]: cesium.Color.GREEN.withAlpha(.6),
1008
- [PlotAction.ACTIVE]: cesium.Color.GREEN.withAlpha(1)
1009
- };
1010
1002
  return {
1011
1003
  position,
1012
1004
  point: {
1013
1005
  pixelSize: 6,
1014
- 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],
1015
1011
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
1016
1012
  outlineWidth: 1,
1017
1013
  outlineColor: cesium.Color.WHITE.withAlpha(.4)
@@ -1056,16 +1052,15 @@ function intervalNonclosed() {
1056
1052
  });
1057
1053
  },
1058
1054
  render: ({ position, action }) => {
1059
- const colors = {
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
- };
1064
1055
  return {
1065
1056
  position,
1066
1057
  point: {
1067
1058
  pixelSize: 6,
1068
- 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],
1069
1064
  disableDepthTestDistance: Number.POSITIVE_INFINITY,
1070
1065
  outlineWidth: 1,
1071
1066
  outlineColor: cesium.Color.WHITE.withAlpha(.4)
@@ -1090,10 +1085,7 @@ function moved() {
1090
1085
  const positions = packable.positions ?? [];
1091
1086
  if (positions.length === 0) return [];
1092
1087
  else if (positions.length === 1) return [positions[0]];
1093
- else {
1094
- const center = cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions));
1095
- return [(0, vesium.toCartesian3)(center)];
1096
- }
1088
+ else return [(0, vesium.toCartesian3)(cesium.Rectangle.center(cesium.Rectangle.fromCartesianArray(positions)))];
1097
1089
  },
1098
1090
  onDrag({ viewer, sampled, packable, event, lockCamera, dragging }) {
1099
1091
  dragging && lockCamera();
@@ -1109,18 +1101,17 @@ function moved() {
1109
1101
  });
1110
1102
  },
1111
1103
  render: ({ position, action }) => {
1112
- const colors = {
1113
- [PlotAction.IDLE]: cesium.Color.WHITE,
1114
- [PlotAction.HOVER]: cesium.Color.WHITE,
1115
- [PlotAction.ACTIVE]: cesium.Color.AQUA.withAlpha(1)
1116
- };
1117
1104
  return {
1118
1105
  position,
1119
1106
  billboard: {
1120
1107
  image: svg,
1121
1108
  width: 20,
1122
1109
  height: 20,
1123
- 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],
1124
1115
  pixelOffset: new cesium.Cartesian3(0, -20),
1125
1116
  horizontalOrigin: cesium.HorizontalOrigin.CENTER,
1126
1117
  verticalOrigin: cesium.VerticalOrigin.BOTTOM,
@@ -1190,12 +1181,12 @@ async function clampToHeightMostDetailedByTilesetOrTerrain(options) {
1190
1181
  else resolve([]);
1191
1182
  });
1192
1183
  const [tilesetPositions, terrainPositions] = await Promise.all([tilesetPromise, terrainPromise]);
1193
- const resluts = [];
1184
+ const results = [];
1194
1185
  positions.forEach((item, index) => {
1195
1186
  const position = tilesetPositions[index] || terrainPositions[index] ? cesium.Ellipsoid.WGS84.cartographicToCartesian(terrainPositions[index]) : item.clone();
1196
- resluts.push(position);
1187
+ results.push(position);
1197
1188
  });
1198
- return resluts;
1189
+ return results;
1199
1190
  }
1200
1191
 
1201
1192
  //#endregion
@@ -1224,8 +1215,7 @@ async function triangleGrid(positions, options) {
1224
1215
  const bbox = cesium.Rectangle.fromCartesianArray(positions);
1225
1216
  const vertical = bbox.north - bbox.south;
1226
1217
  const horizontal = bbox.east - bbox.west;
1227
- const max = Math.max(horizontal, vertical);
1228
- const granularity = max / density;
1218
+ const granularity = Math.max(horizontal, vertical) / density;
1229
1219
  const polygonGeometry = cesium.PolygonGeometry.fromPositions({
1230
1220
  positions,
1231
1221
  vertexFormat: cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
@@ -1244,13 +1234,12 @@ async function triangleGrid(positions, options) {
1244
1234
  }
1245
1235
  if (clampToGround) {
1246
1236
  if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1247
- const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
1237
+ cartesian3List = await clampToHeightMostDetailedByTilesetOrTerrain({
1248
1238
  scene,
1249
1239
  terrainProvider,
1250
1240
  positions: cartesian3List,
1251
1241
  classificationType
1252
1242
  });
1253
- cartesian3List = detaileds;
1254
1243
  }
1255
1244
  const grid = [];
1256
1245
  while (cartesian3List?.length) {
@@ -1298,18 +1287,14 @@ async function area(positions, options) {
1298
1287
  if (positions.length < 2) throw new Error("positions.length must >= 2");
1299
1288
  const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
1300
1289
  if (density <= 0) throw new Error("options.density must > 0");
1301
- if (!clampToGround) {
1302
- const triangles$1 = tesselate(positions);
1303
- return triangles$1.reduce((count, current) => count += triangleArea(...current), 0);
1304
- }
1305
- const triangles = await triangleGrid(positions, {
1290
+ if (!clampToGround) return tesselate(positions).reduce((count, current) => count += triangleArea(...current), 0);
1291
+ return (await triangleGrid(positions, {
1306
1292
  density,
1307
1293
  scene,
1308
1294
  clampToGround,
1309
1295
  classificationType,
1310
1296
  terrainProvider
1311
- });
1312
- return triangles.reduce((count, current) => count += triangleArea(...current), 0);
1297
+ })).reduce((count, current) => count += triangleArea(...current), 0);
1313
1298
  }
1314
1299
 
1315
1300
  //#endregion
@@ -1327,13 +1312,12 @@ async function lerpArray(options) {
1327
1312
  result.push(end.clone());
1328
1313
  if (!clampToGround) return result;
1329
1314
  if (!scene) throw new Error("scene is required on `clampToGround == true`.");
1330
- const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
1315
+ return await clampToHeightMostDetailedByTilesetOrTerrain({
1331
1316
  scene,
1332
1317
  terrainProvider,
1333
1318
  positions: result,
1334
1319
  classificationType
1335
1320
  });
1336
- return detaileds;
1337
1321
  }
1338
1322
 
1339
1323
  //#endregion
@@ -1389,8 +1373,7 @@ async function distance(positions, options) {
1389
1373
  terrainProvider: _options.terrainProvider
1390
1374
  });
1391
1375
  });
1392
- const detaileds = await Promise.all(positionListPromises);
1393
- const stagePromises = detaileds.map(async (positions$1) => {
1376
+ const stagePromises = (await Promise.all(positionListPromises)).map(async (positions$1) => {
1394
1377
  const { count: count$1 } = await distance(positions$1);
1395
1378
  return count$1;
1396
1379
  });
@@ -1460,7 +1443,7 @@ const schemeMeasureDistance = new PlotScheme({
1460
1443
  } })] };
1461
1444
  },
1462
1445
  render(context) {
1463
- const entity = context.previous.entities[0];
1446
+ context.previous.entities[0];
1464
1447
  const { mouse, packable, previous } = context;
1465
1448
  const entities = previous.entities;
1466
1449
  const positions = [...packable.positions ?? []];
@@ -1662,929 +1645,6 @@ const PlotSchemePolygon = new PlotScheme({
1662
1645
  }
1663
1646
  });
1664
1647
 
1665
- //#endregion
1666
- //#region geom/helper.ts
1667
- const FITTING_COUNT = 100;
1668
- const HALF_PI = Math.PI / 2;
1669
- const ZERO_TOLERANCE = 1e-4;
1670
- const TWO_PI = Math.PI * 2;
1671
- /**
1672
- * 计算两个坐标之间的距离
1673
- * @param coord1
1674
- * @param coord2
1675
- */
1676
- function mathDistance(coord1, coord2) {
1677
- return Math.hypot(coord1[0] - coord2[0], coord1[1] - coord2[1]);
1678
- }
1679
- /**
1680
- * 计算点集合的总距离
1681
- * @param points
1682
- */
1683
- function wholeDistance(points) {
1684
- let distance$1 = 0;
1685
- if (points && Array.isArray(points) && points.length > 0) points.forEach((item, index) => {
1686
- if (index < points.length - 1) distance$1 += mathDistance(item, points[index + 1]);
1687
- });
1688
- return distance$1;
1689
- }
1690
- /**
1691
- * 获取基础长度
1692
- * @param points
1693
- */
1694
- const getBaseLength = (points) => wholeDistance(points) ** .99;
1695
- /**
1696
- * 求取两个坐标的中间坐标
1697
- * @param coord1
1698
- * @param coord2
1699
- */
1700
- function mid(coord1, coord2) {
1701
- return [(coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2];
1702
- }
1703
- /**
1704
- * 通过三个点确定一个圆的中心点
1705
- * @param coord1
1706
- * @param coord2
1707
- * @param coord3
1708
- */
1709
- function getCircleCenterOfThreeCoords(coord1, coord2, coord3) {
1710
- const coordA = [(coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2];
1711
- const coordB = [coordA[0] - coord1[1] + coord2[1], coordA[1] + coord1[0] - coord2[0]];
1712
- const coordC = [(coord1[0] + coord3[0]) / 2, (coord1[1] + coord3[1]) / 2];
1713
- const coordD = [coordC[0] - coord1[1] + coord3[1], coordC[1] + coord1[0] - coord3[0]];
1714
- return getIntersectCoord(coordA, coordB, coordC, coordD);
1715
- }
1716
- /**
1717
- * 获取交集的点
1718
- * @param coordA
1719
- * @param coordB
1720
- * @param coordC
1721
- * @param coordD
1722
- */
1723
- function getIntersectCoord(coordA, coordB, coordC, coordD) {
1724
- if (coordA[1] === coordB[1]) {
1725
- const f$1 = (coordD[0] - coordC[0]) / (coordD[1] - coordC[1]);
1726
- const x$1 = f$1 * (coordA[1] - coordC[1]) + coordC[0];
1727
- const y$1 = coordA[1];
1728
- return [x$1, y$1];
1729
- }
1730
- if (coordC[1] === coordD[1]) {
1731
- const e$1 = (coordB[0] - coordA[0]) / (coordB[1] - coordA[1]);
1732
- const x$1 = e$1 * (coordC[1] - coordA[1]) + coordA[0];
1733
- const y$1 = coordC[1];
1734
- return [x$1, y$1];
1735
- }
1736
- const e = (coordB[0] - coordA[0]) / (coordB[1] - coordA[1]);
1737
- const f = (coordD[0] - coordC[0]) / (coordD[1] - coordC[1]);
1738
- const y = (e * coordA[1] - coordA[0] - f * coordC[1] + coordC[0]) / (e - f);
1739
- const x = e * y - e * coordA[1] + coordA[0];
1740
- return [x, y];
1741
- }
1742
- /**
1743
- * 获取方位角(地平经度)
1744
- * @param startCoord
1745
- * @param endCoord
1746
- */
1747
- function getAzimuth(startCoord, endCoord) {
1748
- let azimuth = 0;
1749
- const angle = Math.asin(Math.abs(endCoord[1] - startCoord[1]) / mathDistance(startCoord, endCoord));
1750
- if (endCoord[1] >= startCoord[1] && endCoord[0] >= startCoord[0]) azimuth = angle + Math.PI;
1751
- else if (endCoord[1] >= startCoord[1] && endCoord[0] < startCoord[0]) azimuth = Math.PI * 2 - angle;
1752
- else if (endCoord[1] < startCoord[1] && endCoord[0] < startCoord[0]) azimuth = angle;
1753
- else if (endCoord[1] < startCoord[1] && endCoord[0] >= startCoord[0]) azimuth = Math.PI - angle;
1754
- return azimuth;
1755
- }
1756
- /**
1757
- * 通过三个点获取方位角
1758
- * @param coordA
1759
- * @param coordB
1760
- * @param coordC
1761
- */
1762
- function getAngleOfThreeCoords(coordA, coordB, coordC) {
1763
- const angle = getAzimuth(coordB, coordA) - getAzimuth(coordB, coordC);
1764
- return angle < 0 ? angle + Math.PI * 2 : angle;
1765
- }
1766
- /**
1767
- * 判断是否是顺时针
1768
- * @param coord1
1769
- * @param coord2
1770
- * @param coord3
1771
- */
1772
- function isClockWise(coord1, coord2, coord3) {
1773
- return (coord3[1] - coord1[1]) * (coord2[0] - coord1[0]) > (coord2[1] - coord1[1]) * (coord3[0] - coord1[0]);
1774
- }
1775
- /**
1776
- * 获取立方值
1777
- */
1778
- function getCubicValue(t, startCoord, coord1, coord2, endCoord) {
1779
- t = Math.max(Math.min(t, 1), 0);
1780
- const [tp, t2] = [1 - t, t * t];
1781
- const t3 = t2 * t;
1782
- const tp2 = tp * tp;
1783
- const tp3 = tp2 * tp;
1784
- const x = tp3 * startCoord[0] + 3 * tp2 * t * coord1[0] + 3 * tp * t2 * coord2[0] + t3 * endCoord[0];
1785
- const y = tp3 * startCoord[1] + 3 * tp2 * t * coord1[1] + 3 * tp * t2 * coord2[1] + t3 * endCoord[1];
1786
- return [x, y];
1787
- }
1788
- /**
1789
- * 根据起止点和旋转方向求取第三个点
1790
- * @param startCoord
1791
- * @param endCoord
1792
- * @param angle
1793
- * @param distance
1794
- * @param clockWise
1795
- */
1796
- function getThirdCoord(startCoord, endCoord, angle, distance$1, clockWise) {
1797
- const azimuth = getAzimuth(startCoord, endCoord);
1798
- const alpha = clockWise ? azimuth + angle : azimuth - angle;
1799
- const dx = distance$1 * Math.cos(alpha);
1800
- const dy = distance$1 * Math.sin(alpha);
1801
- return [endCoord[0] + dx, endCoord[1] + dy];
1802
- }
1803
- /**
1804
- * 插值弓形线段点
1805
- * @param center
1806
- * @param radius
1807
- * @param startAngle
1808
- * @param endAngle
1809
- */
1810
- function getArcCoords(center, radius, startAngle, endAngle) {
1811
- let [x, y, coords, angleDiff] = [
1812
- 0,
1813
- 0,
1814
- [],
1815
- endAngle - startAngle
1816
- ];
1817
- angleDiff = angleDiff < 0 ? angleDiff + Math.PI * 2 : angleDiff;
1818
- for (let i = 0; i <= 100; i++) {
1819
- const angle = startAngle + angleDiff * i / 100;
1820
- x = center[0] + radius * Math.cos(angle);
1821
- y = center[1] + radius * Math.sin(angle);
1822
- coords.push([x, y]);
1823
- }
1824
- return coords;
1825
- }
1826
- /**
1827
- * getBisectorNormals
1828
- * @param t
1829
- * @param coord1
1830
- * @param coord2
1831
- * @param coord3
1832
- */
1833
- function getBisectorNormals(t, coord1, coord2, coord3) {
1834
- const normal = getNormal(coord1, coord2, coord3);
1835
- let [bisectorNormalRight, bisectorNormalLeft, dt, x, y] = [
1836
- [0, 0],
1837
- [0, 0],
1838
- 0,
1839
- 0,
1840
- 0
1841
- ];
1842
- const dist = Math.hypot(normal[0], normal[1]);
1843
- const uX = normal[0] / dist;
1844
- const uY = normal[1] / dist;
1845
- const d1 = mathDistance(coord1, coord2);
1846
- const d2 = mathDistance(coord2, coord3);
1847
- if (dist > ZERO_TOLERANCE) if (isClockWise(coord1, coord2, coord3)) {
1848
- dt = t * d1;
1849
- x = coord2[0] - dt * uY;
1850
- y = coord2[1] + dt * uX;
1851
- bisectorNormalRight = [x, y];
1852
- dt = t * d2;
1853
- x = coord2[0] + dt * uY;
1854
- y = coord2[1] - dt * uX;
1855
- bisectorNormalLeft = [x, y];
1856
- } else {
1857
- dt = t * d1;
1858
- x = coord2[0] + dt * uY;
1859
- y = coord2[1] - dt * uX;
1860
- bisectorNormalRight = [x, y];
1861
- dt = t * d2;
1862
- x = coord2[0] - dt * uY;
1863
- y = coord2[1] + dt * uX;
1864
- bisectorNormalLeft = [x, y];
1865
- }
1866
- else {
1867
- x = coord2[0] + t * (coord1[0] - coord2[0]);
1868
- y = coord2[1] + t * (coord1[1] - coord2[1]);
1869
- bisectorNormalRight = [x, y];
1870
- x = coord2[0] + t * (coord3[0] - coord2[0]);
1871
- y = coord2[1] + t * (coord3[1] - coord2[1]);
1872
- bisectorNormalLeft = [x, y];
1873
- }
1874
- return [bisectorNormalRight, bisectorNormalLeft];
1875
- }
1876
- /**
1877
- * 获取默认三点的内切圆
1878
- * @param coord1
1879
- * @param coord2
1880
- * @param coord3
1881
- */
1882
- function getNormal(coord1, coord2, coord3) {
1883
- let dX1 = coord1[0] - coord2[0];
1884
- let dY1 = coord1[1] - coord2[1];
1885
- const d1 = Math.hypot(dX1, dY1);
1886
- dX1 /= d1;
1887
- dY1 /= d1;
1888
- let dX2 = coord3[0] - coord2[0];
1889
- let dY2 = coord3[1] - coord2[1];
1890
- const d2 = Math.hypot(dX2, dY2);
1891
- dX2 /= d2;
1892
- dY2 /= d2;
1893
- const uX = dX1 + dX2;
1894
- const uY = dY1 + dY2;
1895
- return [uX, uY];
1896
- }
1897
- /**
1898
- * 贝塞尔曲线
1899
- * @param points
1900
- */
1901
- function getBezierCoords(points) {
1902
- if (points.length <= 2) return points;
1903
- const bezierCoords = [];
1904
- const n = points.length - 1;
1905
- for (let t = 0; t <= 1; t += .01) {
1906
- let [x, y] = [0, 0];
1907
- for (let index = 0; index <= n; index++) {
1908
- const factor = getBinomialFactor(n, index);
1909
- const a = t ** index;
1910
- const b = (1 - t) ** (n - index);
1911
- x += factor * a * b * points[index][0];
1912
- y += factor * a * b * points[index][1];
1913
- }
1914
- bezierCoords.push([x, y]);
1915
- }
1916
- bezierCoords.push(points[n]);
1917
- return bezierCoords;
1918
- }
1919
- /**
1920
- * 获取阶乘数据
1921
- * @param n
1922
- */
1923
- function getFactorial(n) {
1924
- let result = 1;
1925
- switch (true) {
1926
- case n <= 1:
1927
- result = 1;
1928
- break;
1929
- case n === 2:
1930
- result = 2;
1931
- break;
1932
- case n === 3:
1933
- result = 6;
1934
- break;
1935
- case n === 24:
1936
- result = 24;
1937
- break;
1938
- case n === 5:
1939
- result = 120;
1940
- break;
1941
- default:
1942
- for (let i = 1; i <= n; i++) result *= i;
1943
- break;
1944
- }
1945
- return result;
1946
- }
1947
- /**
1948
- * 获取二项分布
1949
- * @param n
1950
- * @param index
1951
- */
1952
- function getBinomialFactor(n, index) {
1953
- return getFactorial(n) / (getFactorial(index) * getFactorial(n - index));
1954
- }
1955
- /**
1956
- * 插值线性点
1957
- * @param points
1958
- */
1959
- function getQBSplineCoords(points) {
1960
- if (points.length <= 2) return points;
1961
- const [n, bSplineCoords] = [2, []];
1962
- const m = points.length - n - 1;
1963
- bSplineCoords.push(points[0]);
1964
- for (let i = 0; i <= m; i++) for (let t = 0; t <= 1; t += .05) {
1965
- let [x, y] = [0, 0];
1966
- for (let k = 0; k <= n; k++) {
1967
- const factor = getQuadricBSplineFactor(k, t);
1968
- x += factor * points[i + k][0];
1969
- y += factor * points[i + k][1];
1970
- }
1971
- bSplineCoords.push([x, y]);
1972
- }
1973
- bSplineCoords.push(points.at(-1));
1974
- return bSplineCoords;
1975
- }
1976
- /**
1977
- * 得到二次线性因子
1978
- * @param k
1979
- * @param t
1980
- */
1981
- function getQuadricBSplineFactor(k, t) {
1982
- let res = 0;
1983
- if (k === 0) res = (t - 1) ** 2 / 2;
1984
- else if (k === 1) res = (-2 * t ** 2 + 2 * t + 1) / 2;
1985
- else if (k === 2) res = t ** 2 / 2;
1986
- return res;
1987
- }
1988
-
1989
- //#endregion
1990
- //#region geom/arc.ts
1991
- /**
1992
- * 标绘画弓形算法,继承线要素相关方法和属性
1993
- */
1994
- function arc(coords) {
1995
- const coordlength = coords.length;
1996
- if (coordlength <= 2) throw new Error("coords.length must >= 3");
1997
- else {
1998
- let [coord1, coord2, coord3, startAngle, endAngle] = [
1999
- coords[0],
2000
- coords[1],
2001
- coords[2],
2002
- 0,
2003
- 0
2004
- ];
2005
- const center = getCircleCenterOfThreeCoords(coord1, coord2, coord3);
2006
- const radius = mathDistance(coord1, center);
2007
- const angle1 = getAzimuth(coord1, center);
2008
- const angle2 = getAzimuth(coord2, center);
2009
- if (isClockWise(coord1, coord2, coord3)) {
2010
- startAngle = angle2;
2011
- endAngle = angle1;
2012
- } else {
2013
- startAngle = angle1;
2014
- endAngle = angle2;
2015
- }
2016
- return getArcCoords(center, radius, startAngle, endAngle);
2017
- }
2018
- }
2019
-
2020
- //#endregion
2021
- //#region geom/arrowAttackDirection.ts
2022
- /**
2023
- * 尖曲箭头
2024
- */
2025
- function arrowAttackDirection(coords, options = {}) {
2026
- const coordLength = coords.length;
2027
- if (coordLength < 3) throw new Error("coords.length must >= 3");
2028
- else {
2029
- let [tailLeft, tailRight] = [coords[0], coords[1]];
2030
- if (isClockWise(coords[0], coords[1], coords[2])) {
2031
- tailLeft = coords[1];
2032
- tailRight = coords[0];
2033
- }
2034
- const midTail = mid(tailLeft, tailRight);
2035
- const boneCoords = [midTail].concat(coords.slice(2));
2036
- const headCoords = getArrowHeadCoords(boneCoords, {
2037
- tailLeft,
2038
- tailRight,
2039
- ...options
2040
- });
2041
- if (headCoords && headCoords.length > 4) {
2042
- const [neckLeft, neckRight] = [headCoords[0], headCoords[4]];
2043
- const tailWidthFactor = mathDistance(tailLeft, tailRight) / getBaseLength(boneCoords);
2044
- const bodyCoords = getArrowBodyCoords(boneCoords, neckLeft, neckRight, tailWidthFactor);
2045
- const coordlength = bodyCoords.length;
2046
- let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength / 2));
2047
- leftCoords.push(neckLeft);
2048
- let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength / 2, coordlength));
2049
- rightCoords.push(neckRight);
2050
- leftCoords = getQBSplineCoords(leftCoords);
2051
- rightCoords = getQBSplineCoords(rightCoords);
2052
- return leftCoords.concat(headCoords, rightCoords.reverse());
2053
- } else return [];
2054
- }
2055
- }
2056
- /**
2057
- * 插值头部点
2058
- */
2059
- function getArrowHeadCoords(points, options) {
2060
- const { tailLeft, tailRight, headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, headTailFactor = .8 } = options;
2061
- let len = getBaseLength(points);
2062
- let headHeight = len * headHeightFactor;
2063
- const headCoord = points.at(-1);
2064
- len = mathDistance(headCoord, points.at(-2));
2065
- let tailWidth = 0;
2066
- if (tailLeft && tailRight) tailWidth = mathDistance(tailLeft, tailRight);
2067
- if (headHeight > tailWidth * headTailFactor) headHeight = tailWidth * headTailFactor;
2068
- const headWidth = headHeight * headWidthFactor;
2069
- const neckWidth = headHeight * neckWidthFactor;
2070
- headHeight = Math.min(headHeight, len);
2071
- const neckHeight = headHeight * neckHeightFactor;
2072
- const headEndCoord = getThirdCoord(points.at(-2), headCoord, 0, headHeight, true);
2073
- const neckEndCoord = getThirdCoord(points.at(-2), headCoord, 0, neckHeight, true);
2074
- const headLeft = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, false);
2075
- const headRight = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, true);
2076
- const neckLeft = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, false);
2077
- const neckRight = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, true);
2078
- return [
2079
- neckLeft,
2080
- headLeft,
2081
- headCoord,
2082
- headRight,
2083
- neckRight
2084
- ];
2085
- }
2086
- /**
2087
- * 插值面部分数据
2088
- * @param points
2089
- * @param neckLeft
2090
- * @param neckRight
2091
- * @param tailWidthFactor
2092
- */
2093
- function getArrowBodyCoords(points, neckLeft, neckRight, tailWidthFactor) {
2094
- const allLen = wholeDistance(points);
2095
- const len = getBaseLength(points);
2096
- const tailWidth = len * tailWidthFactor;
2097
- const neckWidth = mathDistance(neckLeft, neckRight);
2098
- const widthDif = (tailWidth - neckWidth) / 2;
2099
- let tempLen = 0;
2100
- const leftBodyCoords = [];
2101
- const rightBodyCoords = [];
2102
- for (let i = 1; i < points.length - 1; i++) {
2103
- const angle = getAngleOfThreeCoords(points[i - 1], points[i], points[i + 1]) / 2;
2104
- tempLen += mathDistance(points[i - 1], points[i]);
2105
- const w = (tailWidth / 2 - tempLen / allLen * widthDif) / Math.sin(angle);
2106
- const left = getThirdCoord(points[i - 1], points[i], Math.PI - angle, w, true);
2107
- const right = getThirdCoord(points[i - 1], points[i], angle, w, false);
2108
- leftBodyCoords.push(left);
2109
- rightBodyCoords.push(right);
2110
- }
2111
- return leftBodyCoords.concat(rightBodyCoords);
2112
- }
2113
-
2114
- //#endregion
2115
- //#region geom/arrowAttackDirectionTailed.ts
2116
- /**
2117
- * 燕尾尖曲箭头
2118
- */
2119
- function arrowAttackDirectionTailed(coords, options = {}) {
2120
- const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1, swallowTailFactor = 1 } = options;
2121
- const coordLength = coords.length;
2122
- if (coordLength < 3) throw new Error("coords.length must >= 3");
2123
- let [tailLeft, tailRight] = [coords[0], coords[1]];
2124
- if (isClockWise(coords[0], coords[1], coords[2])) {
2125
- tailLeft = coords[1];
2126
- tailRight = coords[0];
2127
- }
2128
- const midTail = mid(tailLeft, tailRight);
2129
- const boneCoords = [midTail].concat(coords.slice(2));
2130
- const headCoords = getArrowHeadCoords(boneCoords, {
2131
- tailLeft,
2132
- tailRight,
2133
- headHeightFactor,
2134
- headWidthFactor,
2135
- neckWidthFactor,
2136
- neckHeightFactor
2137
- });
2138
- if (headCoords && headCoords.length > 4) {
2139
- const [neckLeft, neckRight] = [headCoords[0], headCoords[4]];
2140
- const tailWidth = mathDistance(tailLeft, tailRight);
2141
- const allLen = getBaseLength(boneCoords);
2142
- const len = allLen * tailWidthFactor * swallowTailFactor;
2143
- const swallowTailCoord = getThirdCoord(boneCoords[1], boneCoords[0], 0, len, true);
2144
- const factor = tailWidth / allLen;
2145
- const bodyCoords = getArrowBodyCoords(boneCoords, neckLeft, neckRight, factor);
2146
- const coordlength = bodyCoords.length;
2147
- let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength / 2));
2148
- leftCoords.push(neckLeft);
2149
- let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength / 2, coordlength));
2150
- rightCoords.push(neckRight);
2151
- leftCoords = getQBSplineCoords(leftCoords);
2152
- rightCoords = getQBSplineCoords(rightCoords);
2153
- return leftCoords.concat(headCoords, rightCoords.reverse(), [swallowTailCoord, leftCoords[0]]);
2154
- } else return [];
2155
- }
2156
-
2157
- //#endregion
2158
- //#region geom/arrowClamped.ts
2159
- /**
2160
- * 钳击箭头 有效点位长度3,4,5
2161
- */
2162
- function arrowClamped(coords) {
2163
- const options = {
2164
- headHeightFactor: .25,
2165
- headWidthFactor: .3,
2166
- neckHeightFactor: .85,
2167
- neckWidthFactor: .15
2168
- };
2169
- if (coords.length < 3) throw new Error(`coords.length must >= 3`);
2170
- const [coord1, coord2, coord3] = coords;
2171
- let tempCoord4, connCoord;
2172
- if (coords.length === 3) {
2173
- tempCoord4 = getTempCoord4(coord1, coord2, coord3);
2174
- connCoord = mid(coord1, coord2);
2175
- } else if (coords.length === 4) {
2176
- tempCoord4 = coords[3];
2177
- connCoord = mid(coord1, coord2);
2178
- } else {
2179
- tempCoord4 = coords[3];
2180
- connCoord = coords[4];
2181
- }
2182
- let leftArrowCoords;
2183
- let rightArrowCoords;
2184
- if (isClockWise(coord1, coord2, coord3)) {
2185
- leftArrowCoords = getArrowCoords(coord1, connCoord, tempCoord4, false, options);
2186
- rightArrowCoords = getArrowCoords(connCoord, coord2, coord3, true, options);
2187
- } else {
2188
- leftArrowCoords = getArrowCoords(coord2, connCoord, coord3, false, options);
2189
- rightArrowCoords = getArrowCoords(connCoord, coord1, tempCoord4, true, options);
2190
- }
2191
- const m = leftArrowCoords.length;
2192
- const t = (m - 5) / 2;
2193
- const llBodyCoords = leftArrowCoords.slice(0, t);
2194
- const lArrowCoords = leftArrowCoords.slice(t, t + 5);
2195
- let lrBodyCoords = leftArrowCoords.slice(t + 5, m);
2196
- let rlBodyCoords = rightArrowCoords.slice(0, t);
2197
- const rArrowCoords = rightArrowCoords.slice(t, t + 5);
2198
- const rrBodyCoords = rightArrowCoords.slice(t + 5, m);
2199
- rlBodyCoords = getBezierCoords(rlBodyCoords);
2200
- const bodyCoords = getBezierCoords(rrBodyCoords.concat(llBodyCoords.slice(1)));
2201
- lrBodyCoords = getBezierCoords(lrBodyCoords);
2202
- return rlBodyCoords.concat(rArrowCoords, bodyCoords, lArrowCoords, lrBodyCoords);
2203
- }
2204
- /**
2205
- * 插值箭形上的点
2206
- * @param coord1 - Wgs84坐标
2207
- * @param coord2 - Wgs84坐标
2208
- * @param coord3 - Wgs84坐标
2209
- * @param clockWise - 是否顺时针
2210
- */
2211
- function getArrowCoords(coord1, coord2, coord3, clockWise, options) {
2212
- const midCoord = mid(coord1, coord2);
2213
- const len = mathDistance(midCoord, coord3);
2214
- let midCoord1 = getThirdCoord(coord3, midCoord, 0, len * .3, true);
2215
- let midCoord2 = getThirdCoord(coord3, midCoord, 0, len * .5, true);
2216
- midCoord1 = getThirdCoord(midCoord, midCoord1, HALF_PI, len / 5, clockWise);
2217
- midCoord2 = getThirdCoord(midCoord, midCoord2, HALF_PI, len / 4, clockWise);
2218
- const coords = [
2219
- midCoord,
2220
- midCoord1,
2221
- midCoord2,
2222
- coord3
2223
- ];
2224
- const arrowCoords = getArrowHeadCoords$1(coords, options);
2225
- if (arrowCoords && Array.isArray(arrowCoords) && arrowCoords.length > 0) {
2226
- const [neckLeftCoord, neckRightCoord] = [arrowCoords[0], arrowCoords[4]];
2227
- const tailWidthFactor = mathDistance(coord1, coord2) / getBaseLength(coords) / 2;
2228
- const bodyCoords = getArrowBodyCoords$1(coords, neckLeftCoord, neckRightCoord, tailWidthFactor);
2229
- const n = bodyCoords.length;
2230
- let lCoords = bodyCoords.slice(0, n / 2);
2231
- let rCoords = bodyCoords.slice(n / 2, n);
2232
- lCoords.push(neckLeftCoord);
2233
- rCoords.push(neckRightCoord);
2234
- lCoords = lCoords.reverse();
2235
- lCoords.push(coord2);
2236
- rCoords = rCoords.reverse();
2237
- rCoords.push(coord1);
2238
- return lCoords.reverse().concat(arrowCoords, rCoords);
2239
- } else throw new Error("插值出错");
2240
- }
2241
- /**
2242
- * 插值头部点
2243
- * @param coords
2244
- */
2245
- function getArrowHeadCoords$1(coords, options) {
2246
- const { headHeightFactor, headWidthFactor, neckWidthFactor, neckHeightFactor } = options;
2247
- const len = getBaseLength(coords);
2248
- const headHeight = len * headHeightFactor;
2249
- const headCoord = coords.at(-1);
2250
- const headWidth = headHeight * headWidthFactor;
2251
- const neckWidth = headHeight * neckWidthFactor;
2252
- const neckHeight = headHeight * neckHeightFactor;
2253
- const headEndCoord = getThirdCoord(coords.at(-2), headCoord, 0, headHeight, true);
2254
- const neckEndCoord = getThirdCoord(coords.at(-2), headCoord, 0, neckHeight, true);
2255
- const headLeft = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, false);
2256
- const headRight = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, true);
2257
- const neckLeft = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, false);
2258
- const neckRight = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, true);
2259
- return [
2260
- neckLeft,
2261
- headLeft,
2262
- headCoord,
2263
- headRight,
2264
- neckRight
2265
- ];
2266
- }
2267
- /**
2268
- * 插值面部分数据
2269
- * @param coords
2270
- * @param neckLeft
2271
- * @param neckRight
2272
- * @param tailWidthFactor
2273
- */
2274
- function getArrowBodyCoords$1(coords, neckLeft, neckRight, tailWidthFactor) {
2275
- const allLen = wholeDistance(coords);
2276
- const len = getBaseLength(coords);
2277
- const tailWidth = len * tailWidthFactor;
2278
- const neckWidth = mathDistance(neckLeft, neckRight);
2279
- const widthDif = (tailWidth - neckWidth) / 2;
2280
- let tempLen = 0;
2281
- const leftBodyCoords = [];
2282
- const rightBodyCoords = [];
2283
- for (let i = 1; i < coords.length - 1; i++) {
2284
- const angle = getAngleOfThreeCoords(coords[i - 1], coords[i], coords[i + 1]) / 2;
2285
- tempLen += mathDistance(coords[i - 1], coords[i]);
2286
- const w = (tailWidth / 2 - tempLen / allLen * widthDif) / Math.sin(angle);
2287
- const left = getThirdCoord(coords[i - 1], coords[i], Math.PI - angle, w, true);
2288
- const right = getThirdCoord(coords[i - 1], coords[i], angle, w, false);
2289
- leftBodyCoords.push(left);
2290
- rightBodyCoords.push(right);
2291
- }
2292
- return leftBodyCoords.concat(rightBodyCoords);
2293
- }
2294
- /**
2295
- * 获取对称点
2296
- * @param lineCoord1
2297
- * @param lineCoord2
2298
- * @param coord
2299
- */
2300
- function getTempCoord4(lineCoord1, lineCoord2, coord) {
2301
- const midCoord = mid(lineCoord1, lineCoord2);
2302
- const len = mathDistance(midCoord, coord);
2303
- const angle = getAngleOfThreeCoords(lineCoord1, midCoord, coord);
2304
- if (angle < HALF_PI) {
2305
- const distance1 = len * Math.sin(angle);
2306
- const distance2 = len * Math.cos(angle);
2307
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, false);
2308
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, true);
2309
- } else if (angle >= HALF_PI && angle < Math.PI) {
2310
- const distance1 = len * Math.sin(Math.PI - angle);
2311
- const distance2 = len * Math.cos(Math.PI - angle);
2312
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, false);
2313
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, false);
2314
- } else if (angle >= Math.PI && angle < Math.PI * 1.5) {
2315
- const distance1 = len * Math.sin(angle - Math.PI);
2316
- const distance2 = len * Math.cos(angle - Math.PI);
2317
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true);
2318
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, true);
2319
- } else {
2320
- const distance1 = len * Math.sin(Math.PI * 2 - angle);
2321
- const distance2 = len * Math.cos(Math.PI * 2 - angle);
2322
- const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true);
2323
- return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, false);
2324
- }
2325
- }
2326
-
2327
- //#endregion
2328
- //#region geom/arrowStraightSharp.ts
2329
- /**
2330
- * 尖箭头
2331
- *
2332
- */
2333
- function arrowStraightSharp(coords, options = {}) {
2334
- const { tailWidthFactor = .1, neckWidthFactor = .2, headWidthFactor = .25, headAngle = Math.PI / 8.5, neckAngle = Math.PI / 13 } = options;
2335
- const coordlength = coords.length;
2336
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2337
- const [coord1, coord2] = [coords[0], coords[1]];
2338
- const len = getBaseLength(coords);
2339
- const tailWidth = len * tailWidthFactor;
2340
- const neckWidth = len * neckWidthFactor;
2341
- const headWidth = len * headWidthFactor;
2342
- const tailLeft = getThirdCoord(coord2, coord1, HALF_PI, tailWidth, true);
2343
- const tailRight = getThirdCoord(coord2, coord1, HALF_PI, tailWidth, false);
2344
- const headLeft = getThirdCoord(coord1, coord2, headAngle, headWidth, false);
2345
- const headRight = getThirdCoord(coord1, coord2, headAngle, headWidth, true);
2346
- const neckLeft = getThirdCoord(coord1, coord2, neckAngle, neckWidth, false);
2347
- const neckRight = getThirdCoord(coord1, coord2, neckAngle, neckWidth, true);
2348
- const pList = [
2349
- tailLeft,
2350
- neckLeft,
2351
- headLeft,
2352
- coord2,
2353
- headRight,
2354
- neckRight,
2355
- tailRight
2356
- ];
2357
- return pList;
2358
- }
2359
-
2360
- //#endregion
2361
- //#region geom/arrowStraight.ts
2362
- /**
2363
- * 直箭头
2364
- */
2365
- function arrowStraight(coords) {
2366
- const tailWidthFactor = .05;
2367
- const neckWidthFactor = .1;
2368
- const headWidthFactor = .15;
2369
- const headAngle = Math.PI / 4;
2370
- const neckAngle = Math.PI * .17741;
2371
- return arrowStraightSharp(coords, {
2372
- tailWidthFactor,
2373
- neckWidthFactor,
2374
- headWidthFactor,
2375
- headAngle,
2376
- neckAngle
2377
- });
2378
- }
2379
-
2380
- //#endregion
2381
- //#region geom/arrowUnitCombatOperation.ts
2382
- /**
2383
- * 分队战斗行动(尖曲箭头)
2384
- */
2385
- function arrowUnitCombatOperation(coords, options = {}) {
2386
- const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1 } = options;
2387
- const coordlength = coords.length;
2388
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2389
- else {
2390
- const allLen = getBaseLength(coords);
2391
- const tailWidth = allLen * tailWidthFactor;
2392
- const tailLeft = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, false);
2393
- const tailRight = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, true);
2394
- const headCoords = getArrowHeadCoords(coords, {
2395
- tailLeft,
2396
- tailRight,
2397
- headHeightFactor,
2398
- headWidthFactor,
2399
- neckWidthFactor,
2400
- neckHeightFactor
2401
- });
2402
- if (headCoords && headCoords.length > 4) {
2403
- const neckLeft = headCoords[0];
2404
- const neckRight = headCoords[4];
2405
- const bodyCoords = getArrowBodyCoords(coords, neckLeft, neckRight, tailWidthFactor);
2406
- const coordlength$1 = bodyCoords.length;
2407
- let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength$1 / 2));
2408
- leftCoords.push(neckLeft);
2409
- let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength$1 / 2, coordlength$1));
2410
- rightCoords.push(neckRight);
2411
- leftCoords = getQBSplineCoords(leftCoords);
2412
- rightCoords = getQBSplineCoords(rightCoords);
2413
- return leftCoords.concat(headCoords, rightCoords.reverse());
2414
- } else return [];
2415
- }
2416
- }
2417
-
2418
- //#endregion
2419
- //#region geom/arrowUnitCombatOperationTailed.ts
2420
- /**
2421
- * 燕尾尖箭头
2422
- */
2423
- function arrowUnitCombatOperationTailed(coords, options = {}) {
2424
- const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1, swallowTailFactor = 1 } = options;
2425
- const coordlength = coords.length;
2426
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2427
- const allLen = getBaseLength(coords);
2428
- const tailWidth = allLen * tailWidthFactor;
2429
- const tailLeft = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, false);
2430
- const tailRight = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, true);
2431
- const len = tailWidth * swallowTailFactor;
2432
- const swallowTailCoord = getThirdCoord(coords[1], coords[0], 0, len, true);
2433
- const tailCoords = [
2434
- tailLeft,
2435
- swallowTailCoord,
2436
- tailRight
2437
- ];
2438
- const headCoords = getArrowHeadCoords(coords, {
2439
- tailLeft: tailCoords[0],
2440
- tailRight: tailCoords[2],
2441
- headHeightFactor,
2442
- headWidthFactor,
2443
- neckWidthFactor,
2444
- neckHeightFactor
2445
- });
2446
- if (headCoords && headCoords.length > 4) {
2447
- const neckLeft = headCoords[0];
2448
- const neckRight = headCoords[4];
2449
- const bodyCoords = getArrowBodyCoords(coords, neckLeft, neckRight, tailWidthFactor);
2450
- const coordlength$1 = bodyCoords.length;
2451
- let leftCoords = [tailCoords[0]].concat(bodyCoords.slice(0, coordlength$1 / 2));
2452
- leftCoords.push(neckLeft);
2453
- let rightCoords = [tailCoords[2]].concat(bodyCoords.slice(coordlength$1 / 2, coordlength$1));
2454
- rightCoords.push(neckRight);
2455
- leftCoords = getQBSplineCoords(leftCoords);
2456
- rightCoords = getQBSplineCoords(rightCoords);
2457
- return leftCoords.concat(headCoords, rightCoords.reverse(), [tailCoords[1], leftCoords[0]]);
2458
- }
2459
- return [];
2460
- }
2461
-
2462
- //#endregion
2463
- //#region geom/assemblingPlace.ts
2464
- /**
2465
- * 集结地
2466
- *
2467
- */
2468
- function assemblingPlace(coords) {
2469
- if (coords.length < 3) throw new Error(`coords.length must >= 3`);
2470
- const t = .4;
2471
- const midCoord = mid(coords[0], coords[2]);
2472
- coords.push(midCoord, coords[0], coords[1]);
2473
- let normals = [];
2474
- const pList = [];
2475
- for (let i = 0; i < coords.length - 2; i++) {
2476
- const coord1 = coords[i];
2477
- const coord2 = coords[i + 1];
2478
- const coord3 = coords[i + 2];
2479
- const normalCoords = getBisectorNormals(t, coord1, coord2, coord3);
2480
- normals = normals.concat(normalCoords);
2481
- }
2482
- const count = normals.length;
2483
- normals = [normals[count - 1]].concat(normals.slice(0, count - 1));
2484
- for (let i = 0; i < coords.length - 2; i++) {
2485
- const coord1 = coords[i];
2486
- const coord2 = coords[i + 1];
2487
- pList.push(coord1);
2488
- for (let t$1 = 0; t$1 <= FITTING_COUNT; t$1++) {
2489
- const coord = getCubicValue(t$1 / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
2490
- pList.push(coord);
2491
- }
2492
- pList.push(coord2);
2493
- }
2494
- return pList;
2495
- }
2496
-
2497
- //#endregion
2498
- //#region geom/flagCurve.ts
2499
- /**
2500
- * 曲线旗标
2501
- */
2502
- function flagCurve(coords) {
2503
- const coordlength = coords.length;
2504
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2505
- return calculatePonits(coords);
2506
- }
2507
- /**
2508
- * 插值点数据
2509
- * @param coords
2510
- */
2511
- function calculatePonits(coords) {
2512
- let components = [];
2513
- if (coords.length > 1) {
2514
- const startCoord = coords[0];
2515
- const endCoord = coords.at(-1);
2516
- const coord1 = startCoord;
2517
- const coord2 = [(endCoord[0] - startCoord[0]) / 4 + startCoord[0], (endCoord[1] - startCoord[1]) / 8 + startCoord[1]];
2518
- const coord3 = [(startCoord[0] + endCoord[0]) / 2, startCoord[1]];
2519
- const coord4 = [(endCoord[0] - startCoord[0]) * 3 / 4 + startCoord[0], -(endCoord[1] - startCoord[1]) / 8 + startCoord[1]];
2520
- const coord5 = [endCoord[0], startCoord[1]];
2521
- const coord6 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
2522
- const coord7 = [(endCoord[0] - startCoord[0]) * 3 / 4 + startCoord[0], (endCoord[1] - startCoord[1]) * 3 / 8 + startCoord[1]];
2523
- const coord8 = [(startCoord[0] + endCoord[0]) / 2, (startCoord[1] + endCoord[1]) / 2];
2524
- const coord9 = [(endCoord[0] - startCoord[0]) / 4 + startCoord[0], (endCoord[1] - startCoord[1]) * 5 / 8 + startCoord[1]];
2525
- const coord10 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
2526
- const coord11 = [startCoord[0], endCoord[1]];
2527
- const curve1 = getBezierCoords([
2528
- coord1,
2529
- coord2,
2530
- coord3,
2531
- coord4,
2532
- coord5
2533
- ]);
2534
- const curve2 = getBezierCoords([
2535
- coord6,
2536
- coord7,
2537
- coord8,
2538
- coord9,
2539
- coord10
2540
- ]);
2541
- components = curve1.concat(curve2);
2542
- components.push(coord11);
2543
- }
2544
- return components;
2545
- }
2546
-
2547
- //#endregion
2548
- //#region geom/flagRect.ts
2549
- /**
2550
- * 直角旗标(使用两个控制点直接创建直角旗标)
2551
- */
2552
- function flagRect(coords) {
2553
- if (coords.length < 2) throw new Error("coords.length must >= 2");
2554
- const [startCoord, endCoord] = coords;
2555
- const coord1 = [endCoord[0], startCoord[1]];
2556
- const coord2 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
2557
- const coord3 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
2558
- const coord4 = [startCoord[0], endCoord[1]];
2559
- return [
2560
- startCoord,
2561
- coord1,
2562
- coord2,
2563
- coord3,
2564
- coord4
2565
- ];
2566
- }
2567
-
2568
- //#endregion
2569
- //#region geom/flagTriangle.ts
2570
- /**
2571
- * 三角旗标(使用两个控制点直接创建三角旗标)
2572
- */
2573
- function flagTriangle(coords) {
2574
- const coordlength = coords.length;
2575
- if (coordlength < 2) throw new Error("coords.length must >= 2");
2576
- const [startCoord, endCoord] = coords;
2577
- const coord1 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
2578
- const coord2 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
2579
- const coord3 = [startCoord[0], endCoord[1]];
2580
- return [
2581
- startCoord,
2582
- coord1,
2583
- coord2,
2584
- coord3
2585
- ];
2586
- }
2587
-
2588
1648
  //#endregion
2589
1649
  //#region scheme/PolygonArc.ts
2590
1650
  const PlotSchemePolygonArc = new PlotScheme({
@@ -2603,8 +1663,7 @@ const PlotSchemePolygonArc = new PlotScheme({
2603
1663
  entity.polygon.hierarchy = void 0;
2604
1664
  return context.previous;
2605
1665
  }
2606
- const positions = arc(coords).map((item) => (0, vesium.toCartesian3)(item));
2607
- const hierarchy = new cesium.PolygonHierarchy(positions);
1666
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arc)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2608
1667
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2609
1668
  return { entities: [entity] };
2610
1669
  }
@@ -2632,8 +1691,7 @@ const PlotSchemePolygonArrowAttackDirection = new PlotScheme({
2632
1691
  entity.polygon.hierarchy = void 0;
2633
1692
  return context.previous;
2634
1693
  }
2635
- const positions = arrowAttackDirection(coords).map((item) => (0, vesium.toCartesian3)(item));
2636
- const hierarchy = new cesium.PolygonHierarchy(positions);
1694
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowAttackDirection)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2637
1695
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2638
1696
  return { entities: [entity] };
2639
1697
  }
@@ -2661,8 +1719,7 @@ const PlotSchemePolygonArrowAttackDirectionTailed = new PlotScheme({
2661
1719
  entity.polygon.hierarchy = void 0;
2662
1720
  return context.previous;
2663
1721
  }
2664
- const positions = arrowAttackDirectionTailed(coords).map((item) => (0, vesium.toCartesian3)(item));
2665
- const hierarchy = new cesium.PolygonHierarchy(positions);
1722
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowAttackDirectionTailed)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2666
1723
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2667
1724
  return { entities: [entity] };
2668
1725
  }
@@ -2686,8 +1743,7 @@ const PlotSchemePolygonArrowClamped = new PlotScheme({
2686
1743
  }
2687
1744
  const coords = points.map((e) => (0, vesium.toCoord)(e));
2688
1745
  if (coords.length >= 3) {
2689
- const positions = arrowClamped(coords);
2690
- const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
1746
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowClamped)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2691
1747
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2692
1748
  } else entity.polygon.hierarchy = void 0;
2693
1749
  return { entities: [entity] };
@@ -2712,8 +1768,7 @@ const PlotSchemePolygonArrowStraight = new PlotScheme({
2712
1768
  }
2713
1769
  const coords = points.map((e) => (0, vesium.toCoord)(e));
2714
1770
  if (coords.length >= 2) {
2715
- const positions = arrowStraight(coords);
2716
- const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
1771
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowStraight)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2717
1772
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2718
1773
  } else entity.polygon.hierarchy = void 0;
2719
1774
  return { entities: [entity] };
@@ -2738,8 +1793,7 @@ const PlotSchemePolygonArrowStraightSharp = new PlotScheme({
2738
1793
  }
2739
1794
  const coords = points.map((e) => (0, vesium.toCoord)(e));
2740
1795
  if (coords.length >= 2) {
2741
- const positions = arrowStraightSharp(coords);
2742
- const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
1796
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowStraightSharp)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2743
1797
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2744
1798
  } else entity.polygon.hierarchy = void 0;
2745
1799
  return { entities: [entity] };
@@ -2768,8 +1822,7 @@ const PlotSchemePolygonArrowUnitCombatOperation = new PlotScheme({
2768
1822
  entity.polygon.hierarchy = void 0;
2769
1823
  return context.previous;
2770
1824
  }
2771
- const positions = arrowUnitCombatOperation(coords).map((item) => (0, vesium.toCartesian3)(item));
2772
- const hierarchy = new cesium.PolygonHierarchy(positions);
1825
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowUnitCombatOperation)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2773
1826
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2774
1827
  return { entities: [entity] };
2775
1828
  }
@@ -2797,8 +1850,7 @@ const PlotSchemePolygonArrowUnitCombatOperationTailed = new PlotScheme({
2797
1850
  entity.polygon.hierarchy = void 0;
2798
1851
  return context.previous;
2799
1852
  }
2800
- const positions = arrowUnitCombatOperationTailed(coords).map((item) => (0, vesium.toCartesian3)(item));
2801
- const hierarchy = new cesium.PolygonHierarchy(positions);
1853
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.arrowUnitCombatOperationTailed)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2802
1854
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2803
1855
  return { entities: [entity] };
2804
1856
  }
@@ -2826,83 +1878,15 @@ const PlotSchemePolygonAssemblingPlace = new PlotScheme({
2826
1878
  entity.polygon.hierarchy = void 0;
2827
1879
  return context.previous;
2828
1880
  }
2829
- const positions = assemblingPlace(coords).map((item) => (0, vesium.toCartesian3)(item));
2830
- const hierarchy = new cesium.PolygonHierarchy(positions);
2831
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2832
- return { entities: [entity] };
2833
- }
2834
- });
2835
-
2836
- //#endregion
2837
- //#region scheme/PolygonFlagCurve.ts
2838
- const PlotSchemePolygonFlagCurve = new PlotScheme({
2839
- type: "PolygonFlagCurve",
2840
- complete: (packable) => packable.positions.length >= 2,
2841
- skeletons: [moved, control],
2842
- initRender() {
2843
- return { entities: [new cesium.Entity({ polygon: {} })] };
2844
- },
2845
- render(context) {
2846
- const entity = context.previous.entities[0];
2847
- const points = context.packable.positions;
2848
- context.mouse && points.push(context.mouse.clone());
2849
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2850
- if (coords.length < 2) {
2851
- entity.polygon.hierarchy = void 0;
2852
- return context.previous;
2853
- }
2854
- const positions = flagCurve(coords).map((item) => (0, vesium.toCartesian3)(item));
2855
- const hierarchy = new cesium.PolygonHierarchy(positions);
2856
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2857
- return { entities: [entity] };
2858
- }
2859
- });
2860
-
2861
- //#endregion
2862
- //#region scheme/PolygonFlagRect.ts
2863
- const PlotSchemePolygonFlagRect = new PlotScheme({
2864
- type: "PolygonFlagRect",
2865
- complete: (packable) => packable.positions.length >= 2,
2866
- skeletons: [moved, control],
2867
- initRender() {
2868
- return { entities: [new cesium.Entity({ polygon: {} })] };
2869
- },
2870
- render(context) {
2871
- const entity = context.previous.entities[0];
2872
- const points = context.packable.positions;
2873
- context.mouse && points.push(context.mouse.clone());
2874
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2875
- if (coords.length < 2) {
2876
- entity.polygon.hierarchy = void 0;
2877
- return context.previous;
2878
- }
2879
- const positions = flagRect(coords).map((item) => (0, vesium.toCartesian3)(item));
2880
- const hierarchy = new cesium.PolygonHierarchy(positions);
2881
- entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2882
- return { entities: [entity] };
2883
- }
2884
- });
2885
-
2886
- //#endregion
2887
- //#region scheme/PolygonFlagTriangle.ts
2888
- const PlotSchemePolygonFlagTriangle = new PlotScheme({
2889
- type: "PolygonFlagTriangle",
2890
- complete: (packable) => packable.positions.length >= 2,
2891
- skeletons: [moved, control],
2892
- initRender() {
2893
- return { entities: [new cesium.Entity({ polygon: {} })] };
2894
- },
2895
- render(context) {
2896
- const entity = context.previous.entities[0];
2897
- const points = context.packable.positions;
2898
- context.mouse && points.push(context.mouse.clone());
2899
- const coords = points.map((e) => (0, vesium.toCoord)(e));
2900
- if (coords.length < 2) {
2901
- entity.polygon.hierarchy = void 0;
2902
- return context.previous;
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)));
2903
1888
  }
2904
- const positions = flagTriangle(coords).map((item) => (0, vesium.toCartesian3)(item));
2905
- const hierarchy = new cesium.PolygonHierarchy(positions);
1889
+ const hierarchy = new cesium.PolygonHierarchy((0, __vesium_geometry.assemblingPlace)(coords).map((item) => (0, vesium.toCartesian3)(item)));
2906
1890
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2907
1891
  return { entities: [entity] };
2908
1892
  }
@@ -2933,8 +1917,7 @@ const PlotSchemePolygonSmooth = new PlotScheme({
2933
1917
  const wgs84s = positions.map((e) => (0, vesium.toCoord)(e));
2934
1918
  wgs84s.push(wgs84s[0]);
2935
1919
  const { features } = __turf_turf.polygonSmooth(__turf_turf.polygon([wgs84s]), { iterations: 3 });
2936
- const cartesians = features[0].geometry.coordinates[0].map((item) => (0, vesium.toCartesian3)(item)).filter((e) => !!e);
2937
- const hierarchy = new cesium.PolygonHierarchy(cartesians);
1920
+ const hierarchy = new cesium.PolygonHierarchy(features[0].geometry.coordinates[0].map((item) => (0, vesium.toCartesian3)(item)).filter((e) => !!e));
2938
1921
  entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
2939
1922
  return { entities: [entity] };
2940
1923
  }
@@ -3043,9 +2026,6 @@ exports.PlotSchemePolygonArrowStraightSharp = PlotSchemePolygonArrowStraightShar
3043
2026
  exports.PlotSchemePolygonArrowUnitCombatOperation = PlotSchemePolygonArrowUnitCombatOperation;
3044
2027
  exports.PlotSchemePolygonArrowUnitCombatOperationTailed = PlotSchemePolygonArrowUnitCombatOperationTailed;
3045
2028
  exports.PlotSchemePolygonAssemblingPlace = PlotSchemePolygonAssemblingPlace;
3046
- exports.PlotSchemePolygonFlagCurve = PlotSchemePolygonFlagCurve;
3047
- exports.PlotSchemePolygonFlagRect = PlotSchemePolygonFlagRect;
3048
- exports.PlotSchemePolygonFlagTriangle = PlotSchemePolygonFlagTriangle;
3049
2029
  exports.PlotSchemePolygonSmooth = PlotSchemePolygonSmooth;
3050
2030
  exports.PlotSchemePolyline = PlotSchemePolyline;
3051
2031
  exports.PlotSchemePolylineCurve = PlotSchemePolylineCurve;