@vesium/plot 1.0.1-beta.26 → 1.0.1-beta.28

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,8 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { Color, Cartesian3, VerticalOrigin, HorizontalOrigin, Rectangle, Entity, CallbackPositionProperty, CallbackProperty, PolygonHierarchy, JulianDate, Event, TimeInterval, createGuid, PrimitiveCollection, CustomDataSource, ScreenSpaceEventType } from "cesium";
5
- import { toCartographic, toCartesian3, canvasCoordToCartesian, isFunction, assertError, createCesiumAttribute, createCesiumProperty, throttle, arrayDifference, pickHitGraphic } from "@vesium/shared";
4
+ import { Entity, Color, Cartesian3, VerticalOrigin, HorizontalOrigin, Rectangle, CallbackPositionProperty, CallbackProperty, PolygonHierarchy, JulianDate, Event, TimeInterval, createGuid, PrimitiveCollection, CustomDataSource, ScreenSpaceEventType } from "cesium";
5
+ import { toCartographic, toCartesian3, canvasCoordToCartesian, assertError, createCesiumAttribute, createCesiumProperty, throttle, arrayDiff, isFunction, pickHitGraphic } from "@vesium/shared";
6
6
  import { assert, notNullish, watchArray, promiseTimeout, onKeyStroke } from "@vueuse/core";
7
7
  import { useViewer, usePrimitive, useDataSource, useEntityScope, usePrimitiveScope, useScreenSpaceEventHandler, useCesiumEventListener, useGraphicDrag, useGraphicHover, useGraphicLeftClick } from "@vesium/core";
8
8
  import { useViewer as useViewer$1 } from "@vesium/core/useViewer";
@@ -13,25 +13,30 @@ var PlotAction = /* @__PURE__ */ ((PlotAction2) => {
13
13
  PlotAction2[PlotAction2["ACTIVE"] = 2] = "ACTIVE";
14
14
  return PlotAction2;
15
15
  })(PlotAction || {});
