@go-home-early/go-home-early98 0.3.1 → 0.3.3

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.
Files changed (56) hide show
  1. package/README.md +53 -24
  2. package/dist/go-home-early.umd.js +5 -5
  3. package/package.json +4 -18
  4. package/src/packages/Cesium/DrawMap/DrawJs/CesiumEntityEdit.js +427 -0
  5. package/src/packages/Cesium/DrawMap/DrawJs/CreatePolygonOnGround.js +202 -0
  6. package/src/packages/Cesium/DrawMap/DrawJs/DrawAttackArrow.js +477 -0
  7. package/src/packages/Cesium/DrawMap/DrawJs/DrawBillboard.js +114 -0
  8. package/src/packages/Cesium/DrawMap/DrawJs/DrawCircle.js +311 -0
  9. package/src/packages/Cesium/DrawMap/DrawJs/DrawCircleTY.js +237 -0
  10. package/src/packages/Cesium/DrawMap/DrawJs/DrawCurve.js +256 -0
  11. package/src/packages/Cesium/DrawMap/DrawJs/DrawPincerArrow.js +584 -0
  12. package/src/packages/Cesium/DrawMap/DrawJs/DrawPoint.js +158 -0
  13. package/src/packages/Cesium/DrawMap/DrawJs/DrawPolygon.js +215 -0
  14. package/src/packages/Cesium/DrawMap/DrawJs/DrawPolyline.js +213 -0
  15. package/src/packages/Cesium/DrawMap/DrawJs/DrawPolylineJT.js +218 -0
  16. package/src/packages/Cesium/DrawMap/DrawJs/DrawProFile.js +314 -0
  17. package/src/packages/Cesium/DrawMap/DrawJs/DrawRectangle.js +215 -0
  18. package/src/packages/Cesium/DrawMap/DrawJs/DrawstraightArrow.js +364 -0
  19. package/src/packages/Cesium/DrawMap/DrawJs/MeasurePolygon.js +337 -0
  20. package/src/packages/Cesium/DrawMap/DrawJs/MeasurePolyline.js +285 -0
  21. package/src/packages/Cesium/DrawMap/DrawJs/ReminderTip.js +78 -0
  22. package/src/packages/Cesium/DrawMap/DrawJs/SlopeAspect.js +436 -0
  23. package/src/packages/Cesium/DrawMap/DrawJs/measureLength.js +177 -0
  24. package/src/packages/Cesium/DrawMap/index.vue +272 -0
  25. package/src/packages/Cesium/components/LocationDialog.vue +283 -0
  26. package/src/packages/Cesium/components/Popup.vue +591 -0
  27. package/src/packages/Cesium/components/PoumianDialog.vue +200 -0
  28. package/src/packages/Cesium/imgs/add-off.png +0 -0
  29. package/src/packages/Cesium/imgs/add.png +0 -0
  30. package/src/packages/Cesium/imgs/circle.png +0 -0
  31. package/src/packages/Cesium/imgs/icon-position-blue.png +0 -0
  32. package/src/packages/Cesium/imgs/line.png +0 -0
  33. package/src/packages/Cesium/imgs/map-delete.png +0 -0
  34. package/src/packages/Cesium/imgs/map.png +0 -0
  35. package/src/packages/Cesium/imgs/orientation-bg.svg +14 -0
  36. package/src/packages/Cesium/imgs/orientation.svg +21 -0
  37. package/src/packages/Cesium/imgs/poi.png +0 -0
  38. package/src/packages/Cesium/imgs/point.png +0 -0
  39. package/src/packages/Cesium/imgs/polygon.png +0 -0
  40. package/src/packages/Cesium/imgs/popup/back-popup-img.png +0 -0
  41. package/src/packages/Cesium/imgs/popup/backimg-btn.png +0 -0
  42. package/src/packages/Cesium/imgs/popup/dialog-bd.png +0 -0
  43. package/src/packages/Cesium/imgs/popup/dialog-btn.png +0 -0
  44. package/src/packages/Cesium/imgs/popup/dialog-ft.png +0 -0
  45. package/src/packages/Cesium/imgs/popup/dialog-hd.png +0 -0
  46. package/src/packages/Cesium/imgs/reduce-off.png +0 -0
  47. package/src/packages/Cesium/index.md +292 -0
  48. package/src/packages/Cesium/index.vue +3830 -0
  49. package/src/packages/Cesium/materials/CircularDiffusionMaterialProperty.js +98 -0
  50. package/src/packages/Cesium/materials/CircularRippleMaterialProperty.js +126 -0
  51. package/src/packages/Cesium/materials/PolylineArrowMaterialProperty.js +109 -0
  52. package/src/packages/Cesium/utils/MeasureHeight.js +261 -0
  53. package/src/packages/Cesium/utils/MeasureTools.js +1188 -0
  54. package/src/packages/index.js +33 -0
  55. package/src/packages/utils/charts.js +54 -0
  56. package/src/packages/utils/index.js +50 -0
@@ -0,0 +1,202 @@
1
+ /*
2
+ * 创建贴地多边形
3
+ * @Author: Wang jianLei
4
+ * @Date: 2022-04-17 22:49:57
5
+ * @Last Modified by: 宋木桐
6
+ * @Last Modified time: 2024-08-20 11:20:28
7
+ */
8
+ import CreateRemindertip from "./ReminderTip";
9
+ const Cesium = window.Cesium;
10
+ /**
11
+ * 创建贴地多边形
12
+ * @param {object} viewer viewer
13
+ * @param {Array} resultList
14
+ * @param {{id:String,color:object,outlineColor:object,outlineWidth:number}} options {id,填充颜色,轮廓线颜色,轮廓线宽度}
15
+ * @param {Function} callback 携带创建的多边形对象
16
+ */
17
+ const CreatePolygonOnGround = function (viewer, resultList, options, callback) {
18
+ if (!viewer) throw new Error("no viewer object!");
19
+ options = options || {};
20
+ let id = options.id || setSessionid(); //Polygon的id
21
+ if (viewer.entities.getById(id))
22
+ throw new Error("the id parameter is an unique value");
23
+ let color = options.color || Cesium.Color.RED; //Polygon的填充色
24
+ let outlineColor = options.outlineColor || color.withAlpha(1); //Polygon的轮廓线颜色
25
+ let outlineWidth = options.outlineWidth || 2; //Polygon的轮廓线宽度
26
+ const handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
27
+ let toolTip = "左键点击开始绘制";
28
+ let anchorpoints = [];
29
+ let polygon = undefined;
30
+ let drawStatus = true;
31
+ handler.setInputAction(function (event) {
32
+ let pixPos = event.position;
33
+ let cartesian = getCatesian3FromPX(viewer, pixPos);
34
+ if (anchorpoints.length == 0) {
35
+ toolTip = "左键添加第二个点";
36
+ anchorpoints.push(cartesian);
37
+ let linePoints = new Cesium.CallbackProperty(function () {
38
+ let verPoints = anchorpoints.concat([anchorpoints[0]]);
39
+ return verPoints;
40
+ }, false);
41
+ let dynamicPositions = new Cesium.CallbackProperty(function () {
42
+ return new Cesium.PolygonHierarchy(anchorpoints);
43
+ }, false);
44
+ polygon = viewer.entities.add({
45
+ name: "Polygon",
46
+ id: id,
47
+ polyline: {
48
+ positions: linePoints,
49
+ width: outlineWidth,
50
+ material: outlineColor,
51
+ clampToGround: true,
52
+ },
53
+ polygon: {
54
+ heightReference: Cesium.HeightReference.None,
55
+ hierarchy: dynamicPositions,
56
+ material: color,
57
+ },
58
+ });
59
+ polygon.GeoType = "Polygon";
60
+ } else {
61
+ toolTip = "左键添加点,Ctrl+Z回退,右键完成绘制";
62
+ }
63
+ anchorpoints.push(cartesian);
64
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
65
+ handler.setInputAction(function (movement) {
66
+ let endPos = movement.endPosition;
67
+ CreateRemindertip(toolTip, endPos, true);
68
+ if (Cesium.defined(polygon)) {
69
+ anchorpoints.pop();
70
+ let cartesian = getCatesian3FromPX(viewer, endPos);
71
+ anchorpoints.push(cartesian);
72
+ }
73
+ if (anchorpoints.length === 3) {
74
+ polygon.polygon.heightReference = Cesium.HeightReference.CLAMP_TO_GROUND;
75
+ }
76
+ }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
77
+ handler.setInputAction(function (event) {
78
+ anchorpoints.pop();
79
+ polygon.pottingPoint = anchorpoints;
80
+ resultList.push(polygon);
81
+ handler.destroy();
82
+ CreateRemindertip(toolTip, event.position, false);
83
+ drawStatus = false;
84
+ if (typeof callback == "function") callback(polygon);
85
+ }, Cesium.ScreenSpaceEventType.RIGHT_DOWN);
86
+ //Ctrl + Z回退
87
+ document.onkeydown = function (event) {
88
+ if (event.ctrlKey && window.event.keyCode == 90) {
89
+ if (!drawStatus) {
90
+ return false;
91
+ }
92
+ anchorpoints.pop();
93
+ if (anchorpoints.length == 2) {
94
+ toolTip = "左键添加第二个点";
95
+ }
96
+ }
97
+ };
98
+ };
99
+ function getCatesian3FromPX(viewer, px) {
100
+ let picks = viewer.scene.drillPick(px);
101
+ let cartesian = null;
102
+ let isOn3dtiles = false,
103
+ isOnTerrain = false;
104
+ // drillPick
105
+ for (let i in picks) {
106
+ let pick = picks[i];
107
+ if (
108
+ (pick && pick.primitive instanceof Cesium.Cesium3DTileFeature) ||
109
+ (pick && pick.primitive instanceof Cesium.Cesium3DTileset) ||
110
+ (pick && pick.primitive instanceof Cesium.Model)
111
+ ) {
112
+ //模型上拾取
113
+ isOn3dtiles = true;
114
+ }
115
+ // 3dtilset
116
+ if (isOn3dtiles) {
117
+ viewer.scene.pick(px);
118
+ cartesian = viewer.scene.pickPosition(px);
119
+ if (cartesian) {
120
+ let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
121
+ if (cartographic.height < 0) cartographic.height = 0;
122
+ let lon = Cesium.Math.toDegrees(cartographic.longitude),
123
+ lat = Cesium.Math.toDegrees(cartographic.latitude),
124
+ height = cartographic.height;
125
+ cartesian = transformWGS84ToCartesian(viewer, {
126
+ lng: lon,
127
+ lat: lat,
128
+ alt: height,
129
+ });
130
+ }
131
+ }
132
+ }
133
+ // 地形
134
+ let boolTerrain =
135
+ viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider;
136
+ // console.log(`output->boolTerrain---------`, boolTerrain);
137
+ // console.log(`output->isOn3dtiles---------`, isOn3dtiles);
138
+ // Terrain
139
+ if (!isOn3dtiles && !boolTerrain) {
140
+ let ray = viewer.scene.camera.getPickRay(px);
141
+ if (!ray) return null;
142
+ cartesian = viewer.scene.globe.pick(ray, viewer.scene);
143
+ isOnTerrain = true;
144
+ }
145
+ // 地球
146
+ if (!isOn3dtiles && !isOnTerrain && boolTerrain) {
147
+ cartesian = viewer.scene.camera.pickEllipsoid(
148
+ px,
149
+ viewer.scene.globe.ellipsoid
150
+ );
151
+ }
152
+ if (cartesian) {
153
+ let position = transformCartesianToWGS84(viewer, cartesian);
154
+ if (position.alt < 0) {
155
+ cartesian = transformWGS84ToCartesian(viewer, position, 0.1);
156
+ }
157
+ return cartesian;
158
+ }
159
+ return false;
160
+ }
161
+
162
+ /***
163
+ * 坐标转换 84转笛卡尔
164
+ * @param {Object} {lng,lat,alt} 地理坐标
165
+ * @return {Object} Cartesian3 三维位置坐标
166
+ */
167
+ function transformWGS84ToCartesian(viewer, position, alt) {
168
+ return position
169
+ ? Cesium.Cartesian3.fromDegrees(
170
+ position.lng || position.lon,
171
+ position.lat,
172
+ (position.alt = alt || position.alt),
173
+ Cesium.Ellipsoid.WGS84
174
+ )
175
+ : Cesium.Cartesian3.ZERO;
176
+ }
177
+
178
+ /***
179
+ * 坐标转换 笛卡尔转84
180
+ * @param {Object} Cartesian3 三维位置坐标
181
+ * @return {Object} {lng,lat,alt} 地理坐标
182
+ */
183
+ function transformCartesianToWGS84(viewer, cartesian) {
184
+ let ellipsoid = Cesium.Ellipsoid.WGS84;
185
+ let cartographic = ellipsoid.cartesianToCartographic(cartesian);
186
+ return {
187
+ lng: Cesium.Math.toDegrees(cartographic.longitude),
188
+ lat: Cesium.Math.toDegrees(cartographic.latitude),
189
+ alt: cartographic.height,
190
+ };
191
+ }
192
+ function setSessionid(num) {
193
+ let len = num || 32;
194
+ let chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
195
+ let maxPos = chars.length;
196
+ let pwd = "";
197
+ for (let i = 0; i < len; i++) {
198
+ pwd += chars.charAt(Math.floor(Math.random() * maxPos));
199
+ }
200
+ return pwd;
201
+ }
202
+ export default CreatePolygonOnGround;
@@ -0,0 +1,477 @@
1
+ // DrawAttackArrow
2
+ /*
3
+ 绘制分队箭头
4
+ */
5
+ class DrawAttackArrow {
6
+ constructor(arg) {
7
+ // 设置唯一id 备用
8
+ this.objId = Number(
9
+ new Date().getTime() + '' + Number(Math.random() * 1000).toFixed(0)
10
+ );
11
+ this.drawName = 'DrawAttackArrow';
12
+ this.viewer = arg.viewer;
13
+ this.Cesium = arg.Cesium;
14
+ this.Text = arg.data.text || '';
15
+ this.Color = arg.data.color || '#000';
16
+ this.imgUrl = arg.data.imgUrl || '';
17
+ this.FontSize = arg.data.fontSize || 16;
18
+ this.callback = arg.data.callback || null;
19
+ this.handler = null;
20
+ this.floatingPoint = null; // 标识点
21
+ this._AttackArrow = null; // 活动箭头
22
+ this._AttackArrowLast = null; // 最后一个箭头
23
+ this._positions = []; // 活动点
24
+ this._entities_point = []; // 脏数据
25
+ this._entities_AttackArrow = []; // 脏数据+
26
+ this._AttackArrowData = null; // 用于构造箭头数据
27
+ }
28
+
29
+ // 返回箭头
30
+ get AttackArrow() {
31
+ return this._AttackArrowLast;
32
+ }
33
+
34
+ // 修改样式
35
+ updateStyleFunction(data) {
36
+ this.Text = data.text || '';
37
+ this.Color = data.color || '#000';
38
+ this.imgUrl = data.imgUrl || '';
39
+ this.FontSize = data.fontSize || 16;
40
+ this.callback = data.callback || null;
41
+ }
42
+
43
+ // 返回箭头数据用于加载箭头
44
+ getData() {
45
+ return this._AttackArrowData;
46
+ }
47
+
48
+ // 加载箭头
49
+ loadAttackArrow(data) {
50
+ var $this = this;
51
+ if (data.length < 3) {
52
+ return null;
53
+ }
54
+ var lnglatArr = [];
55
+ for (let i = 0; i < data.length; i++) {
56
+ var lnglat = $this.cartesianToLatlng(data[i]);
57
+ lnglatArr.push(lnglat);
58
+ }
59
+ for (let i = 0; i < this._entities_point.length; i++) {
60
+ this.viewer.entities.remove(this._entities_point[i]);
61
+ }
62
+ var res = $this.fineArrow(lnglatArr);
63
+ var returnData = res.polygonalPoint;
64
+ var arrowEntity = $this.viewer.entities.add({
65
+ polygon: {
66
+ hierarchy: new $this.Cesium.PolygonHierarchy(returnData),
67
+ show: true,
68
+ fill: true,
69
+ clampToGround: true,
70
+ material: $this.Cesium.Color.fromCssColorString($this.Color)
71
+ }
72
+ });
73
+ return arrowEntity;
74
+ }
75
+
76
+ // 开始创建
77
+ startCreate() {
78
+ var $this = this;
79
+ this.handler = new this.Cesium.ScreenSpaceEventHandler(
80
+ this.viewer.scene.canvas
81
+ );
82
+
83
+ this.handler.setInputAction(function(evt) {
84
+ // 单机开始绘制
85
+ // 屏幕坐标转地形上坐标
86
+ var cartesian = $this.getCatesian3FromPX(evt.position);
87
+ if ($this._positions.length == 0) {
88
+ // $this._positions.push(cartesian.clone());
89
+ $this.floatingPoint = $this.createPoint(cartesian);
90
+ $this.createPoint(cartesian); // 绘制点
91
+ }
92
+ if ($this._positions.length == 1) {
93
+ $this._positions.push(cartesian.clone());
94
+ $this.createPoint(cartesian); // 绘制点
95
+ }
96
+ $this._positions.push(cartesian);
97
+ }, $this.Cesium.ScreenSpaceEventType.LEFT_CLICK);
98
+
99
+ this.handler.setInputAction(function(evt) {
100
+ // 移动时绘制面
101
+ if ($this._positions.length < 3) return;
102
+ var cartesian = $this.getCatesian3FromPX(evt.endPosition);
103
+ if (!$this.Cesium.defined($this._AttackArrow)) {
104
+ $this._AttackArrow = $this.createAttackArrow();
105
+ }
106
+ $this.floatingPoint.position.setValue(cartesian);
107
+ if ($this._AttackArrow) {
108
+ // 因为有时候获取移动的点会出现undefined导致报错,所以在这里控制住
109
+ if (cartesian.x && cartesian.y && cartesian.z) {
110
+ $this._positions.pop();
111
+ $this._positions.push(cartesian);
112
+ }
113
+ }
114
+ }, $this.Cesium.ScreenSpaceEventType.MOUSE_MOVE);
115
+
116
+ this.handler.setInputAction(function(evt) {
117
+ if (!$this._AttackArrow) return;
118
+ var cartesian = $this.getCatesian3FromPX(evt.position);
119
+ $this._positions.pop();
120
+ $this._positions.push(cartesian);
121
+ $this._AttackArrowData = $this._positions.concat();
122
+ $this.viewer.entities.remove($this._AttackArrow); // 移除
123
+ $this._AttackArrow = null;
124
+ $this._positions = [];
125
+ $this.floatingPoint.position.setValue(cartesian);
126
+ var straightArrow = $this.loadAttackArrow($this._AttackArrowData); // 加载
127
+ $this._entities_AttackArrow.push(straightArrow);
128
+ $this._AttackArrowLast = straightArrow;
129
+ $this.clearPoint();
130
+ if (typeof $this.callback == 'function') {
131
+ // 提取多边形层次结构
132
+ var hierarchy = straightArrow.polygon.hierarchy.getValue();
133
+
134
+ // 从层次结构中提取坐标
135
+ var coordinates = hierarchy.positions.map(function(position) {
136
+ var cartographic = $this.Cesium.Cartographic.fromCartesian(position);
137
+ return [
138
+ $this.Cesium.Math.toDegrees(cartographic.longitude),
139
+ $this.Cesium.Math.toDegrees(cartographic.latitude)
140
+ ];
141
+ });
142
+
143
+ // 创建GeoJSON对象
144
+ var geojson = {
145
+ type: 'Polygon',
146
+ coordinates: [coordinates],
147
+ geometry: {
148
+ type: 'Polygon'
149
+ },
150
+ properties: {
151
+ color: $this.Color
152
+ }
153
+ };
154
+
155
+ $this.callback(geojson);
156
+ }
157
+ // $this.handler.destroy();
158
+ }, $this.Cesium.ScreenSpaceEventType.RIGHT_CLICK);
159
+ }
160
+
161
+ // 创建攻击箭头
162
+ createAttackArrow() {
163
+ var $this = this;
164
+ var arrowEntity = $this.viewer.entities.add({
165
+ polygon: {
166
+ hierarchy: new $this.Cesium.CallbackProperty(function() {
167
+ // 计算面
168
+ var lnglatArr = [];
169
+ for (var i = 0; i < $this._positions.length; i++) {
170
+ if (i > 0 && $this._positions[i] === $this._positions[i - 1]) {
171
+ continue;
172
+ }
173
+ var lnglat = $this.cartesianToLatlng($this._positions[i]);
174
+ lnglatArr.push(lnglat);
175
+ }
176
+ var res = $this.fineArrow(lnglatArr);
177
+ var returnData = res.polygonalPoint;
178
+ return new $this.Cesium.PolygonHierarchy(returnData);
179
+ }, false),
180
+ show: true,
181
+ fill: true,
182
+ clampToGround: true,
183
+ material:
184
+ $this.Cesium.Color.fromCssColorString('#ffffff').withAlpha(0.5)
185
+ }
186
+ });
187
+ $this._entities_AttackArrow.push(arrowEntity);
188
+ return arrowEntity;
189
+ }
190
+
191
+ // 创建点
192
+ createPoint(cartesian) {
193
+ var $this = this;
194
+ var point = this.viewer.entities.add({
195
+ position: cartesian,
196
+ point: {
197
+ pixelSize: 10,
198
+ color: $this.Cesium.Color.YELLOW
199
+ }
200
+ });
201
+ point.objId = this.objId;
202
+ $this._entities_point.push(point);
203
+ return point;
204
+ }
205
+
206
+ cartesianToLatlng(cartesian) {
207
+ var latlng =
208
+ this.viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
209
+ var lat = this.Cesium.Math.toDegrees(latlng.latitude);
210
+ var lng = this.Cesium.Math.toDegrees(latlng.longitude);
211
+ return [lng, lat];
212
+ }
213
+
214
+ // 销毁
215
+ destroy() {
216
+ if (this.handler) {
217
+ this.handler.destroy();
218
+ this.handler = null;
219
+ }
220
+ }
221
+
222
+ clearPoint() {
223
+ for (var i = 0; i < this._entities_point.length; i++) {
224
+ this.viewer.entities.remove(this._entities_point[i]);
225
+ }
226
+ this._entities_point = []; // 脏数据
227
+ }
228
+
229
+ // 清空实体对象
230
+ clear() {
231
+ for (let i = 0; i < this._entities_point.length; i++) {
232
+ this.viewer.entities.remove(this._entities_point[i]);
233
+ }
234
+ for (let i = 0; i < this._entities_AttackArrow.length; i++) {
235
+ this.viewer.entities.remove(this._entities_AttackArrow[i]);
236
+ }
237
+
238
+ this.floatingPoint = null; // 标识点
239
+ this._AttackArrow = null; // 活动箭头
240
+ this._AttackArrowLast = null; // 最后一个箭头
241
+ this._positions = []; // 活动点
242
+ this._entities_point = []; // 脏数据
243
+ this._entities_AttackArrow = []; // 脏数据
244
+ this._AttackArrowData = null; // 用于构造箭头数据
245
+ }
246
+
247
+ getCatesian3FromPX(px) {
248
+ var cartesian;
249
+ var ray = this.viewer.camera.getPickRay(px);
250
+ if (!ray) return null;
251
+ cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
252
+ return cartesian;
253
+ }
254
+
255
+ // //////////////////////////////////////求取箭头坐标函数/////////////////////////////////////////////////////
256
+ // 箭头配置函数
257
+ fineArrowDefualParam() {
258
+ return {
259
+ headHeightFactor: 0.18,
260
+ headWidthFactor: 0.3,
261
+ neckHeightFactor: 0.85,
262
+ neckWidthFactor: 0.15,
263
+ tailWidthFactor: 0.1,
264
+ headTailFactor: 0.8,
265
+ swallowTailFactor: 1
266
+ };
267
+ }
268
+
269
+ fineArrow(inputPoint) {
270
+ var $this = this;
271
+ inputPoint = $this.dereplication(inputPoint);
272
+ const tailWidthFactor = $this.fineArrowDefualParam().tailWidthFactor;
273
+ const swallowTailFactor = $this.fineArrowDefualParam().swallowTailFactor;
274
+ let swallowTailPnt = $this.fineArrowDefualParam().swallowTailPnt;
275
+ // 控制点
276
+ var result = {
277
+ controlPoint: null,
278
+ polygonalPoint: null
279
+ };
280
+ result.controlPoint = inputPoint;
281
+ var t = inputPoint.length;
282
+ if (!(t < 2)) {
283
+ if (inputPoint.length == 2) {
284
+ result.polygonalPoint = inputPoint;
285
+ return result;
286
+ }
287
+ var o = inputPoint;
288
+ var e = o[0];
289
+ var r = o[1];
290
+ $this.isClockWise(o[0], o[1], o[2]) && ((e = o[1]), (r = o[0]));
291
+ var n = $this.mid(e, r);
292
+ var g = [n].concat(o.slice(2));
293
+ var i = $this.getAttackArrowHeadPoints(
294
+ g,
295
+ e,
296
+ r,
297
+ $this.fineArrowDefualParam()
298
+ );
299
+ var s = i[0];
300
+ var a = i[4];
301
+ var l = $this.distance(e, r);
302
+ var u = $this.getBaseLength(g);
303
+ var c = u * tailWidthFactor * swallowTailFactor;
304
+ swallowTailPnt = $this.getThirdPoint(g[1], g[0], 0, c, !0);
305
+ var p = l / u;
306
+ var h = $this.getAttackArrowBodyPoints(g, s, a, p);
307
+ const t = h.length;
308
+ var d = [e].concat(h.slice(0, t / 2));
309
+ d.push(s);
310
+ var f = [r].concat(h.slice(t / 2, t));
311
+ var newArray = [];
312
+ f.push(a);
313
+ d = $this.getQBSplinePoints(d);
314
+ f = $this.getQBSplinePoints(f);
315
+ newArray = $this.array2Dto1D(
316
+ d.concat(i, f.reverse(), [swallowTailPnt, d[0]])
317
+ );
318
+
319
+ result.polygonalPoint =
320
+ $this.Cesium.Cartesian3.fromDegreesArray(newArray);
321
+ }
322
+ return result;
323
+ }
324
+
325
+ getAttackArrowHeadPoints(t, o, e, defaultParam) {
326
+ var $this = this;
327
+ const headHeightFactor = defaultParam.headHeightFactor;
328
+ const headTailFactor = defaultParam.headTailFactor;
329
+ const headWidthFactor = defaultParam.headWidthFactor;
330
+ const neckWidthFactor = defaultParam.neckWidthFactor;
331
+ const neckHeightFactor = defaultParam.neckHeightFactor;
332
+ var r = $this.getBaseLength(t);
333
+ var n = r * headHeightFactor;
334
+ var g = t[t.length - 1];
335
+ r = $this.distance(g, t[t.length - 2]);
336
+ var i = $this.distance(o, e);
337
+ n > i * headTailFactor && (n = i * headTailFactor);
338
+ var s = n * headWidthFactor;
339
+ var a = n * neckWidthFactor;
340
+ n = n > r ? r : n;
341
+ var l = n * neckHeightFactor;
342
+ var u = $this.getThirdPoint(t[t.length - 2], g, 0, n, !0);
343
+ var c = $this.getThirdPoint(t[t.length - 2], g, 0, l, !0);
344
+ var p = $this.getThirdPoint(g, u, Math.PI / 2, s, !1);
345
+ var h = $this.getThirdPoint(g, u, Math.PI / 2, s, !0);
346
+ var d = $this.getThirdPoint(g, c, Math.PI / 2, a, !1);
347
+ var f = $this.getThirdPoint(g, c, Math.PI / 2, a, !0);
348
+ return [d, p, g, h, f];
349
+ }
350
+
351
+ getAttackArrowBodyPoints = function(t, o, e, r) {
352
+ var $this = this;
353
+ for (
354
+ var n = $this.wholeDistance(t),
355
+ g = $this.getBaseLength(t),
356
+ i = g * r,
357
+ s = $this.distance(o, e),
358
+ a = (i - s) / 2,
359
+ l = 0,
360
+ u = [],
361
+ c = [],
362
+ p = 1;
363
+ p < t.length - 1;
364
+ p++
365
+ ) {
366
+ var h = $this.getAngleOfThreePoints(t[p - 1], t[p], t[p + 1]) / 2;
367
+ l += $this.distance(t[p - 1], t[p]);
368
+ var d = (i / 2 - (l / n) * a) / Math.sin(h);
369
+ var f = $this.getThirdPoint(t[p - 1], t[p], Math.PI - h, d, !0);
370
+ var E = $this.getThirdPoint(t[p - 1], t[p], h, d, !1);
371
+ u.push(f);
372
+ c.push(E);
373
+ }
374
+ return u.concat(c);
375
+ };
376
+
377
+ getAngleOfThreePoints(t, o, e) {
378
+ var r = this.getAzimuth(o, t) - this.getAzimuth(o, e);
379
+ return r < 0 ? r + Math.PI * 2 : r;
380
+ }
381
+
382
+ dereplication(arr) {
383
+ return arr.filter((value, index, array) => {
384
+ return (
385
+ array.findIndex((item) => {
386
+ return item[0] === value[0] && item[1] === value[1];
387
+ }) === index
388
+ );
389
+ });
390
+ }
391
+
392
+ getBaseLength(t) {
393
+ return Math.pow(this.wholeDistance(t), 0.99);
394
+ }
395
+
396
+ wholeDistance(t) {
397
+ for (var o = 0, e = 0; e < t.length - 1; e++) {
398
+ o += this.distance(t[e], t[e + 1]);
399
+ }
400
+ return o;
401
+ }
402
+
403
+ distance(t, o) {
404
+ return Math.sqrt(Math.pow(t[0] - o[0], 2) + Math.pow(t[1] - o[1], 2));
405
+ }
406
+
407
+ getThirdPoint(t, o, e, r, n) {
408
+ var g = this.getAzimuth(t, o);
409
+ var i = n ? g + e : g - e;
410
+ var s = r * Math.cos(i);
411
+ var a = r * Math.sin(i);
412
+ return [o[0] + s, o[1] + a];
413
+ }
414
+
415
+ getAzimuth(t, o) {
416
+ var e;
417
+ var r = Math.asin(Math.abs(o[1] - t[1]) / this.distance(t, o));
418
+ return (
419
+ o[1] >= t[1] && o[0] >= t[0]
420
+ ? (e = r + Math.PI)
421
+ : o[1] >= t[1] && o[0] < t[0]
422
+ ? (e = 2 * Math.PI - r)
423
+ : o[1] < t[1] && o[0] < t[0]
424
+ ? (e = r)
425
+ : o[1] < t[1] && o[0] >= t[0] && (e = Math.PI - r),
426
+ e
427
+ );
428
+ }
429
+
430
+ isClockWise(t, o, e) {
431
+ return (e[1] - t[1]) * (o[0] - t[0]) > (o[1] - t[1]) * (e[0] - t[0]);
432
+ }
433
+
434
+ mid(t, o) {
435
+ return [(t[0] + o[0]) / 2, (t[1] + o[1]) / 2];
436
+ }
437
+
438
+ getQBSplinePoints = function(t) {
439
+ if (t.length <= 2) return t;
440
+ var o = 2;
441
+ var e = [];
442
+ var r = t.length - o - 1;
443
+ var y = 0;
444
+ e.push(t[0]);
445
+ for (var n = 0; r >= n; n++) {
446
+ for (var g = 0; g <= 1; g += 0.05) {
447
+ for (var i = (y = 0), s = 0; o >= s; s++) {
448
+ var a = this.getQuadricBSplineFactor(s, g);
449
+ i += a * t[n + s][0];
450
+ y += a * t[n + s][1];
451
+ }
452
+ e.push([i, y]);
453
+ }
454
+ }
455
+ e.push(t[t.length - 1]);
456
+ return e;
457
+ };
458
+ getQuadricBSplineFactor = function(t, o) {
459
+ return t == 0
460
+ ? Math.pow(o - 1, 2) / 2
461
+ : t == 1
462
+ ? (-2 * Math.pow(o, 2) + 2 * o + 1) / 2
463
+ : t == 2
464
+ ? Math.pow(o, 2) / 2
465
+ : 0;
466
+ };
467
+ array2Dto1D = function(array) {
468
+ var newArray = [];
469
+ array.forEach(function(elt) {
470
+ newArray.push(elt[0]);
471
+ newArray.push(elt[1]);
472
+ });
473
+ return newArray;
474
+ };
475
+ }
476
+
477
+ export default DrawAttackArrow;