16
+ class PlotSkeletonEntity extends Entity {
17
+ constructor(options) {
18
+ super(options);
19
+ }
20
+ }
16
21
  function control() {
17
22
  return {
18
- diabled: ({ active }) => !active,
23
+ disabled: ({ active }) => !active,
19
24
  cursor: "pointer",
20
25
  dragCursor: "crosshair",
21
- onDrag({ viewer, sample, packable, context, index, lockCamera }) {
26
+ onDrag({ viewer, sampled, packable, context, index, lockCamera }) {
22
27
  lockCamera();
23
28
  const position = canvasCoordToCartesian(context.endPosition, viewer.scene);
24
29
  if (position) {
25
30
  const positions = [...packable.positions ?? []];
26
31
  positions[index] = position;
27
- sample.setSample({
32
+ sampled.setSample({
28
33
  time: packable.time,
29
34
  derivative: packable.derivative,
30
35
  positions
31
36
  });
32
37
  }
33
38
  },
34
- onKeyPressed({ viewer, keyEvent, sample, packable, index }) {
39
+ onKeyPressed({ viewer, keyEvent, sampled, packable, index }) {
35
40
  var _a;
36
41
  const height = (_a = toCartographic(viewer.camera.position)) == null ? void 0 : _a.height;
37
42
  if (!height || !["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft"].includes(keyEvent.key))
@@ -60,7 +65,7 @@ function control() {
60
65
  cartographic.latitude += distance * Math.cos(newHeading);
61
66
  cartographic.longitude += distance * Math.sin(newHeading);
62
67
  positions[index] = toCartesian3(cartographic);
63
- sample.setSample({
68
+ sampled.setSample({
64
69
  time: packable.time,
65
70
  derivative: packable.derivative,
66
71
  positions
@@ -88,7 +93,7 @@ function control() {
88
93
  function interval() {
89
94
  let dragIndex = -1;
90
95
  return {
91
- diabled: ({ active, defining }) => !active || defining,
96
+ disabled: ({ active, defining }) => !active || defining,
92
97
  cursor: "pointer",
93
98
  dragCursor: "crosshair",
94
99
  format(packable) {
@@ -101,7 +106,7 @@ function interval() {
101
106
  return Cartesian3.midpoint(position, next, new Cartesian3());
102
107
  });
103
108
  },
104
- onDrag({ viewer, sample, packable, context, index, lockCamera, dragging }) {
109
+ onDrag({ viewer, sampled, packable, context, index, lockCamera, dragging }) {
105
110
  lockCamera();
106
111
  const position = canvasCoordToCartesian(context.endPosition, viewer.scene);
107
112
  if (!position) {
@@ -117,7 +122,7 @@ function interval() {
117
122
  if (!dragging) {
118
123
  dragIndex = -1;
119
124
  }
120
- sample.setSample({
125
+ sampled.setSample({
121
126
  time: packable.time,
122
127
  derivative: packable.derivative,
123
128
  positions
@@ -148,7 +153,7 @@ function interval() {
148
153
  function intervalNonclosed() {
149
154
  let dragIndex = -1;
150
155
  return {
151
- diabled: ({ active, defining }) => !active || defining,
156
+ disabled: ({ active, defining }) => !active || defining,
152
157
  cursor: "pointer",
153
158
  dragCursor: "crosshair",
154
159
  format(packable) {
@@ -156,11 +161,13 @@ function intervalNonclosed() {
156
161
  if (_positions.length < 2) {
157
162
  return [];
158
163
  }
159
- return _positions.slice(0, _positions.length - 1).map((position, i) => {
160
- return Cartesian3.midpoint(position, _positions[i + 1], new Cartesian3());
161
- });
164
+ const midpoints = [];
165
+ for (let i = 0; i < _positions.length - 1; i++) {
166
+ midpoints.push(Cartesian3.midpoint(_positions[i], _positions[i + 1], new Cartesian3()));
167
+ }
168
+ return midpoints;
162
169
  },
163
- onDrag({ viewer, sample, packable, context, index, lockCamera, dragging }) {
170
+ onDrag({ viewer, sampled, packable, context, index, lockCamera, dragging }) {
164
171
  lockCamera();
165
172
  const position = canvasCoordToCartesian(context.endPosition, viewer.scene);
166
173
  if (!position) {
@@ -176,7 +183,7 @@ function intervalNonclosed() {
176
183
  if (!dragging) {
177
184
  dragIndex = -1;
178
185
  }
179
- sample.setSample({
186
+ sampled.setSample({
180
187
  time: packable.time,
181
188
  derivative: packable.derivative,
182
189
  positions
@@ -206,7 +213,7 @@ const svg = `data:image/svg+xml;utf8,${encodeURIComponent(
206
213
  )}`;
207
214
  function moved() {
208
215
  return {
209
- diabled: ({ active, defining }) => !active || defining,
216
+ disabled: ({ active, defining }) => !active || defining,
210
217
  cursor: "pointer",
211
218
  dragCursor: "crosshair",
212
219
  format(packable) {
@@ -220,7 +227,7 @@ function moved() {
220
227
  return [toCartesian3(center)];
221
228
  }
222
229
  },
223
- onDrag({ viewer, sample, packable, context, lockCamera, dragging }) {
230
+ onDrag({ viewer, sampled, packable, context, lockCamera, dragging }) {
224
231
  dragging && lockCamera();
225
232
  const startPosition = canvasCoordToCartesian(context.startPosition, viewer.scene);
226
233
  const endPosition = canvasCoordToCartesian(context.endPosition, viewer.scene);
@@ -229,7 +236,7 @@ function moved() {
229
236
  }
230
237
  const offset = Cartesian3.subtract(endPosition, startPosition, new Cartesian3());
231
238
  const positions = [...packable.positions ?? []];
232
- sample.setSample({
239
+ sampled.setSample({
233
240
  time: packable.time,
234
241
  derivative: packable.derivative,
235
242
  positions: positions.map((position) => Cartesian3.add(position, offset, new Cartesian3()))
@@ -399,16 +406,20 @@ const _PlotScheme = class _PlotScheme {
399
406
  this.complete = options.complete;
400
407
  this.forceComplete = options.forceComplete;
401
408
  this.definingCursor = options.definingCursor ?? "crosshair";
402
- this.skeletons = ((_a = options.skeletons) == null ? void 0 : _a.map((item) => isFunction(item) ? item() : item)) ?? [];
409
+ this.skeletons = ((_a = options.skeletons) == null ? void 0 : _a.map((item) => item())) ?? [];
403
410
  this.render = options.render;
404
411
  }
405
- static getRecordTypes() {
412
+ static getCacheTypes() {
406
413
  return [...this._record.keys()];
407
414
  }
408
- static getRecord(type) {
415
+ static getCache(type) {
409
416
  return _PlotScheme._record.get(type);
410
417
  }
411
- static setRecord(scheme) {
418
+ /**
419
+ * 设置标绘方案
420
+ * @param scheme
421
+ */
422
+ static setCache(scheme) {
412
423
  assertError(!scheme.type, "`scheme.type` is required");
413
424
  _PlotScheme._record.set(scheme.type, scheme);
414
425
  }
@@ -417,7 +428,7 @@ const _PlotScheme = class _PlotScheme {
417
428
  */
418
429
  static resolve(maybeScheme) {
419
430
  if (typeof maybeScheme === "string") {
420
- const _scheme = _PlotScheme.getRecord(maybeScheme);
431
+ const _scheme = _PlotScheme.getCache(maybeScheme);
421
432
  assert(!!_scheme, `scheme ${maybeScheme} not found`);
422
433
  return _scheme;
423
434
  } else if (!(maybeScheme instanceof _PlotScheme)) {
@@ -682,31 +693,45 @@ class Plot {
682
693
  createCesiumAttribute(this, "disabled", !!options.disabled);
683
694
  createCesiumAttribute(this, "defining", true);
684
695
  createCesiumAttribute(this, "scheme", PlotScheme.resolve(options.scheme), { readonly: true });
685
- const sample = options.sample instanceof SampledPlotProperty ? options.sample : new SampledPlotProperty(options.sample);
686
- createCesiumProperty(this, "sample", sample);
696
+ const sampled = options.sampled instanceof SampledPlotProperty ? options.sampled : new SampledPlotProperty(options.sampled);
697
+ createCesiumProperty(this, "sampled", sampled);
687
698
  createCesiumAttribute(this, "entities", []);
688
699
  createCesiumAttribute(this, "primitives", []);
689
700
  createCesiumAttribute(this, "groundPrimitives", []);
690
701
  createCesiumAttribute(this, "skeletonEntities", []);
691
702
  }
703
+ /**
704
+ * An event that is raised when a property is changed.
705
+ */
692
706
  get definitionChanged() {
693
707
  return this._definitionChanged;
694
708
  }
709
+ /**
710
+ * 当前标绘是否处于定义态
711
+ */
695
712
  isDefining() {
696
713
  return this.defining;
697
714
  }
715
+ /**
716
+ * 获取当前标绘的entity数组
717
+ */
698
718
  getEntities() {
699
719
  return [...this.entities];
700
720
  }
721
+ /**
722
+ * 获取当前标绘的primitive数组
723
+ */
701
724
  getPrimitives() {
702
725
  return [...this.primitives];
703
726
  }
727
+ /**
728
+ * 获取当前标绘的贴地primitive数组
729
+ */
704
730
  getGroundPrimitives() {
705
731
  return [...this.groundPrimitives];
706
732
  }
707
733
  /**
708
- * 获取该标绘的骨架点entity数组
709
- *
734
+ * 获取当前标绘标绘的骨架点entity数组
710
735
  */
711
736
  getSkeletonEntities() {
712
737
  return [...this.skeletonEntities];
@@ -745,15 +770,15 @@ function useRender(plots, current, getCurrentTime) {
745
770
  () => plots.value.map((item) => item.definitionChanged),
746
771
  (_scope, key, newValue, oldValue) => {
747
772
  if (key === "entities") {
748
- const { added, removed } = arrayDifference(newValue, oldValue);
773
+ const { added, removed } = arrayDiff(newValue, oldValue);
749
774
  added.forEach((item) => entityScope.add(item));
750
775
  removed.forEach((item) => entityScope.remove(item));
751
776
  } else if (key === "primitives") {
752
- const { added, removed } = arrayDifference(newValue, oldValue);
777
+ const { added, removed } = arrayDiff(newValue, oldValue);
753
778
  added.forEach((item) => primitiveScope.add(item));
754
779
  removed.forEach((item) => primitiveScope.remove(item));
755
780
  } else if (key === "groundPrimitives") {
756
- const { added, removed } = arrayDifference(newValue, oldValue);
781
+ const { added, removed } = arrayDiff(newValue, oldValue);
757
782
  added.forEach((item) => groundPrimitiveScope.add(item));
758
783
  removed.forEach((item) => groundPrimitiveScope.remove(item));
759
784
  }
@@ -762,7 +787,7 @@ function useRender(plots, current, getCurrentTime) {
762
787
  const update = throttle(async (plot) => {
763
788
  var _a, _b;
764
789
  const reslut = await ((_b = (_a = plot.scheme).render) == null ? void 0 : _b.call(_a, {
765
- packable: plot.sample.getValue(getCurrentTime()),
790
+ packable: plot.sampled.getValue(getCurrentTime()),
766
791
  mouse: plot.defining ? mouseCartesian.value : void 0,
767
792
  defining: plot.defining,
768
793
  previous: {
@@ -781,7 +806,7 @@ function useRender(plots, current, getCurrentTime) {
781
806
  useCesiumEventListener(
782
807
  () => plots.value.map((item) => item.definitionChanged),
783
808
  (plot, key) => {
784
- if (["disabled", "defining", "scheme", "sample", "time"].includes(key)) {
809
+ if (["disabled", "defining", "scheme", "sampled", "time"].includes(key)) {
785
810
  update(plot);
786
811
  }
787
812
  }
@@ -800,7 +825,7 @@ function useSampled(current, getCurrentTime) {
800
825
  const doubleClicking = ref(false);
801
826
  const packable = computed(() => {
802
827
  var _a;
803
- return (_a = current.value) == null ? void 0 : _a.sample.getValue(getCurrentTime());
828
+ return (_a = current.value) == null ? void 0 : _a.sampled.getValue(getCurrentTime());
804
829
  });
805
830
  useScreenSpaceEventHandler(
806
831
  ScreenSpaceEventType.LEFT_CLICK,
@@ -813,7 +838,7 @@ function useSampled(current, getCurrentTime) {
813
838
  if (doubleClicking.value) {
814
839
  return;
815
840
  }
816
- const { scheme, defining, sample } = current.value;
841
+ const { scheme, defining, sampled } = current.value;
817
842
  if (!defining) {
818
843
  return;
819
844
  }
@@ -823,7 +848,7 @@ function useSampled(current, getCurrentTime) {
823
848
  }
824
849
  (_a = packable.value).positions ?? (_a.positions = []);
825
850
  packable.value.positions.push(position);
826
- sample.setSample(packable.value);
851
+ sampled.setSample(packable.value);
827
852
  const completed = (_b = scheme.complete) == null ? void 0 : _b.call(scheme, packable.value);
828
853
  completed && (current.value.defining = false);
829
854
  }
@@ -857,7 +882,7 @@ function useSampled(current, getCurrentTime) {
857
882
  if (!current.value || !packable.value) {
858
883
  return;
859
884
  }
860
- const { defining, sample } = current.value;
885
+ const { defining, sampled } = current.value;
861
886
  if (!defining) {
862
887
  return;
863
888
  }
@@ -866,7 +891,7 @@ function useSampled(current, getCurrentTime) {
866
891
  return;
867
892
  }
868
893
  packable.value.positions.splice(packable.value.positions.length - 1, 1);
869
- sample.setSample(packable.value);
894
+ sampled.setSample(packable.value);
870
895
  }
871
896
  );
872
897
  const definingCursorCss = ref();
@@ -889,17 +914,12 @@ function useSampled(current, getCurrentTime) {
889
914
  var _a;
890
915
  return (_a = current.value) == null ? void 0 : _a.definitionChanged;
891
916
  }, (plot, key) => {
892
- if (key === "defining" || key === "sample") {
917
+ if (key === "defining" || key === "sampled") {
893
918
  setDefiningCursorCss();
894
919
  }
895
920
  });
896
921
  watch(current, () => setDefiningCursorCss());
897
922
  }
898
- class PlotSkeletonEntity extends Entity {
899
- constructor(options) {
900
- super(options);
901
- }
902
- }
903
923
  function useSkeleton(plots, current, getCurrentTime) {
904
924
  const viewer = useViewer();
905
925
  const dataSource = useDataSource(new CustomDataSource());
@@ -919,14 +939,14 @@ function useSkeleton(plots, current, getCurrentTime) {
919
939
  if (destroyed || plot.disabled) {
920
940
  plot.skeletonEntities = [];
921
941
  } else {
922
- const packable = plot.sample.getValue(getCurrentTime());
942
+ const packable = plot.sampled.getValue(getCurrentTime());
923
943
  const defining = plot.defining;
924
944
  const active = current.value === plot;
925
945
  const skeletons = plot.scheme.skeletons;
926
946
  skeletons.forEach((skeleton) => {
927
947
  var _a;
928
- const diabled = isFunction(skeleton.diabled) ? skeleton.diabled({ active, defining }) : skeleton.diabled;
929
- if (diabled) {
948
+ const disabled = isFunction(skeleton.disabled) ? skeleton.disabled({ active, defining }) : skeleton.disabled;
949
+ if (disabled) {
930
950
  return;
931
951
  }
932
952
  const positions = ((_a = skeleton.format) == null ? void 0 : _a.call(skeleton, packable)) ?? (packable == null ? void 0 : packable.positions) ?? [];
@@ -987,10 +1007,10 @@ function useSkeleton(plots, current, getCurrentTime) {
987
1007
  activeEntity.value = entity;
988
1008
  const skeleton = entity.skeleton;
989
1009
  const index = entity.index;
990
- const packable = plot.sample.getValue(getCurrentTime());
1010
+ const packable = plot.sampled.getValue(getCurrentTime());
991
1011
  (_a = skeleton.onDrag) == null ? void 0 : _a.call(skeleton, {
992
1012
  viewer: viewer.value,
993
- sample: plot.sample,
1013
+ sampled: plot.sampled,
994
1014
  packable,
995
1015
  active: current.value === plot,
996
1016
  index,
@@ -1010,10 +1030,10 @@ function useSkeleton(plots, current, getCurrentTime) {
1010
1030
  const plot = entity.plot;
1011
1031
  const skeleton = entity.skeleton;
1012
1032
  const index = entity.index;
1013
- const packable = plot.sample.getValue(getCurrentTime());
1033
+ const packable = plot.sampled.getValue(getCurrentTime());
1014
1034
  (_a = skeleton.onKeyPressed) == null ? void 0 : _a.call(skeleton, {
1015
1035
  viewer: viewer.value,
1016
- sample: plot.sample,
1036
+ sampled: plot.sampled,
1017
1037
  packable,
1018
1038
  index,
1019
1039
  keyEvent
@@ -1039,10 +1059,10 @@ function useSkeleton(plots, current, getCurrentTime) {
1039
1059
  const plot = entity.plot;
1040
1060
  const skeleton = entity.skeleton;
1041
1061
  const index = entity.index;
1042
- const packable = plot.sample.getValue(getCurrentTime());
1062
+ const packable = plot.sampled.getValue(getCurrentTime());
1043
1063
  (_a = skeleton.onLeftClick) == null ? void 0 : _a.call(skeleton, {
1044
1064
  viewer: viewer.value,
1045
- sample: plot.sample,
1065
+ sampled: plot.sampled,
1046
1066
  packable,
1047
1067
  active: current.value === plot,
1048
1068
  defining: plot.defining,
@@ -1059,11 +1079,11 @@ function useSkeleton(plots, current, getCurrentTime) {
1059
1079
  removed.forEach((plot) => update(plot, true));
1060
1080
  });
1061
1081
  useCesiumEventListener(() => plots.value.map((plot) => plot.definitionChanged), (plot, key, newValue, oldValue) => {
1062
- if (["disabled", "defining", "scheme", "sample", "time"].includes(key)) {
1082
+ if (["disabled", "defining", "scheme", "sampled", "time"].includes(key)) {
1063
1083
  update(plot);
1064
1084
  }
1065
1085
  if (key === "skeletonEntities") {
1066
- const { added, removed } = arrayDifference(newValue, oldValue);
1086
+ const { added, removed } = arrayDiff(newValue, oldValue);
1067
1087
  added.forEach((item) => entityScope.add(item));
1068
1088
  removed.forEach((item) => entityScope.remove(item));
1069
1089
  }
@@ -1092,11 +1112,11 @@ function usePlot(options) {
1092
1112
  useCesiumEventListener([
1093
1113
  () => {
1094
1114
  var _a;
1095
- return (_a = current.value) == null ? void 0 : _a.sample.definitionChanged;
1115
+ return (_a = current.value) == null ? void 0 : _a.sampled.definitionChanged;
1096
1116
  }
1097
1117
  ], () => {
1098
1118
  var _a;
1099
- packable.value = (_a = current.value) == null ? void 0 : _a.sample.getValue(getCurrentTime());
1119
+ packable.value = (_a = current.value) == null ? void 0 : _a.sampled.getValue(getCurrentTime());
1100
1120
  });
1101
1121
  useSampled(current, getCurrentTime);
1102
1122
  useRender(plots, current, getCurrentTime);
@@ -1122,7 +1142,7 @@ function usePlot(options) {
1122
1142
  var _a, _b;
1123
1143
  if (previous) {
1124
1144
  if (previous.defining) {
1125
- const packable2 = previous.sample.getValue(getCurrentTime());
1145
+ const packable2 = previous.sampled.getValue(getCurrentTime());
1126
1146
  const completed = (_b = (_a = previous.scheme).forceComplete) == null ? void 0 : _b.call(_a, packable2);
1127
1147
  if (completed) {
1128
1148
  previous.defining = false;