@yangyongtao/gaea 1.0.3 → 1.1.0

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 (137) hide show
  1. package/README.md +158 -67
  2. package/package.json +28 -7
  3. package/public/Gaea.apple-touch-icon.png +0 -0
  4. package/public/Gaea.apple-touch-icon.png.import +35 -0
  5. package/public/Gaea.audio.worklet.js +211 -0
  6. package/public/Gaea.html +245 -0
  7. package/public/Gaea.icon.png +0 -0
  8. package/public/Gaea.icon.png.import +35 -0
  9. package/public/Gaea.js +782 -0
  10. package/public/Gaea.png +0 -0
  11. package/public/Gaea.png.import +35 -0
  12. package/public/Gaea.worker.js +1 -0
  13. package/public/GaeaApp.html +275 -0
  14. package/public/GaeaMethods.js +4342 -0
  15. package/public/GaeaModule.html +276 -0
  16. package/public/config.js +76 -0
  17. package/public/constants.js +185 -0
  18. package/public/favicon.ico +0 -0
  19. package/public/image/1.png +0 -0
  20. package/public/image/12-min-min.gif +0 -0
  21. package/public/image/3.png +0 -0
  22. package/public/image/labelImg//345/217/263/350/276/271.png +0 -0
  23. package/public/image/labelImg//345/267/246/350/276/271.png +0 -0
  24. package/public/image/labelImg//346/260/264/344/275/215.png +0 -0
  25. package/public/image/screenIcon//345/205/266/344/273/226.png +0 -0
  26. package/public/image/screenIcon//345/256/211/345/205/250/347/233/221/346/265/213/350/201/232/345/220/210-/347/272/242.png +0 -0
  27. package/public/image/screenIcon//345/256/211/345/205/250/347/233/221/346/265/213/350/201/232/345/220/210-/347/273/277.png +0 -0
  28. package/public/image/screenIcon//346/212/242/351/231/251/345/215/225/344/275/215.png +0 -0
  29. package/public/image/screenIcon//346/226/255/351/235/242.png +0 -0
  30. package/public/image/screenIcon//346/227/240/344/272/272/346/234/272.png +0 -0
  31. package/public/image/screenIcon//346/227/240/344/272/272/346/234/272/345/237/272/345/234/260.png +0 -0
  32. package/public/image/screenIcon//346/260/264/345/272/223/347/253/231.png +0 -0
  33. package/public/image/screenIcon//346/260/264/346/226/207/346/265/213/347/253/231.png +0 -0
  34. package/public/image/screenIcon//346/260/264/351/227/270.png +0 -0
  35. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/346/227/240/346/225/260/346/215/256.png +0 -0
  36. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/346/255/243/345/270/270.png +0 -0
  37. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/344/277/235.png +0 -0
  38. package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/350/255/246.png +0 -0
  39. package/public/image/screenIcon//346/263/265/347/253/231-/347/201/260.png +0 -0
  40. package/public/image/screenIcon//346/263/265/347/253/231-/347/273/277.png +0 -0
  41. package/public/image/screenIcon//346/265/201/351/207/217/346/265/213/347/253/231.png +0 -0
  42. package/public/image/screenIcon//346/265/267/345/241/230-1/347/272/247.png +0 -0
  43. package/public/image/screenIcon//346/265/267/345/241/230-2/347/272/247.png +0 -0
  44. package/public/image/screenIcon//346/265/267/345/241/230-3/347/272/247.png +0 -0
  45. package/public/image/screenIcon//346/265/267/345/241/230-4/347/272/247.png +0 -0
  46. package/public/image/screenIcon//346/265/267/345/241/230-5/347/272/247.png +0 -0
  47. package/public/image/screenIcon//346/265/267/345/241/230-/346/251/231.png +0 -0
  48. package/public/image/screenIcon//346/265/267/345/241/230-/347/272/242.png +0 -0
  49. package/public/image/screenIcon//346/265/267/345/241/230-/347/273/277.png +0 -0
  50. package/public/image/screenIcon//346/265/267/345/241/230-/350/247/204/346/250/241/344/273/245/344/270/213.png +0 -0
  51. package/public/image/screenIcon//346/265/267/345/241/230-/351/273/204.png +0 -0
  52. package/public/image/screenIcon//346/265/267/345/241/230.png +0 -0
  53. package/public/image/screenIcon//346/275/256/344/275/215.png +0 -0
  54. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/346/227/240/346/225/260/346/215/256.png +0 -0
  55. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/346/255/243/345/270/270.png +0 -0
  56. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/344/277/235.png +0 -0
  57. package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/350/255/246.png +0 -0
  58. package/public/image/screenIcon//347/211/251/350/265/204/344/273/223/345/272/223.png +0 -0
  59. package/public/image/screenIcon//347/220/203/346/234/272-/345/205/263.png +0 -0
  60. package/public/image/screenIcon//347/220/203/346/234/272-/345/274/200.png +0 -0
  61. package/public/image/screenIcon//347/220/203/346/234/272-/347/272/242.png +0 -0
  62. package/public/image/screenIcon//350/247/206/351/242/221/347/233/221/346/216/247.png +0 -0
  63. package/public/image/screenIcon//351/227/270/351/227/250-/347/201/260.png +0 -0
  64. package/public/image/screenIcon//351/227/270/351/227/250-/347/273/277.png +0 -0
  65. package/public/image/screenIcon//351/230/262/346/264/252/344/273/223/345/272/223.png +0 -0
  66. package/public/image/screenIcon//351/232/220/346/202/243.png +0 -0
  67. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/346/265/205/350/223/235.png +0 -0
  68. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/201/260.png +0 -0
  69. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/262/211.png +0 -0
  70. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/272/242.png +0 -0
  71. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/273/277.png +0 -0
  72. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/350/223/235.png +0 -0
  73. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/204.png +0 -0
  74. package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/221.png +0 -0
  75. package/public/image/screenIcon//351/243/216/351/200/237.png +0 -0
  76. package/public/image/screenIcon//351/243/216/351/200/237/346/265/213/347/253/231.png +0 -0
  77. package/public/image//346/260/264/346/226/207.gif +0 -0
  78. package/public/image//350/211/262/345/270/246.png +0 -0
  79. package/public/index.html +22 -0
  80. package/public/index.js +185662 -0
  81. package/public/jsWebControl-1.0.0.min.js +31 -0
  82. package/public/jsencrypt.min.js +1 -0
  83. package/public/math/Box2.js +203 -0
  84. package/public/math/Box3.js +532 -0
  85. package/public/math/Color.js +605 -0
  86. package/public/math/ColorManagement.js +74 -0
  87. package/public/math/Cylindrical.js +61 -0
  88. package/public/math/EngineUtils.js +81 -0
  89. package/public/math/Euler.js +315 -0
  90. package/public/math/Frustum.js +162 -0
  91. package/public/math/Interpolant.js +241 -0
  92. package/public/math/Line3.js +115 -0
  93. package/public/math/MathUtils.js +345 -0
  94. package/public/math/Matrix3.js +365 -0
  95. package/public/math/Matrix4.js +858 -0
  96. package/public/math/Plane.js +205 -0
  97. package/public/math/Quaternion.js +724 -0
  98. package/public/math/Ray.js +493 -0
  99. package/public/math/Sphere.js +243 -0
  100. package/public/math/Spherical.js +86 -0
  101. package/public/math/SphericalHarmonics3.js +243 -0
  102. package/public/math/Triangle.js +299 -0
  103. package/public/math/Vector2.js +464 -0
  104. package/public/math/Vector3.js +715 -0
  105. package/public/math/Vector4.js +644 -0
  106. package/public/math/interpolants/CubicInterpolant.js +151 -0
  107. package/public/math/interpolants/DiscreteInterpolant.js +26 -0
  108. package/public/math/interpolants/LinearInterpolant.js +38 -0
  109. package/public/math/interpolants/QuaternionLinearInterpolant.js +39 -0
  110. package/public/static/Cloud.png +0 -0
  111. package/public/static/Global2.jpg +0 -0
  112. package/public/static/css/main.css +170 -0
  113. package/public/static/geojson//346/265/267/345/241/230.geojson +99 -0
  114. package/public/static/img/loading.gif +0 -0
  115. package/public/static/js/app.js +359 -0
  116. package/public/static/js/appcontroller.js +207 -0
  117. package/public/static/js/dist/game.dev.js +137 -0
  118. package/public/static/js/env.js +74 -0
  119. package/public/static/js/event/event.js +107 -0
  120. package/public/static/js/init.js +8 -0
  121. package/public/static/js/initcloudmorph.js +1 -0
  122. package/public/static/js/log.js +35 -0
  123. package/public/static/js/network/ajax.js +29 -0
  124. package/public/static/js/network/rtcp.js +172 -0
  125. package/public/static/js/network/socket.js +106 -0
  126. package/public/web-control.min.js +2 -0
  127. package/scripts/postinstall.mjs +127 -0
  128. package/src/GaeaMethods.js +68 -405
  129. package/src/components/FlyAlongRoute.vue +1 -0
  130. package/src/components/WeatherControl.vue +2 -0
  131. package/src/directives/vDrag.js +70 -0
  132. package/src/index.js +1 -8
  133. package/src/plugin.js +16 -0
  134. package/src/utils.js +10 -21
  135. package/src/vite-plugin.js +117 -0
  136. package/public/static/1111.res +0 -0
  137. package/src/config.js +0 -40
@@ -0,0 +1,4342 @@
1
+ /**
2
+ * Gaea-version:"4.0.0"
3
+ * version:"4.0.0"
4
+ * 修改时间:2023/3/10
5
+ * 方法作者: nx
6
+ */
7
+
8
+ import Gaea from "./index.js";
9
+ // import * as turf from "@/utils/turf.js";
10
+ import { Tween, Group, Easing } from "@tweenjs/tween.js";
11
+ import pinia from "@/store/store.js";
12
+ import { storeToRefs } from "pinia";
13
+ import gaeaData from "@/store/module/gaeaData.js";
14
+ import groundLine from "@/assets/js/groundLine.js";
15
+ import { serveUrl, getServerAssets, TerrainList, serveLocal } from "./config.js";
16
+
17
+ const gaeaExample = gaeaData(pinia);
18
+ const { rollerPower, gltfList, MoveCoordinates, ScreenIconList, groundLineList, iconLayerVisible } =
19
+ storeToRefs(gaeaExample);
20
+ // const {
21
+ // changeCoordinates
22
+ // } = gaeaExample;
23
+
24
+ //获取当前时间
25
+ Date.prototype.Format = function (fmt) {
26
+ var o = {
27
+ "M+": this.getMonth() + 1, //月份
28
+ "d+": this.getDate(), //日
29
+ "H+": this.getHours(), //小时
30
+ "m+": this.getMinutes(), //分
31
+ "s+": this.getSeconds(), //秒
32
+ "q+": Math.floor((this.getMonth() + 3) / 3), //季度
33
+ S: this.getMilliseconds(), //毫秒
34
+ };
35
+ if (/(y+)/.test(fmt))
36
+ fmt = fmt.replace(
37
+ RegExp.$1,
38
+ (this.getFullYear() + "").substr(4 - RegExp.$1.length)
39
+ );
40
+ for (var k in o)
41
+ if (new RegExp("(" + k + ")").test(fmt))
42
+ fmt = fmt.replace(
43
+ RegExp.$1,
44
+ RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
45
+ );
46
+ return fmt;
47
+ };
48
+ //加载资源
49
+ function LoadResourceAsync(url = "") {
50
+ let name = url.substring(url.lastIndexOf("/") + 1);
51
+ return new Promise((res, rej) => {
52
+ Gaea.GaeaResourceLoader.Instance.LoadResourceFromUrl1(
53
+ url,
54
+ name,
55
+ (code, msg) => {
56
+ if (code == 200) {
57
+ res();
58
+ } else {
59
+ rej(new Error("出错啦!!!!!"));
60
+ }
61
+ }
62
+ );
63
+ });
64
+ }
65
+ async function LoadResourceFromUrl(url, name) {
66
+ return new Promise((res, rej) => {
67
+ Gaea.GaeaResourceLoader.Instance.LoadResourceFromUrl1(
68
+ url,
69
+ name,
70
+ (code, msg) => {
71
+ if (code == 200) {
72
+ res(true);
73
+ } else {
74
+ console.log(msg);
75
+ rej(false);
76
+ }
77
+ }
78
+ );
79
+ });
80
+ }
81
+ /**
82
+ * 获取路径中的文件名称
83
+ * @param {string} url
84
+ */
85
+ function getFlieName(url) {
86
+ // console.log(url);
87
+ // // url=url.replace(/\%23/g,"#")
88
+ // let index = url.lastIndexOf("/");
89
+ // let flieName = url.substring(index + 1, url.length);
90
+ // return flieName;
91
+ return url.split("/").pop().split("?")[0];
92
+ }
93
+
94
+ //生成uuid
95
+ /**
96
+ * @param {number} len 生成长度
97
+ * @param {number} radix 进制
98
+ * @return {string}
99
+ */
100
+ function uuid(len = 8, radix = 16) {
101
+ var chars =
102
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
103
+ var uuid = [],
104
+ i;
105
+ radix = radix || chars.length;
106
+
107
+ if (len) {
108
+ // Compact form
109
+ for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
110
+ } else {
111
+ // rfc4122, version 4 form
112
+ var r;
113
+
114
+ // rfc4122 requires these characters
115
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
116
+ uuid[14] = "4";
117
+
118
+ // Fill in random data. At i==19 set the high bits of clock sequence as
119
+ // per rfc4122, sec. 4.1.5
120
+ for (i = 0; i < 36; i++) {
121
+ if (!uuid[i]) {
122
+ r = 0 | (Math.random() * 16);
123
+ uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
124
+ }
125
+ }
126
+ }
127
+
128
+ return uuid.join("");
129
+ }
130
+ //识别是否base64路径
131
+ function base64FileHeaderMapper(fileBase64) {
132
+ let fileHeader = new Map();
133
+
134
+ //获取不同文件的文件头前3个字作为判断依据
135
+ fileHeader.set("/9j", "JPG");
136
+ fileHeader.set("iVB", "PNG");
137
+ fileHeader.set("Qk0", "BMP");
138
+ fileHeader.set("SUk", "TIFF");
139
+ fileHeader.set("JVB", "PDF");
140
+ fileHeader.set("UEs", "OFD");
141
+
142
+ let res = "";
143
+
144
+ //遍历map中所提及的文件头特征
145
+ fileHeader.forEach((v, k) => {
146
+ if (k == fileBase64.substr(0, 3)) {
147
+ res = v;
148
+ }
149
+ });
150
+
151
+ //如果不在map中返回unknown file
152
+ if (res == "") {
153
+ res = "unknown file";
154
+ }
155
+
156
+ //否则返回map中的value值
157
+ return res;
158
+ }
159
+ function parseColorString(colorString) {
160
+ //配置颜色
161
+ const colors = {};
162
+ // 将16进制颜色值转换为Gaea颜色
163
+ function hexToGaeaColor(hex) {
164
+ // 去除前缀 #
165
+ hex = hex.replace(/^#/, "");
166
+
167
+ // 处理6位或3位的16进制颜色值
168
+ if (hex.length === 6) {
169
+ const r = parseInt(hex.slice(0, 2), 16) / 255;
170
+ const g = parseInt(hex.slice(2, 4), 16) / 255;
171
+ const b = parseInt(hex.slice(4, 6), 16) / 255;
172
+ const GaeaColor = new Gaea.Color(r, g, b, 1);
173
+ console.log(GaeaColor);
174
+ return GaeaColor;
175
+ } else if (hex.length === 3) {
176
+ const r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
177
+ const g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
178
+ const b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
179
+ const GaeaColor = new Gaea.Color(r, g, b, 1);
180
+ console.log(r, g, b);
181
+ console.log(GaeaColor);
182
+ return GaeaColor;
183
+ } else {
184
+ throw new Error("Invalid hex color string");
185
+ }
186
+ }
187
+
188
+ // 将RGBA颜色值转换为Gaea颜色
189
+ function rgbaToGaeaColor(rgba) {
190
+ const rgbaRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*([\d.]+)?\)$/;
191
+ const matches = rgba.match(rgbaRegex);
192
+
193
+ if (matches) {
194
+ const r = parseInt(matches[1]) / 255;
195
+ const g = parseInt(matches[2]) / 255;
196
+ const b = parseInt(matches[3]) / 255;
197
+ const a = parseFloat(matches[4] || 1);
198
+ console.log(new Gaea.Color(r, g, b, a));
199
+ return new Gaea.Color(r, g, b, a);
200
+ } else {
201
+ throw new Error("Invalid RGBA color string");
202
+ }
203
+ }
204
+ // 匹配16进制颜色值
205
+ const hexRegex = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
206
+ // 匹配rgba颜色值
207
+ const rgbaRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*([\d.]+)?\)$/;
208
+ // 判断字符串格式并进行转换
209
+ if (hexRegex.test(colorString)) {
210
+ return hexToGaeaColor(colorString);
211
+ } else if (rgbaRegex.test(colorString)) {
212
+ return rgbaToGaeaColor(colorString);
213
+ } else if (colors[colorString]) {
214
+ return colors[colorString];
215
+ } else {
216
+ console.error("not color string");
217
+ return false;
218
+ }
219
+ }
220
+ //rgb转gaea内置颜色
221
+ function RgbcolorToGaeaColor(rgb) {
222
+ if (typeof rgb !== "string") return false;
223
+ let regex = /\((.+?)\)/g;
224
+ let newRgb = rgb.match(regex)[0];
225
+ let newRgbArr = newRgb.substring(1, newRgb.length - 1).split(",");
226
+ let gaeaColor = new Gaea.Color(
227
+ newRgbArr[0] / 255,
228
+ newRgbArr[1] / 255,
229
+ newRgbArr[2] / 255,
230
+ 1
231
+ );
232
+ console.log(gaeaColor);
233
+ return gaeaColor;
234
+ }
235
+ //rgb转vector3颜色
236
+ function RbgColorToVector3(rgb) {
237
+ if (typeof rgb !== "string") return false;
238
+ let regex = /\((.+?)\)/g;
239
+ let newRgb = rgb.match(regex)[0];
240
+ let newRgbArr = newRgb.substring(1, newRgb.length - 1).split(",");
241
+ return new Gaea.Color(
242
+ newRgbArr[0] / 255,
243
+ newRgbArr[1] / 255,
244
+ newRgbArr[2] / 255,
245
+ 1.0
246
+ );
247
+ }
248
+
249
+ /**
250
+ * NOTE: 通过tileset.json中的transform计算坐标
251
+ */
252
+ function fromCartesian(cartesian) {
253
+ const oneOverRadii = {
254
+ x: 1.0 / 6378137.0,
255
+ y: 1.0 / 6378137.0,
256
+ z: 1.0 / 6356752.3142451793,
257
+ };
258
+ const oneOverRadiiSquared = {
259
+ x: 1.0 / (6378137.0 * 6378137.0),
260
+ y: 1.0 / (6378137.0 * 6378137.0),
261
+ z: 1.0 / (6356752.3142451793 * 6356752.3142451793),
262
+ };
263
+
264
+ const p = scaleToGeodeticSurface(
265
+ cartesian,
266
+ oneOverRadii,
267
+ oneOverRadiiSquared,
268
+ 0.1
269
+ );
270
+
271
+ if (!(p !== undefined && p !== null)) {
272
+ return undefined;
273
+ }
274
+
275
+ let n = {
276
+ x: p.x * oneOverRadiiSquared.x,
277
+ y: p.y * oneOverRadiiSquared.y,
278
+ z: p.z * oneOverRadiiSquared.z,
279
+ };
280
+ const m1 = magnitude(n);
281
+ n = {
282
+ x: n.x / m1,
283
+ y: n.y / m1,
284
+ z: n.z / m1,
285
+ };
286
+
287
+ const h = {
288
+ x: cartesian.x - p.x,
289
+ y: cartesian.y - p.y,
290
+ z: cartesian.z - p.z,
291
+ };
292
+
293
+ const longitude = Math.atan2(n.y, n.x);
294
+ const latitude = Math.asin(n.z);
295
+ const height =
296
+ Math.sign(h.x * cartesian.x + h.y * cartesian.y + h.z * cartesian.z) *
297
+ magnitude(h);
298
+
299
+ let result = {};
300
+ result.longitude = (longitude * 180.0) / Math.PI;
301
+ result.latitude = (latitude * 180.0) / Math.PI;
302
+ result.height = height;
303
+ return result;
304
+ }
305
+
306
+ function scaleToGeodeticSurface(
307
+ cartesian,
308
+ oneOverRadii,
309
+ oneOverRadiiSquared,
310
+ centerToleranceSquared
311
+ ) {
312
+ const positionX = cartesian.x;
313
+ const positionY = cartesian.y;
314
+ const positionZ = cartesian.z;
315
+
316
+ const oneOverRadiiX = oneOverRadii.x;
317
+ const oneOverRadiiY = oneOverRadii.y;
318
+ const oneOverRadiiZ = oneOverRadii.z;
319
+
320
+ const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
321
+ const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
322
+ const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;
323
+
324
+ // Compute the squared ellipsoid norm.
325
+ const squaredNorm = x2 + y2 + z2;
326
+ const ratio = Math.sqrt(1.0 / squaredNorm);
327
+
328
+ // As an initial approximation, assume that the radial intersection is the projection point.
329
+ const intersection = {
330
+ x: cartesian.x * ratio,
331
+ y: cartesian.y * ratio,
332
+ z: cartesian.z * ratio,
333
+ };
334
+
335
+ // If the position is near the center, the iteration will not converge.
336
+ if (squaredNorm < centerToleranceSquared) {
337
+ return !isFinite(ratio) ? undefined : intersection;
338
+ }
339
+
340
+ const oneOverRadiiSquaredX = oneOverRadiiSquared.x;
341
+ const oneOverRadiiSquaredY = oneOverRadiiSquared.y;
342
+ const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;
343
+
344
+ // Use the gradient at the intersection point in place of the true unit normal.
345
+ // The difference in magnitude will be absorbed in the multiplier.
346
+ const gradient = {
347
+ x: intersection.x * oneOverRadiiSquaredX * 2.0,
348
+ y: intersection.y * oneOverRadiiSquaredY * 2.0,
349
+ z: intersection.z * oneOverRadiiSquaredZ * 2.0,
350
+ };
351
+
352
+ // Compute the initial guess at the normal vector multiplier, lambda.
353
+ let lambda =
354
+ ((1.0 - ratio) * magnitude(cartesian)) / (0.5 * magnitude(gradient));
355
+ let correction = 0.0;
356
+
357
+ let func;
358
+ let denominator;
359
+ let xMultiplier;
360
+ let yMultiplier;
361
+ let zMultiplier;
362
+ let xMultiplier2;
363
+ let yMultiplier2;
364
+ let zMultiplier2;
365
+ let xMultiplier3;
366
+ let yMultiplier3;
367
+ let zMultiplier3;
368
+
369
+ do {
370
+ lambda -= correction;
371
+
372
+ xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);
373
+ yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);
374
+ zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);
375
+
376
+ xMultiplier2 = xMultiplier * xMultiplier;
377
+ yMultiplier2 = yMultiplier * yMultiplier;
378
+ zMultiplier2 = zMultiplier * zMultiplier;
379
+
380
+ xMultiplier3 = xMultiplier2 * xMultiplier;
381
+ yMultiplier3 = yMultiplier2 * yMultiplier;
382
+ zMultiplier3 = zMultiplier2 * zMultiplier;
383
+
384
+ func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;
385
+
386
+ // "denominator" here refers to the use of this expression in the velocity and acceleration
387
+ // computations in the sections to follow.
388
+ denominator =
389
+ x2 * xMultiplier3 * oneOverRadiiSquaredX +
390
+ y2 * yMultiplier3 * oneOverRadiiSquaredY +
391
+ z2 * zMultiplier3 * oneOverRadiiSquaredZ;
392
+
393
+ const derivative = -2.0 * denominator;
394
+
395
+ correction = func / derivative;
396
+ } while (Math.abs(func) > 0.000000000001);
397
+
398
+ let result = {
399
+ x: positionX * xMultiplier,
400
+ y: positionY * yMultiplier,
401
+ z: positionZ * zMultiplier,
402
+ };
403
+ return result;
404
+ }
405
+
406
+ function magnitude(cartesian) {
407
+ return Math.sqrt(
408
+ cartesian.x * cartesian.x +
409
+ cartesian.y * cartesian.y +
410
+ cartesian.z * cartesian.z
411
+ );
412
+ }
413
+
414
+
415
+
416
+ let RiverEditTool;
417
+ let ytImageId;
418
+ let ytTimer;
419
+ // 集雨区
420
+ let jyqpolygonElement = [];
421
+ //三角网
422
+ let vt;
423
+
424
+ // 台风
425
+ let typhoonData;
426
+
427
+ // 存储
428
+ const types = {
429
+ GroundDistance: Gaea.MeasureGroundContactDistanceTool,
430
+ SpatialDistance: Gaea.MeasureSpatialDistanceTool,
431
+ Height: Gaea.MeasureHeightTool,
432
+ Area: Gaea.MeasureAreaPolygonTool,
433
+ Volume: Gaea.DrawVolumeMeasurementTool,
434
+ };
435
+ // var onload = null
436
+ export default class App {
437
+ constructor() {
438
+ //当前图层列表
439
+ this.layers = [];
440
+ //影像图层
441
+ this.tLayers = [];
442
+ //鼠标点击事件
443
+ this.mouserUp = null;
444
+ //鼠标滚动事件
445
+ this.mouserWheel = null;
446
+ //鼠标移动事件
447
+ this.mouseMove = null;
448
+ // 鼠标双击事件
449
+ this.mouseDoubleClick = null;
450
+
451
+ // 地形数组
452
+ this.dxyb_Arr = [];
453
+ // 地形演变定时器
454
+ this.dxyb_Interval = null;
455
+
456
+ // 画线
457
+ this.importBox = false;
458
+
459
+ this.streamline = [];
460
+
461
+ // 流场对象
462
+ this._streaml = null;
463
+
464
+ // 服务列表
465
+ this.serveList = [];
466
+
467
+ //用来存储所有点线面生成的element对象,这个需要前端自行管理(例如删除)
468
+ this.elements = [];
469
+
470
+ // 坐标点集合
471
+ this.pointList = [];
472
+
473
+ // 线数组
474
+ this.lineList = [];
475
+
476
+ // 等值云图对象
477
+ this.isometricRendering = {};
478
+ this.texture0 = {};
479
+ this.vt = {};
480
+ // new add
481
+ this.iconDict = new Map();
482
+ this.wmsLayers = [];
483
+ // VTS矢量服务对象
484
+ this.vectorServiceList = [];
485
+ this.groundPolygon = [];
486
+
487
+ this.tweenGroup = new Group();
488
+
489
+ this.groundWire = []
490
+ }
491
+
492
+ // //获取静态资源路径
493
+ getServerAssets = async () => {
494
+ console.log("加载静态资源");
495
+ Gaea.World.Instance.Is3DTilesNeedCache = false; //缓存关闭
496
+ Gaea.World.Instance.IsPyramidTileSetNeedCache = false; //缓存关闭
497
+ //关闭雾
498
+ var fog_environment = Gaea.Environment.ConvertBy(
499
+ Gaea.GaeaResourceLoader.Instance.LoadLoaclResource(
500
+ "res://default_env.tres"
501
+ )
502
+ );
503
+ fog_environment.FogEnabled = false;
504
+
505
+ // 关闭大气
506
+ // var FullScreenQuad = Gaea.WeatherManager.ConvertBy(
507
+ // Gaea.World.Instance.GetNode("Camera/FullScreenQuad")
508
+ // );
509
+ // FullScreenQuad.Visible = false;
510
+
511
+ // const logo = Gaea.World.Instance.GetNode("@@6");
512
+ // logo.QueueFree()
513
+ window.Gaea = Gaea;
514
+ var cfg_code2 = `[Engine]
515
+ DefaultGlobalOverview="Global2.jpg"
516
+ AssetHost="${getServerAssets}"`;
517
+ // Gaea.EngineConfig.Instance.LoadConfig(cfg_code2);
518
+ // Gaea.World.Instance.LoadDefaultEngineConfig();
519
+ Gaea.World.Instance.EngineConfigString = cfg_code2;
520
+ // Gaea.EngineConfig.Instance.engin(cfg_code2);
521
+ // Gaea.World.Instance.UseHttps = true;
522
+ Gaea.World.Instance.ForceCloudVisalbe = true;
523
+ Gaea.World.Instance.CloudVisalbe = false;
524
+ // Gaea.World.instance.GeometryErrorFineness = 10.0;
525
+ // await this.InitFontTexture();
526
+
527
+ // RiverEditTool = new Gaea.RiverEditTool();
528
+ var environment = Gaea.Environment.ConvertBy(Gaea.GaeaResourceLoader.Instance.LoadLoaclResource("res://default_env.tres"));
529
+ environment.BackgroundEnergy = 0.6;
530
+
531
+ var sun = Gaea.Sun.ConvertBy(Gaea.World.Instance.GetNode("Sun"));
532
+ var environment = Gaea.Environment.ConvertBy(Gaea.GaeaResourceLoader.Instance.LoadLoaclResource("res://default_env.tres"));
533
+ sun.Power = 1.5;
534
+ // sun.TimeString = "2022-09-15 10:00:00";
535
+ // setInterval(() => {
536
+ // let i = 0
537
+ // sun.TimeString = `2022-09-15 ${i}:00:00`;
538
+ // i++
539
+ // if (i == 24) {
540
+ // i = 0
541
+ // }
542
+ // }, 1000);
543
+ // sun.TimeScale = 7200;
544
+
545
+ };
546
+ //获取服务列表
547
+ getAllServe = async () => {
548
+ const url = `${serveUrl}htc/service/wmts?REQUEST=GetCapabilities`;
549
+ var result = await (
550
+ await fetch(url)
551
+ ).text();
552
+ // var result = await (await fetch('http://172.18.100.213:6080/arcgis/rest/services/yanjiuyuan/soundgwms21/MapServer/WMTS/1.0.0/WMTSCapabilities.xml')).text()
553
+ // if (Object.prototype.toString.call(result) === "[object Object]") return console.error('图层列表获取失败,请检查请求地址');
554
+ let hostUrl = `${serveUrl}htc/service/wmts`;
555
+ // let hostUrl = `http://172.18.100.213:6080/arcgis/rest/services/yanjiuyuan/soundgwms21/MapServer/WMTS/1.0.0/WMTSCapabilities.xml`
556
+ const layers = Gaea.WMTSImageStore.ParserXml2Capabilities(hostUrl, result);
557
+ this.layers = [...this.layers, ...layers];
558
+ return this.layers;
559
+ };
560
+
561
+ //监听鼠标点击事件
562
+ addMouseUp = () => {
563
+ document.getElementById("canvas").addEventListener("mousedown", function () {
564
+ var pointlist = []
565
+ var pointelement = new Gaea.PointGeometryElement();//创建点element
566
+ Gaea.World.Instance.RenderableObjectList.AddLast(pointelement);
567
+ var result = Gaea.GaeaMath.ProjectPosition(new Gaea.Vector2(event.offsetX, event.offsetY));
568
+ var lonlat = Gaea.GaeaMath.CartesianToSphericalDeg(result);
569
+ const pos = {
570
+ x: lonlat.x,
571
+ y: lonlat.y,
572
+ z: lonlat.z,
573
+ }
574
+ // 画点
575
+ // pointelement.Visible = true;
576
+ // pointlist.push(lonlat);
577
+ // var pointgeometry = Gaea.Geometry.Create1(Gaea.GeometryType.Point, pointlist);
578
+ // pointelement.Shape = pointgeometry;
579
+ // pointelement.NeedIntersectWithMesh = true;
580
+ // pointlist = []
581
+ console.log(pos, 'pospos');
582
+
583
+ },
584
+ false);
585
+ };
586
+ //移除鼠标点击事件
587
+ removeMouseUp = () => {
588
+ if (this.mouserUp) {
589
+ Gaea.World.Instance.ClearEvent(this.mouserUp);
590
+ this.mouserUp = null;
591
+ }
592
+ };
593
+ //监听滚动事件
594
+ addMouseWhill = (cb = null) => {
595
+ this.mouserWheel = Gaea.World.Instance.OnMouseWheel((p, b) => {
596
+ if (p == 1 || p == -1) {
597
+ const { Altitude } = Gaea.World.Instance.DefaultCamera;
598
+
599
+ debounce(() => {
600
+ console.log(Altitude);
601
+ if (Altitude < 60) {
602
+ Gaea.World.Instance.DefaultCamera.CameraZoomAcceleration = 0.01;
603
+ } else {
604
+ Gaea.World.Instance.DefaultCamera.CameraZoomAcceleration = 2.5;
605
+ }
606
+ console.log(Gaea.World.Instance.DefaultCamera.CameraZoomAcceleration);
607
+ rollerPower.value =
608
+ Gaea.World.Instance.DefaultCamera.CameraZoomAcceleration;
609
+ // Gaea.World.Instance.DefaultCamera.CameraZoomAcceleration = 2.5;
610
+ }, 2000);
611
+ }
612
+ });
613
+ };
614
+
615
+ //添加鼠标移动事件
616
+ addMouseMove = (cb = null) => {
617
+ this.mouseMove = Gaea.World.Instance.OnMouseMove((p, b) => {
618
+ var screenpos = new Gaea.Vector2(p.x, p.y);
619
+ var spacepos = Gaea.GaeaMath.ProjectPosition(screenpos);
620
+ var latlonalt = Gaea.GaeaMath.CartesianToSphericalDeg(spacepos);
621
+ // changeCoordinates(latlonalt.instance.x,latlonalt.instance.y,latlonalt.instance.z)
622
+ MoveCoordinates.value.x = latlonalt.instance.x;
623
+ MoveCoordinates.value.y = latlonalt.instance.y;
624
+ MoveCoordinates.value.z = latlonalt.instance.z;
625
+ // console.log(MoveCoordinates.value,'MoveCoordinates');
626
+ cb(MoveCoordinates.value);
627
+ });
628
+ };
629
+ //移除鼠标移动事件
630
+ removeMouseMove = () => {
631
+ if (this.mouseMove) {
632
+ Gaea.World.Instance.ClearEvent(this.mouseMove);
633
+ this.mouseMove = null;
634
+ }
635
+ };
636
+
637
+ // 降雨
638
+ WeatherManager = (WeatherManagerObj) => {
639
+ //开启全球大气
640
+ // var FullScreenQuad = Gaea.WeatherManager.ConvertBy(Gaea.World.Instance.GetNode("Camera/FullScreenQuad"));
641
+ // FullScreenQuad.Visible = true;
642
+
643
+ // //雨雪方向-1.5为右,1.5为左
644
+ // FullScreenQuad.WindDirection = -1.5;
645
+ // //雨雪速度 max:100,min:0
646
+ // FullScreenQuad.Speed = 30;
647
+ // //雨雪数量 max:100,min:0
648
+ // FullScreenQuad.Count = 30;
649
+ // //闪电频率 默认为4s
650
+ // FullScreenQuad.FlashFrequency = 1;
651
+ // //闪电强度
652
+ // FullScreenQuad.FlashFrequency = 4;
653
+ // switch (type) {
654
+ // case '雨':
655
+ // FullScreenQuad.Rainy = true;
656
+ // break;
657
+ // case '雪':
658
+ // FullScreenQuad.Snowy = true;
659
+ // break;
660
+ // case '闪电':
661
+ // FullScreenQuad.Flash = true;
662
+ // case '大气':
663
+ // FullScreenQuad.NeedAtmosphere = true;
664
+ // default:
665
+ // break;
666
+ // }
667
+ var sun = Gaea.Sun.ConvertBy(Gaea.World.Instance.GetNode("Sun"));
668
+ var environment = Gaea.Environment.ConvertBy(
669
+ Gaea.GaeaResourceLoader.Instance.LoadLoaclResource(
670
+ "res://default_env.tres"
671
+ )
672
+ );
673
+ var FullScreenQuad = Gaea.World.Instance.FullScreenQuad;
674
+ if (WeatherManagerObj.Rainy) {
675
+ FullScreenQuad.Visible = true;
676
+ FullScreenQuad.NeedAtmosphere = false;
677
+ sun.LightEnergy = 0.05;
678
+ environment.BackgroundEnergy = 0.11;
679
+ environment.GlowBlendMode = 1;
680
+ if (WeatherManagerObj.WindDirection) {
681
+ FullScreenQuad.WindDirection = WeatherManagerObj.WindDirection;
682
+ }
683
+ if (WeatherManagerObj.Speed) {
684
+ FullScreenQuad.Speed = WeatherManagerObj.Speed;
685
+ }
686
+ if (WeatherManagerObj.Count) {
687
+ FullScreenQuad.Count = WeatherManagerObj.Count;
688
+ }
689
+ } else {
690
+ FullScreenQuad.Visible = false;
691
+ FullScreenQuad.NeedAtmosphere = false;
692
+
693
+ sun.LightEnergy = 3.5;
694
+ environment.BackgroundEnergy = 0.2;
695
+ environment.GlowBlendMode = 2;
696
+ }
697
+ // console.log('降雨');
698
+ // // 降雨
699
+ // // var FullScreenQuad = Gaea.WeatherManager.ConvertBy(Gaea.World.Instance.GetNode("Camera/FullScreenQuad"));
700
+ // var FullScreenQuad = Gaea.World.Instance.FullScreenQuad;
701
+ // // FullScreenQuad.Visible = false;
702
+ // FullScreenQuad.Visible = true;
703
+ // FullScreenQuad.NeedAtmosphere = false;
704
+
705
+ // var sun = Gaea.Sun.ConvertBy(Gaea.World.Instance.GetNode("Sun"));
706
+ // var environment = Gaea.Environment.ConvertBy(Gaea.GaeaResourceLoader.Instance.LoadLoaclResource("res://default_env.tres"));
707
+ // // sun.TimeString = "2022-09-15 00:00:00";
708
+ // // sun.LightColor = new Gaea.Color(255 / 255, 255 / 255, 255 / 255, 1);
709
+ // // if (WeatherManagerObj.LightEnergy) { sun.LightEnergy = WeatherManagerObj.LightEnergy; }
710
+ // // if (WeatherManagerObj.BackgroundEnergy) { environment.BackgroundEnergy = WeatherManagerObj.BackgroundEnergy; }
711
+ // // if (WeatherManagerObj.GlowBlendMode) { environment.GlowBlendMode = WeatherManagerObj.GlowBlendMode; }
712
+ // FullScreenQuad.Rainy = WeatherManagerObj.Rainy;
713
+ // if (FullScreenQuad.Rainy) {
714
+ // sun.LightEnergy = 0.05;
715
+ // environment.BackgroundEnergy = 0.11;
716
+ // environment.GlowBlendMode = 1;
717
+ // } else {
718
+ // sun.LightEnergy = 3.5;
719
+ // environment.BackgroundEnergy = 0.2;
720
+ // environment.GlowBlendMode = 2;
721
+ // }
722
+ // if (WeatherManagerObj.WindDirection) { FullScreenQuad.WindDirection = WeatherManagerObj.WindDirection; }
723
+ // if (WeatherManagerObj.Speed) { FullScreenQuad.Speed = WeatherManagerObj.Speed; }
724
+ // if (WeatherManagerObj.Count) { FullScreenQuad.Count = WeatherManagerObj.Count; }
725
+ };
726
+
727
+ // 画点
728
+ DrawPointFuc = async (params, callback = () => { }) => {
729
+ const {
730
+ latitude,
731
+ longitude,
732
+ airpressure,
733
+ issueDate,
734
+ moveSpeed,
735
+ wind,
736
+ iconUrl,
737
+ pointType,
738
+ typhoonCode,
739
+ typhoonName,
740
+ namePY,
741
+ DrawPointClick,
742
+ DrawLineClick,
743
+ removeDashedPoint,
744
+ removeDashedLine,
745
+ addScreenForTyphoon,
746
+ removeScreenForTyphoon,
747
+ setPointData,
748
+ } = params;
749
+ //请求点的贴图,参数为(请求地址,保存为文件(带后缀))
750
+ var PointElement;
751
+ var PointIconMarkSymbol;
752
+ // await request(iconUrl, "图标.png");
753
+ await LoadResourceAsync(iconUrl);
754
+ const iconName = getFlieName(iconUrl);
755
+ var id = Gaea.GaeaResourceLoader.Instance.GetResource(iconName);
756
+ var tex = new Gaea.Texture(false);
757
+ tex.InstanceID = id + "";
758
+
759
+ // 点数组,(纬度,经度,到球心距离)
760
+ var Position = [];
761
+ var pos = new Gaea.Vector3(latitude, longitude, 30);
762
+ var elv = Gaea.World.Instance.DefaultTerrainAccessor.GetElevationAt(
763
+ latitude,
764
+ longitude,
765
+ 20
766
+ );
767
+ pos.z += pos.z + elv;
768
+ Position.push(pos);
769
+ // 根据坐标点创建几何对象,参数(几何形状类型,几何数据)
770
+ var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Point, Position);
771
+
772
+ // 创建PointGeometryElement对象
773
+ PointElement = new Gaea.PointGeometryElement();
774
+ // 赋值
775
+ PointElement.Shape = geometry;
776
+ //设置点图标的样式,系统自带样式,可以不用设置
777
+ PointIconMarkSymbol = new Gaea.IconMarkSymbol();
778
+ //图标大小
779
+ PointIconMarkSymbol.MarkSize = 24;
780
+ //图片
781
+ PointIconMarkSymbol.Icon = tex;
782
+ // 点的层级
783
+ PointIconMarkSymbol.Priority = 6;
784
+ //样式赋给element
785
+ PointElement.Symbol = PointIconMarkSymbol;
786
+ // 允许点击
787
+ PointElement.EnablePick = true;
788
+ // 允许编辑
789
+ PointElement.EnableEdit = false;
790
+
791
+ // 允许在3Dtiles、管线、挖方等位置编辑
792
+ PointElement.NeedIntersectWithMesh = false;
793
+ //选中的回调事件
794
+ PointElement.SelectedCallBack(async (a, b, c, d, e, f) => {
795
+ if (c) {
796
+ //获取选中element
797
+ const selectelement = new Gaea.LineGeometryElement(false);
798
+ selectelement.InstanceID = a + "";
799
+
800
+ // 返回数据
801
+ setPointData(params);
802
+ }
803
+ });
804
+ // PointElement.VisibleRange = new Gaea.Vector2(
805
+ // 0, 1000000
806
+ // );
807
+ // 将Element加入到场景中
808
+ Gaea.World.Instance.RenderableObjectList.AddLast(PointElement);
809
+ // elements.push(PointElement);
810
+ //定位
811
+ // Gaea.World.Instance.DefaultCamera.SetPosition2(LATITUDE, LONGITUDE, 0, 1500, 0, 0)
812
+ callback(PointElement);
813
+ };
814
+
815
+ // 画线
816
+ DrawLineFuc = async (id, list, color) => {
817
+ let Position = [];
818
+ list.forEach((item) => {
819
+ Position.push(new Gaea.Vector3(item.x, item.y, item.z));
820
+ });
821
+
822
+ // 根据坐标点创建几何对象,参数(几何形状类型,几何数据)
823
+ var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Polyline, Position);
824
+ // 创建PointGeometryElement对象
825
+ var LineElement = new Gaea.LineGeometryElement();
826
+ LineElement.id = id;
827
+ // 赋值
828
+ LineElement.Shape = geometry;
829
+ // 允许点击
830
+ LineElement.EnablePick = false;
831
+ // 允许编辑
832
+ LineElement.EnableEdit = false;
833
+ // 允许在3Dtiles、管线、挖方等位置编辑
834
+ LineElement.NeedIntersectWithMesh = true;
835
+ //开启虚拟点
836
+ LineElement.EnableVirtualPoint = true;
837
+ LineElement.InitialLineColor = new Gaea.Color(color[0] / 255, color[1] / 255, color[2] / 255, 1)
838
+ //选中的回调事件
839
+ LineElement.SelectedCallBack((a, b, c, d, e, f) => {
840
+ if (c) {
841
+ //获取选中element
842
+ selectelement = new Gaea.LineGeometryElement(false);
843
+ selectelement.InstanceID = a + "";
844
+ }
845
+ else {
846
+ selectelement = null;
847
+ }
848
+ });
849
+ // 将Element加入到场景中
850
+ Gaea.World.Instance.RenderableObjectList.AddLast(LineElement);
851
+ this.elements.push(LineElement);
852
+ return LineElement;
853
+ };
854
+
855
+ drawPoint = (item) => {
856
+ var pointelement = new Gaea.PointGeometryElement();//创建点element
857
+ Gaea.World.Instance.RenderableObjectList.AddLast(pointelement);
858
+ pointelement.Visible = true;
859
+ var Position = [];
860
+ var pos = new Gaea.Vector3(item.x, item.y, 1);
861
+ var elv = Gaea.World.Instance.DefaultTerrainAccessor.GetElevationAt(
862
+ item.x,
863
+ item.y,
864
+ item.z
865
+ );
866
+ pos.z += pos.z + elv;
867
+ Position.push(pos);
868
+ var pointgeometry = Gaea.Geometry.Create1(Gaea.GeometryType.Point, Position);
869
+ pointelement.Shape = pointgeometry;
870
+ pointelement.NeedIntersectWithMesh = true;
871
+ }
872
+
873
+ // 移除点
874
+ removePoint = (list) => {
875
+ list.forEach((value) => {
876
+ Gaea.World.Instance.RenderableObjectList.Remove(value.PointElement);
877
+ });
878
+ };
879
+
880
+ // 移除线
881
+ removeLine = (list) => {
882
+ list.forEach((value) => {
883
+ Gaea.World.Instance.RenderableObjectList.Remove(value.LineElement);
884
+ });
885
+ };
886
+
887
+ // 画多边形
888
+ AddCircle = (params, callback = () => { }) => {
889
+ const { pointradius, latitude, longitude, colorList, positions } = params;
890
+ // const PointElements = []
891
+
892
+ //获取当前的点坐标
893
+ var latlon = new Gaea.Vector3(latitude, longitude, 0);
894
+ // var point = turf.point([latlon.y, latlon.x]);
895
+ // var buffered = turf.buffer(point, pointradius, { units: 'meters' });
896
+ // var positions = []
897
+ // for (var i = 0; i < buffered.geometry.coordinates[0].length; i++) {
898
+ // var hei = Gaea.World.Instance.DefaultTerrainAccessor.GetElevationAt(buffered.geometry.coordinates[0][i][1], buffered.geometry.coordinates[0][i][0], 20);
899
+ // var position = new Gaea.Vector3(buffered.geometry.coordinates[0][i][1], buffered.geometry.coordinates[0][i][0], hei);
900
+ // positions.push(position);
901
+ // }
902
+ var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Polygon, positions);
903
+ // 创建PolygonGeometryElement对象
904
+ var Element = new Gaea.PolygonGeometryElement();
905
+ // 赋值
906
+ Element.Shape = geometry;
907
+ // 允许点击
908
+ Element.EnablePick = false;
909
+ // 允许编辑
910
+ Element.EnableEdit = false;
911
+ // 允许在3Dtiles、管线、挖方等位置编辑
912
+ Element.NeedIntersectWithMesh = false;
913
+
914
+ // 改变面的颜色
915
+ Element.InitialFillColor = new Gaea.Color(0, 0, 0, 0);
916
+ // 改变线的颜色
917
+ var ElementSymbol = Gaea.SimpleFillSymbol.ConvertBy(Element.Symbol);
918
+ ElementSymbol.OutLineSymbol.SymbolColor = new Gaea.Color(
919
+ colorList[0],
920
+ colorList[1],
921
+ colorList[2],
922
+ 1
923
+ );
924
+ // 改变线的类型
925
+ ElementSymbol.OutLineSymbol.LineStyle = 1;
926
+ ElementSymbol.OutLineSymbol.RepeatTimes = 100;
927
+
928
+ //开启虚拟点
929
+ Element.EnableVirtualPoint = false;
930
+ // Element.Symbol = symbol;
931
+ // 将Element加入到场景中
932
+ Gaea.World.Instance.RenderableObjectList.AddLast(Element);
933
+ callback(Element);
934
+ // PointElements.push(Element);
935
+ // //调用画点工具
936
+ // var tool = new Gaea.DrawPointTool();
937
+ // //切换工具时,是否清除当前的element,默认为true
938
+ // tool.DeleteElementOnDispose = false;
939
+ // //绘制完成,是否创建Element,默认为true
940
+ // tool.CreateElementOnCompleted = true;
941
+ // //工具是否与gltf等实体交互,默认为true
942
+ // tool.NeedIntersectWithMesh = false;
943
+ // //将当前工具挂载在世界节点
944
+ // Gaea.World.Instance.SetCurrentTool(tool);
945
+ // tool.OverDraw = () => {
946
+ // tool.Element.EnableEdit = false;
947
+ // tool.Element.EnablePick = false;
948
+ // // primitivepoints.push(tool.Element);
949
+
950
+ // }
951
+ };
952
+
953
+ // 移除圆形
954
+ removeCircle = (element) => {
955
+ Gaea.World.Instance.RenderableObjectList.Remove(element);
956
+ };
957
+ // 集雨区面
958
+ addPolygon = async (jyqJson) => {
959
+ const resData = await (await fetch(jyqJson)).json();
960
+ let pointList = resData.features;
961
+ console.log("-增加面数据json--", pointList);
962
+
963
+ var Position = [];
964
+ pointList.forEach((item) => {
965
+ item.geometry.coordinates[0].forEach((item1) => {
966
+ Position.push(new Gaea.Vector3(item1[1], item1[0], 10000));
967
+ });
968
+ });
969
+ // 根据坐标点创建几何对象,参数(几何形状类型,几何数据)
970
+ var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Polygon, Position);
971
+ // 创建PointGeometryElement对象
972
+ var Element = new Gaea.PolygonGeometryElement();
973
+ // 赋值
974
+ Element.Shape = geometry;
975
+ // 允许点击
976
+ Element.EnablePick = true;
977
+ // 允许编辑
978
+ Element.EnableEdit = false;
979
+ // 允许在3Dtiles、管线、挖方等位置编辑
980
+ Element.NeedIntersectWithMesh = false;
981
+ //开启虚拟点
982
+ Element.VirtualHelperIcon = false;
983
+
984
+ // if (styleThreeForm.orContrastColor) {
985
+ // Element.InitialFillColor = new Gaea.Color(this.changeRgba(styleThreeForm.color)[0], this.changeRgba(styleThreeForm.color)[1], this.changeRgba(styleThreeForm.color)[2], styleThreeForm.transparency / 100);//填充颜色
986
+ // } else {
987
+ // Element.InitialFillColor = new Gaea.Color(13 / 255, 64 / 255, 209 / 255, 0);//填充颜色
988
+
989
+ // }
990
+ // var PolygonSimpleFillSymbol = Gaea.SimpleFillSymbol.ConvertBy(Element.Symbol);
991
+ // PolygonSimpleFillSymbol.HasOutLine = styleThreeForm.orBorder //显示边框 true
992
+ // // 显示边框
993
+ // if (styleThreeForm.orBorder) {
994
+ // Element.InitialLineColor = new Gaea.Color(this.changeRgba(styleThreeForm.borderColor)[0], this.changeRgba(styleThreeForm.borderColor)[1], this.changeRgba(styleThreeForm.borderColor)[2], styleThreeForm.borderTransparency / 100);//边框颜色
995
+ // // PolygonSimpleFillSymbol.OutLineSymbol.LineWidth = styleThreeForm.borderWidth;
996
+
997
+ // }
998
+
999
+ // // 将Element加入到场景中
1000
+ Gaea.World.Instance.RenderableObjectList.AddLast(Element);
1001
+ // RiverEditTool.AddPolygonGeometryElement(Element);
1002
+ // Element.SelectedCallBack((a, b, c, d, e, g) => {
1003
+ // if (c) {
1004
+
1005
+ // }
1006
+ // });
1007
+
1008
+ // jyqpolygonElement.push(Element)
1009
+ const parts = jyqJson.split("/");
1010
+ const lastItem = parts[parts.length - 1]; // 获取部分(深圳水库集雨区.geojson)
1011
+ const jyqName = lastItem.split(".")[0];
1012
+ jyqpolygonElement.push({
1013
+ Element: Element,
1014
+ jyq: jyqName,
1015
+ });
1016
+
1017
+ // callback(Element)
1018
+ };
1019
+ // 移除集雨区面
1020
+ removejyqPolygon() {
1021
+ if (jyqpolygonElement.length) {
1022
+ jyqpolygonElement.forEach((item) => {
1023
+ Gaea.World.Instance.RenderableObjectList.Remove(item.Element);
1024
+ });
1025
+ }
1026
+ }
1027
+
1028
+ changeJYQcolor(jyqArr) {
1029
+ console.log("-----jyqArr", jyqArr);
1030
+ console.log("-----jyqpolygonElement", jyqpolygonElement);
1031
+ // jyqpolygonElement.forEach(item=>{
1032
+ // if()
1033
+ // })
1034
+ }
1035
+ // 批量画点
1036
+ addMorePoint = async (screenObj, callback) => {
1037
+ const {
1038
+ iconUrl,
1039
+ selectIconUrl,
1040
+ jsonUrl,
1041
+ Field = "name",
1042
+ IconSize = 30,
1043
+ FontSize = 30,
1044
+ fontColor,
1045
+ fontOutLineColor,
1046
+ min,
1047
+ max,
1048
+ } = screenObj;
1049
+ //请求点的贴图,参数为(请求地址,保存为文件(带后缀))
1050
+ var PointElement;
1051
+ var PointIconMarkSymbol;
1052
+ // await request(iconUrl, "图标.png");
1053
+ await LoadResourceAsync(iconUrl);
1054
+ const iconName = getFlieName(iconUrl);
1055
+ var id = Gaea.GaeaResourceLoader.Instance.GetResource(iconName);
1056
+ var tex = new Gaea.Texture(false);
1057
+ tex.InstanceID = id + "";
1058
+ const resData = await (await fetch(jsonUrl)).json();
1059
+ let pointList = resData.features;
1060
+
1061
+ // 点数组,(纬度,经度,到球心距离)
1062
+ var Position = [];
1063
+ pointList.forEach((item) => {
1064
+ var pos = new Gaea.Vector3(
1065
+ item.geometry.coordinates[1],
1066
+ item.geometry.coordinates[0],
1067
+ 30
1068
+ );
1069
+ var elv = Gaea.World.Instance.DefaultTerrainAccessor.GetElevationAt(
1070
+ item.geometry.coordinates[1],
1071
+ item.geometry.coordinates[0],
1072
+ 20
1073
+ );
1074
+ pos.z += pos.z + elv;
1075
+ Position.push(pos);
1076
+ });
1077
+ // 根据坐标点创建几何对象,参数(几何形状类型,几何数据)
1078
+ // var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Point, Position);
1079
+ var geometry = Gaea.Geometry.Create1(
1080
+ Gaea.GeometryType.MultiPoint,
1081
+ Position
1082
+ );
1083
+
1084
+ // 创建PointGeometryElement对象
1085
+ PointElement = new Gaea.PointGeometryElement();
1086
+ // 赋值
1087
+ PointElement.Shape = geometry;
1088
+ //设置点图标的样式,系统自带样式,可以不用设置
1089
+ PointIconMarkSymbol = new Gaea.IconMarkSymbol();
1090
+ //图标大小
1091
+ PointIconMarkSymbol.MarkSize = IconSize || 24;
1092
+ //图片
1093
+ PointIconMarkSymbol.Icon = tex;
1094
+ // 点的层级
1095
+ PointIconMarkSymbol.Priority = 6;
1096
+ //样式赋给element
1097
+ PointElement.Symbol = PointIconMarkSymbol;
1098
+ // 允许点击
1099
+ PointElement.EnablePick = true;
1100
+ // 允许编辑
1101
+ PointElement.EnableEdit = false;
1102
+
1103
+ // 允许在3Dtiles、管线、挖方等位置编辑
1104
+ PointElement.NeedIntersectWithMesh = false;
1105
+ //选中的回调事件
1106
+ PointElement.SelectedCallBack(async (a, b, c, d, e, f) => {
1107
+ if (c) {
1108
+ //获取选中element
1109
+ const selectelement = new Gaea.LineGeometryElement(false);
1110
+ selectelement.InstanceID = a + "";
1111
+ }
1112
+ });
1113
+ PointElement.VisibleRange = new Gaea.Vector2(min || 0, max || 100000);
1114
+ // 将Element加入到场景中
1115
+ Gaea.World.Instance.RenderableObjectList.AddLast(PointElement);
1116
+ // elements.push(PointElement);
1117
+ //定位
1118
+ // Gaea.World.Instance.DefaultCamera.SetPosition2(LATITUDE, LONGITUDE, 0, 1500, 0, 0)
1119
+ callback(PointElement);
1120
+ };
1121
+
1122
+ // 移除批量点
1123
+ removeMorePoint = (flayer) => {
1124
+ Gaea.World.Instance.RenderableObjectList.Remove(flayer);
1125
+ };
1126
+
1127
+ // 定位
1128
+ gaeaLocation = (obj) => {
1129
+ const { lat, lon, altitude } = obj;
1130
+ Gaea.World.Instance.DefaultCamera.SetPosition2(
1131
+ lat,
1132
+ lon,
1133
+ 0,
1134
+ altitude || 1500,
1135
+ 0,
1136
+ 0
1137
+ );
1138
+ };
1139
+
1140
+ //添加公告牌
1141
+ addScreenElement = async (screenparams, callback = () => { }) => {
1142
+ // const { Name, lat, lon, width, height, left, top, anchorType, onClick = () => { }, divId, visibleRange, elevation } = screenparams
1143
+ const {
1144
+ Name,
1145
+ lat,
1146
+ lon,
1147
+ width,
1148
+ height,
1149
+ left,
1150
+ top,
1151
+ anchorType,
1152
+ divId,
1153
+ min,
1154
+ max,
1155
+ elevation,
1156
+ } = screenparams;
1157
+ // const geojsonFileName = getFlieName(jsonUrl)
1158
+ // console.log(geojsonFileName,'geojsonFileName');
1159
+ const screen = new Gaea.ScreenGUIElement();
1160
+ screen.Name = Name;
1161
+ if (screenparams.divId) {
1162
+ screen.DivID = divId;
1163
+ const root = new Gaea.Control();
1164
+ root.MouseFilter = 2;
1165
+ root.RectSize = new Gaea.Vector2(width || 150, height || 100);
1166
+ // root.RectSize = new Gaea.Vector2(width || 0, height || 0);
1167
+ screen.Root = root;
1168
+ } else {
1169
+ screen.Root = this.InitUI(screenparams.ui);
1170
+ }
1171
+ // 标签的地理坐标
1172
+ screen.GeographyPosition = new Gaea.Vector3(lat, lon, elevation || 0);
1173
+ // 标签默认位置为左上角
1174
+ screen.ScreenOffset = new Gaea.Vector2(left || 50, top || -100);
1175
+ // screen.ScreenOffset = new Gaea.Vector2(left || 0, top || 0);
1176
+ // screen.ScreenOffset = new Gaea.Vector2(-72, -130);
1177
+ screen.ConnectAnchor = anchorType || 6;
1178
+ screen.DrawLine = false;
1179
+ // if (anchorType) {
1180
+ // screen.CnnectAnchor = Gaea.AnchorType[anchorType];
1181
+ // } else {
1182
+ // screen.ConnectAnchor = Gaea.AnchorType.LeftDown;
1183
+ // }
1184
+ // 开启点击事件 默认为false
1185
+ screen.EnablePick = true;
1186
+ screen.VisibleRange = new Gaea.Vector2(min || 0, max || 10000);
1187
+ // screen.Visible = true;
1188
+ // screen.UseAutoVisible();
1189
+ screen.OnHitElement = () => {
1190
+ // onClick();
1191
+ };
1192
+ Gaea.World.Instance.RenderableObjectList.AddLast(screen);
1193
+ // Gaea.World.Instance.DefaultCamera.SetPosition2(lat,lon,0,1500,0,0);
1194
+ console.log("标签添加成功");
1195
+ callback(screen, divId);
1196
+ };
1197
+
1198
+ //移除广告牌标注
1199
+ removeScreenElement = (screen, divId, holdDiv) => {
1200
+ Gaea.World.Instance.RenderableObjectList.Remove(screen);
1201
+
1202
+ if (!holdDiv) {
1203
+ // 通过ID获取DOM元素
1204
+ var element = document.getElementById(divId);
1205
+
1206
+ // 如果该元素存在,则移除它
1207
+ if (element) {
1208
+ element.remove();
1209
+ } else {
1210
+ console.log("该盒子不存在");
1211
+ }
1212
+ }
1213
+ };
1214
+
1215
+ /**
1216
+ * 初始化容器
1217
+ * @param {*} text
1218
+ */
1219
+ InitUI = (text = [], size, name) => {
1220
+ // 边距容器 MouseFilter = 2 为不捕捉鼠标
1221
+ const root = new Gaea.TextureRect(); //父容器
1222
+ // root.Visible = show;
1223
+ if (name) {
1224
+ var tex = new Gaea.Texture(false);
1225
+ tex.InstanceID =
1226
+ Gaea.GaeaResourceLoader.Instance.GetResource(name).toString();
1227
+ root.Texture = tex; // 图片名称
1228
+
1229
+ root.Expand = true; // 开启图片缩放
1230
+ root.StretchMode = 6; // 缩放模式
1231
+ }
1232
+ // const root = new Gaea.Panel();
1233
+ root.MouseFilter = 2; // 鼠标移到标记上可以转动视角
1234
+ root.RectSize = new Gaea.Vector2(size[0], size[1]);
1235
+ // 居中布局容器
1236
+ const center = new Gaea.CenterContainer()
1237
+ center.MouseFilter = 2
1238
+ center.AnchorRight = 1
1239
+ center.AnchorBottom = 1
1240
+ center.MarginRight = 0
1241
+ center.MarginBottom = 0
1242
+ // 纵向排布容器
1243
+ const vbox = new Gaea.VBoxContainer()
1244
+ vbox.MouseFilter = 2
1245
+ text.forEach(item => {
1246
+ const label = new Gaea.Label()
1247
+ label.Text = item;
1248
+ vbox.AddChild(label, false)
1249
+ });
1250
+ center.AddChild(vbox, false)
1251
+ root.AddChild(center, false)
1252
+ return root
1253
+ };
1254
+
1255
+ AddTD = () => {
1256
+ //创建天地图影像对象
1257
+ var store = new Gaea.TDTWMTSImageStore();
1258
+ // 影像注记+PNG格式配置(经纬度投影)
1259
+ store.ServerUri = "https://t{0}.tianditu.gov.cn/cia_c/wmts";
1260
+ // 关键:FORMAT改为image/png(替换原有的tiles)
1261
+ store.FormatString = "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=c&FORMAT=image/png&TILECOL={0}&TILEROW={1}&TILEMATRIX={2}&tk={3}";
1262
+ // 同步修改ImageExtension为PNG
1263
+ store.ImageExtension = Gaea.ImageExtensionEnum.PNG;
1264
+ //天地图token
1265
+ store.TK = "63201cfd7df1e1bff7d88bb8baa32151";
1266
+ store.Name = "影像底图";
1267
+ store.LevelRange = new Gaea.Vector2(9, 15); //设置可见层级
1268
+ //添加到世界节点
1269
+ Gaea.World.Instance.DefaultPyramidTileSet.AddImageStore(store);
1270
+ // imgsoresTD.push(store);
1271
+ }
1272
+
1273
+ /***
1274
+ * 从获取的服务列表中添加图层
1275
+ * @param {String} layerName 影像图层名称
1276
+ */
1277
+ addLayer = (layerObj, callback = () => { }) => {
1278
+ const {
1279
+ layerName,
1280
+ max,
1281
+ min,
1282
+ transparency,
1283
+ forMat = "image/vnd.jpeg-png",
1284
+ inserIndex = null,
1285
+ } = layerObj;
1286
+
1287
+ let forMatTypeList = [
1288
+ "image/jpeg",
1289
+ "image/png",
1290
+ "image/tga",
1291
+ "image/webp",
1292
+ "image/bmp",
1293
+ "application/json;type=geojson",
1294
+ "image/vnd.jpeg-png",
1295
+ ];
1296
+ let forMatType = forMatTypeList.indexOf(forMat);
1297
+ if (forMatType === -1) {
1298
+ console.warn("暂无当前图层类型");
1299
+ }
1300
+ var ts_ibo_c;
1301
+ var tileset = Gaea.World.Instance.DefaultPyramidTileSet;
1302
+ if (this.layers == null) return;
1303
+ //创建图层对象
1304
+ ts_ibo_c = new Gaea.WMTSImageStore();
1305
+ ts_ibo_c.ImageExtension = forMatType;
1306
+ //拿出图层对象
1307
+ var zcq = this.layers.filter((i) => i.Title == layerName)[0];
1308
+ ts_ibo_c.CurrentCapabilitie = zcq;
1309
+ //设置最大最小显示层级
1310
+ if (max) {
1311
+ ts_ibo_c.LevelRange = new Gaea.Vector2(min, max);
1312
+ }
1313
+ if (transparency) {
1314
+ ts_ibo_c.ImageTransparency = transparency
1315
+ }
1316
+ //如果存在该对象,instanceID为空或者0
1317
+ if (!ts_ibo_c.CurrentCapabilitie.InstanceID) {
1318
+ console.error(`${layerName}图层加载异常`);
1319
+ } else {
1320
+ //设置影像图层的层级
1321
+ if (inserIndex !== null) {
1322
+ tileset.InsertImageStore(ts_ibo_c, inserIndex);
1323
+ } else {
1324
+ tileset.AddImageStore(ts_ibo_c);
1325
+ }
1326
+ console.log(`影像${layerName}添加成功`);
1327
+ return ts_ibo_c;
1328
+ }
1329
+ };
1330
+
1331
+
1332
+ /***
1333
+ * 移除图层
1334
+ * @param {String} layerName 影像图层名称
1335
+ */
1336
+ removeLayer = ({ layerName, layerElement }) => {
1337
+ var tileset = Gaea.World.Instance.DefaultPyramidTileSet;
1338
+ tileset.RemoveImageStore(layerElement);
1339
+ console.log(`影像${layerName}移除成功`);
1340
+ };
1341
+ //添加VTS图层
1342
+ addVts = (vtsObj, callback = () => { }) => {
1343
+ let { vtsName, LineWidth, lineColor, height, max, min } = vtsObj;
1344
+ var lineSymbol = new Gaea.LineSymbol(); //创建线符号
1345
+ lineSymbol.DepthTestEnable = true; //深度检测
1346
+ lineSymbol.LineWidth = LineWidth || 20; //设置宽度
1347
+ // Symbol.LineColor = RgbcolorToGaeaColor(lineColor) || RgbcolorToGaeaColor("rgb(255,0,0)") //设置颜色
1348
+ lineSymbol.LineColor =
1349
+ RbgColorToVector3(lineColor) || RbgColorToVector3("rgb(255,92,0)");
1350
+ lineSymbol.EmissionPower = 100;
1351
+ // lineSymbol.EmissionPower = 1;
1352
+ lineSymbol.HeightOffset = height || 0; //设置高度偏移
1353
+ const cap = this.layers.find((i) => i.Title == vtsName); // 从服务列表layers中加载需要的矢量线服务
1354
+ var store = new Gaea.WMTSVectorStore();
1355
+ console.log(store);
1356
+ store.Init(cap);
1357
+ store.ImageExtension = Gaea.ImageExtensionEnum.GEOJSON;
1358
+ if (max) {
1359
+ store.LevelRange = new Gaea.Vector2(min, max); //设置可见层级
1360
+ }
1361
+ store.DefaultSymbol = lineSymbol; //设置符号样式
1362
+ Gaea.World.Instance.DefaultVectorPyramidTileSet.AddImageStore(store);
1363
+ Gaea.World.Instance.WorldEnvironment.Environment.GlowEnabled = false;
1364
+ callback(store);
1365
+ };
1366
+
1367
+ /***
1368
+ * 贴地线加载
1369
+ * @param {String} name 图层名称
1370
+ * @param {Array} range 显示范围
1371
+ * @param {Array} color 图层颜色
1372
+ * @param {Number} index 图层层级
1373
+ */
1374
+ AddVTSLine = async ({ name, range, color, index }) => {
1375
+ //贴地符号
1376
+ var symbol = new Gaea.GroundPolylineSymbol();
1377
+ symbol.Width = 2;
1378
+ symbol.LineColor = new Gaea.Color(color[0] / 255, color[1] / 255, color[2] / 255, 1);
1379
+ symbol.Priority = index;
1380
+ var render = new Gaea.SimpleFeatureRenderer();
1381
+ render.Symbol = symbol;
1382
+ //服务名称,省界2
1383
+ await this.CreateFeature(name, new Gaea.Vector2(range[0], range[1]), render);
1384
+ return render;
1385
+ }
1386
+
1387
+ //移除vts图层
1388
+ RemoveVts = ({ vtsName, vtsData }) => {
1389
+ Gaea.World.Instance.DefaultVectorPyramidTileSet.RemoveImageStore(Gaea.WMTSVectorStore.ConvertBy(Gaea.World.Instance.DefaultVectorPyramidTileSet.GetImageStore(vtsName)));
1390
+ console.log(`vts影像${vtsName}移除成功`);
1391
+
1392
+ // 从数组中也将元素删除
1393
+ const targetIndex = groundLineList.value.findIndex(item => item.name === vtsName);
1394
+ if (targetIndex !== -1) {
1395
+ groundLineList.value.splice(targetIndex, 1); // 删除当前索引的1个元素
1396
+ }
1397
+ };
1398
+
1399
+
1400
+ AddVTSLineText = async ({ name, range, color, Field }) => {
1401
+ // var symbol = new Gaea.LineSymbol()
1402
+ // symbol.LineWidth = 1;
1403
+ // symbol.LineColor = new Gaea.Color(color[0] / 255, color[1] / 255, color[2] / 255, 1);
1404
+
1405
+ // var render5 = new Gaea.SimpleFeatureRenderer();
1406
+ // render5.Symbol = symbol;
1407
+ // await this.CreateFeature(name, new Gaea.Vector2(range[0], range[1]), render5,);
1408
+
1409
+ var symbolText = new Gaea.TextMarkSymbol()
1410
+ symbolText.MarkSize = 20;
1411
+ symbolText.Field = Field;
1412
+ symbolText.FontColor = new Gaea.Color(color[0] / 255, color[1] / 255, color[2] / 255, 1);
1413
+
1414
+ //沿线标注
1415
+ var render = new Gaea.InstanceFeatureRenderer()
1416
+ render.RenderType = Gaea.RenderTypeEnum.Along;
1417
+ render.Symbol = symbolText
1418
+ await this.CreateFeature(name, new Gaea.Vector2(range[0], range[1]), render);
1419
+ }
1420
+
1421
+ CreateFeature = async (serviceName, levelRange, render, alias) => {
1422
+ const cap = this.layers.find((i) => i.Title == serviceName); // 从服务列表layers中加载需要的矢量线服务
1423
+ var store = new Gaea.WMTSVectorStore();
1424
+ store.Name = alias == null ? serviceName : alias;
1425
+ store.Init(cap);
1426
+ store.ImageExtension = Gaea.ImageExtensionEnum.GEOJSON;
1427
+ store.LevelRange = levelRange;
1428
+ if (render != null) store.DefaultRenderer = render;
1429
+ Gaea.World.Instance.DefaultVectorPyramidTileSet.AddImageStore(store);
1430
+ this.vectorServiceList.push(store);
1431
+ };
1432
+
1433
+ /***
1434
+ * 添加图片标注
1435
+ * @param {String} image bs64图片地址||图片路径
1436
+ * @param {Array} extent 图片的位置
1437
+ * @return {Number} 图片的id
1438
+ */
1439
+
1440
+ // addImage = async (image, extent, callback) => {
1441
+
1442
+ // const reg =
1443
+ // /^\s*data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s]*?)\s*$/i;
1444
+ // if (reg.test(image)) {
1445
+ // // ---------------------分割线---下面是base64图片导入-----------------
1446
+ // //加载base64图片
1447
+ // var base64 = image;
1448
+ // var img = base64.replace(/^data:image\/\w+;base64,/, "");
1449
+ // let flieName = uuid();
1450
+ // //base64加载图片至图片数据库
1451
+ // var id = Gaea.GaeaResourceLoader.Instance.LoadResourceFromBase64(
1452
+ // img,
1453
+ // flieName + ".png"
1454
+ // );
1455
+ // console.log(id);
1456
+ // var path = "user://resources/" + flieName + ".png";
1457
+
1458
+ // // console.log(path);
1459
+ // var invalidColor = new Gaea.Color(0, 0, 0, 1);
1460
+ // //渲染图片
1461
+ // // var imageId = Gaea.DecalManager.Instance.CreateItem(
1462
+ // // extent[3],
1463
+ // // extent[1],
1464
+ // // extent[0],
1465
+ // // extent[2],
1466
+ // // invalidColor,
1467
+ // // path
1468
+ // // );
1469
+ // var imageId = Gaea.DecalManager.Instance.CreateItem(
1470
+ // extent[0],
1471
+ // extent[1],
1472
+ // extent[2],
1473
+ // extent[3],
1474
+ // invalidColor,
1475
+ // path
1476
+ // );
1477
+ // console.log(imageId);
1478
+ // return imageId;
1479
+ // } else {
1480
+ // // ---------------------分割线---下面是imgae图片导入-----------------
1481
+ // // 加载静态图片
1482
+ // var flieName = getFlieName(image);
1483
+ // console.log(flieName);
1484
+ // await this.LoadResourceFromUrl(image, flieName);
1485
+ // var path = "user://resources/" + flieName;
1486
+
1487
+ // // console.log(path);
1488
+ // // console.log(path);
1489
+ // var invalidColor = new Gaea.Color(0, 0, 0, 1);
1490
+ // //渲染图片
1491
+ // // var imageId = Gaea.DecalManager.Instance.CreateItem(
1492
+ // // extent[3],
1493
+ // // extent[1],
1494
+ // // extent[0],
1495
+ // // extent[2],
1496
+ // // invalidColor,
1497
+ // // path
1498
+ // // );
1499
+ // var imageId = Gaea.DecalManager.Instance.CreateItem(
1500
+ // extent[0],
1501
+ // extent[1],
1502
+ // extent[2],
1503
+ // extent[3],
1504
+ // invalidColor,
1505
+ // path
1506
+ // );
1507
+ // console.log(imageId);
1508
+ // callback(imageId);
1509
+ // }
1510
+ // };
1511
+ /***
1512
+ * 移除图片标注
1513
+ * @param {Number} featureId 标注id
1514
+ * @return {Number} 标注的id
1515
+ */
1516
+ removeImage = (imageId) => {
1517
+ Gaea.DecalManager.Instance.RemoveItem(imageId);
1518
+ return imageId;
1519
+ };
1520
+ //切换播放云图函数
1521
+ addYtImage = async (imgList, extend, callback = () => { }) => {
1522
+ const stepTime = 2000;
1523
+ let i = 0;
1524
+ var invalidColor = new Gaea.Color(0, 0, 0, 1);
1525
+ const timerFn = async () => {
1526
+ let element = imgList[i];
1527
+ await this.LoadResourceFromUrl(element.url, element.name);
1528
+ if (ytImageId) {
1529
+ Gaea.DecalManager.Instance.RemoveItem(ytImageId);
1530
+ ytImageId = null;
1531
+ }
1532
+ i++;
1533
+ ytImageId = Gaea.DecalManager.Instance.CreateItem(
1534
+ extend[0],
1535
+ extend[1],
1536
+ extend[2],
1537
+ extend[3],
1538
+ invalidColor,
1539
+ "user://resources/" + element.name
1540
+ );
1541
+ callback(element.date);
1542
+ if (i === imgList.length) {
1543
+ i = 0;
1544
+ }
1545
+ };
1546
+ timerFn();
1547
+ ytTimer = setInterval(timerFn, stepTime);
1548
+ };
1549
+ //移除云图演变效果
1550
+ removeYtImage = () => {
1551
+ clearInterval(ytTimer);
1552
+ if (ytImageId) {
1553
+ Gaea.DecalManager.Instance.RemoveItem(ytImageId);
1554
+ ytImageId = null;
1555
+ }
1556
+ };
1557
+ //添加iconFont标注
1558
+ addSymbol = async (SymbolObj, callback = () => { }) => {
1559
+ let { jsonUrl, IconStyle, FontStyle, max, min } = SymbolObj;
1560
+
1561
+ var iconurl = IconStyle?.IconUrl;
1562
+ let fileName = getFlieName(jsonUrl);
1563
+ if (iconurl) {
1564
+ await LoadResourceAsync(iconurl);
1565
+ }
1566
+ await LoadResourceAsync(jsonUrl);
1567
+
1568
+ var ws = Gaea.WorkspaceFactory.OpenFromFile(`user://resources/${fileName}`);
1569
+ var fclass = ws.OpenFeatureClass(true, false);
1570
+
1571
+ var Symbol = new Gaea.CompositeSymbol();
1572
+ Symbol.HeightOffset = 5000;
1573
+ var Field = FontStyle?.Field;
1574
+ //配置文字样式
1575
+ if (Field) {
1576
+ var textSymbol = new Gaea.TextMarkSymbol();
1577
+ textSymbol.MarkSize = FontStyle?.FontSize || 20;
1578
+ textSymbol.Field = FontStyle?.Field || "Name";
1579
+ textSymbol.Fontgap = 0.5;
1580
+ //["Left","Right","Up","Down"]
1581
+ if (FontStyle?.FontColor?.length > 0) {
1582
+ textSymbol.FontColor = RgbcolorToGaeaColor(FontStyle.FontColor);
1583
+ textSymbol.OutLineColor = RgbcolorToGaeaColor(
1584
+ FontStyle.FontoOutLineColor
1585
+ );
1586
+ }
1587
+ textSymbol.Anchor = FontStyle?.FontAnchor
1588
+ ? Gaea.AnchorType[FontStyle.FontAnchor]
1589
+ : Gaea.AnchorType.Right;
1590
+ Symbol.AddSymbol(textSymbol);
1591
+ }
1592
+
1593
+ // //配置icon样式
1594
+ if (iconurl) {
1595
+ var iconSymbol = new Gaea.IconMarkSymbol();
1596
+
1597
+ iconSymbol.MarkSize = IconStyle?.IconSize || 20;
1598
+ var tex_id = Gaea.GaeaResourceLoader.Instance.GetResource(
1599
+ getFlieName(iconurl)
1600
+ );
1601
+ var tex = new Gaea.Texture(false);
1602
+ var tex1 = Gaea.GaeaResourceLoader.Instance.LoadLoaclResource(
1603
+ "res://assets/images/warningIcon/warningIcon.res"
1604
+ );
1605
+ tex.InstanceID = tex_id + "";
1606
+ iconSymbol.Icon = tex1;
1607
+
1608
+ Symbol.AddSymbol(iconSymbol);
1609
+ }
1610
+
1611
+ var flayer = new Gaea.FeatureLayer();
1612
+ var FeatureRenderer = new Gaea.SimpleFeatureRenderer();
1613
+ FeatureRenderer.Symbol = Symbol;
1614
+ flayer.VisibleRange = new Gaea.Vector2(min, max);
1615
+ flayer.FeatureClass = fclass;
1616
+ flayer.FeatureRenderer = FeatureRenderer;
1617
+ // flayer.Priority = 100
1618
+
1619
+ callback(flayer);
1620
+ Gaea.World.Instance.RenderableObjectList.AddLast(flayer);
1621
+ };
1622
+ //移除iconFont标注
1623
+ removeSymbol = (flayer) => {
1624
+ Gaea.World.Instance.RenderableObjectList.Remove(flayer);
1625
+ };
1626
+ //添加自定义图标
1627
+ addSetPoint = async (pointObj, callback = () => { }) => {
1628
+ const {
1629
+ poitnData,
1630
+ iconUrl = `${serveLocal}/icon/当前位置.png`,
1631
+ FontColor,
1632
+ FontSize = 20,
1633
+ IconSize = 20,
1634
+ } = pointObj;
1635
+ const PointTextSymbol = new Gaea.TextMarkSymbol(); //创建字体符号
1636
+ const PointIconSymbol = new Gaea.IconMarkSymbol(); //创建图标
1637
+ // const iconUrl = `${serveLocal}/icon/当前位置.png`
1638
+ await LoadResourceAsync(iconUrl);
1639
+ const iconName = getFlieName(iconUrl);
1640
+ var id = Gaea.GaeaResourceLoader.Instance.GetResource(iconName);
1641
+ var tex = new Gaea.Texture(false);
1642
+ tex.InstanceID = id + "";
1643
+
1644
+ // var points = [
1645
+ // new Gaea.Vector3(34.5694745790576, 105.962108201382, 100), //社棠镇
1646
+ // new Gaea.Vector3(34.708176474057, 105.396793259202, 100), //六峰镇
1647
+ // new Gaea.Vector3(34.8066648907865, 105.454541877039, 100), //金山乡
1648
+ // new Gaea.Vector3(34.589829786221, 105.207673919421, 100),
1649
+ // new Gaea.Vector3(34.6822687130929, 105.31284238242, 100)
1650
+ // ];
1651
+ // var names = [
1652
+ // "社棠镇",
1653
+ // "六峰镇",
1654
+ // "金山乡",
1655
+ // "古坡乡",
1656
+ // "白家湾乡"
1657
+ // ]
1658
+ const points = poitnData.map((item) => {
1659
+ return new Gaea.Vector3(item.position.x, item.position.y, 100);
1660
+ });
1661
+ const names = poitnData.map((item) => {
1662
+ return item.name;
1663
+ });
1664
+ //创建组合符号
1665
+ var Symbol = new Gaea.CompositeSymbol();
1666
+ PointTextSymbol.MarkSize = FontSize; //设置大小
1667
+ PointTextSymbol.FontColor = new Gaea.Color(
1668
+ FontColor[0],
1669
+ FontColor[1],
1670
+ FontColor[2],
1671
+ FontColor[3]
1672
+ ); //设置颜色
1673
+ PointTextSymbol.Field = "name"; //显示字段名
1674
+ PointTextSymbol.HeightOffset = 0; //设置高度偏移
1675
+ PointTextSymbol.Anchor = Gaea.AnchorType.Up; //字体停靠方向
1676
+ PointTextSymbol.Fontgap = 0.5; //字体间距
1677
+ Symbol.AddSymbol(PointTextSymbol);
1678
+
1679
+ PointIconSymbol.HeightOffset = 0;
1680
+ PointIconSymbol.Icon = tex;
1681
+ PointIconSymbol.MarkSize = IconSize;
1682
+ Symbol.AddSymbol(PointIconSymbol);
1683
+
1684
+ const pointElements = [];
1685
+ for (var i = 0; i < points.length; i++) {
1686
+ var element = new Gaea.Element();
1687
+
1688
+ var pos = [points[i]];
1689
+ var Shape = Gaea.Geometry.Create1(Gaea.GeometryType.Point, pos);
1690
+ var Feature = new Gaea.Feature();
1691
+ var fields = new Gaea.Fields();
1692
+ var field = new Gaea.Field();
1693
+ field.Name = "name";
1694
+ fields.AddField(field);
1695
+ Feature.SetFields(fields);
1696
+ Feature.SetStringValue("name", names[i]);
1697
+ Feature.SetShape(Shape);
1698
+ var element = new Gaea.PointGeometryElement();
1699
+ element.Feature = Feature;
1700
+ element.Symbol = Symbol;
1701
+ Gaea.World.Instance.RenderableObjectList.AddLast(element);
1702
+ pointElements.push({
1703
+ name: names[i],
1704
+ element,
1705
+ });
1706
+ }
1707
+ callback(pointElements);
1708
+ };
1709
+ //移除自定义图标
1710
+ removeSetPoint = (pointElements) => {
1711
+ pointElements.forEach((item) => {
1712
+ Gaea.World.Instance.RenderableObjectList.Remove(item.element);
1713
+ });
1714
+ };
1715
+
1716
+ async addGeoJson(obj, cb = () => { }, cb1 = () => { }) {
1717
+ console.log(obj, obj.params.Field, "************");
1718
+ let names = obj.params.Field;
1719
+ // console.log(url, name, fieldName, minHeight, maxHeight, img, "************");
1720
+ // const layer = Gaea.World.Instance.RenderableObjectList.GetByName(layerName);
1721
+ // if (layer._InstanceID) {
1722
+ // layer.Visible = true;
1723
+ // layer.UseAutoVisible();
1724
+ // return;
1725
+ // }
1726
+ let imgName;
1727
+ Gaea.QueryServer.Instance.Enable = false;
1728
+ if (obj.labelImg) {
1729
+ imgName = obj.label;
1730
+ } else {
1731
+ imgName = "当前点位";
1732
+ }
1733
+ const iconUrl = obj.labelImg;
1734
+ const iconName = getFlieName(iconUrl);
1735
+ var id = Gaea.GaeaResourceLoader.Instance.GetResource(iconName);
1736
+ console.log("id:", id);
1737
+ if (id === 0) {
1738
+ // 说明第一次加载
1739
+ console.log("第一次加载资源");
1740
+ await LoadResourceAsync(iconUrl);
1741
+ // 再次获取一次
1742
+ id = Gaea.GaeaResourceLoader.Instance.GetResource(iconName);
1743
+ }
1744
+ // var id = Gaea.GaeaResourceLoader.Instance.GetResource("雨量1.png");
1745
+ let tex = new Gaea.ImageTexture(false);
1746
+ tex.InstanceID = id + "";
1747
+ const img1 = tex.GetData();
1748
+ img1.SrgbToLinear();
1749
+ tex.CreateFromImage(img1, 7);
1750
+ var res = "user://resources/";
1751
+ Gaea.GaeaResourceLoader.Instance.LoadResourceFromUrl1(
1752
+ `${serveLocal}/json/图层树/测试数据/${obj.params.jsonUrl}`,
1753
+ obj.params.jsonUrl,
1754
+ (code, msg) => {
1755
+ var ws = Gaea.WorkspaceFactory.OpenFromFile(res + obj.params.jsonUrl);
1756
+ var fclass = ws.OpenFeatureClass(true, false);
1757
+ var flayer = new Gaea.FeatureLayer();
1758
+ flayer.Name = obj.params.jsonUrl.split(".")[0];
1759
+ flayer.FeatureClass = fclass;
1760
+ // if (maxHeight) {
1761
+ // // flayer.VisibleRange = new Gaea.Vector2(Number(minHeight), Number(maxHeight));
1762
+ // } else {
1763
+ flayer.VisibleRange = new Gaea.Vector2(0, 100000000000);
1764
+ // }
1765
+ var icomSymbol = new Gaea.IconMarkSymbol();
1766
+ icomSymbol.MarkSize = 24;
1767
+ icomSymbol.Field = names;
1768
+ icomSymbol.Priority = 127;
1769
+ icomSymbol.UseMergedTextures = false;
1770
+ icomSymbol.AddIcon("default", tex);
1771
+ icomSymbol.Icon = tex;
1772
+ var textSymbol = new Gaea.TextMarkSymbol();
1773
+ textSymbol.TextOffset = 24;
1774
+ textSymbol.FontColor = new Gaea.Color(0.7, 0.8, 0.9, 1); // 字体颜色
1775
+ textSymbol.HoverColor = new Gaea.Color(0.7, 0.8, 0.9, 1); // 字体颜色
1776
+ textSymbol.Priority = 127;
1777
+ textSymbol.MarkSize = 24;
1778
+ textSymbol.Field = names;
1779
+ textSymbol.Anchor = Gaea.AnchorType.Up;
1780
+ var Symbol = new Gaea.CompositeSymbol();
1781
+ Symbol.AddSymbol(icomSymbol);
1782
+ Symbol.AddSymbol(textSymbol);
1783
+ const flayerArr = [];
1784
+ var FeatureRenderer = new Gaea.InstanceFeatureRenderer();
1785
+ FeatureRenderer.RenderType = Gaea.RenderTypeEnum.Collision;
1786
+ FeatureRenderer.Symbol = Symbol;
1787
+ window.flayer = flayer;
1788
+ FeatureRenderer.EnablePick = true;
1789
+ // FeatureRenderer.SelectedCallBack((fid) =>
1790
+ // {
1791
+ // console.log(fid,'----111222333');
1792
+
1793
+ // let node = fclass.GetFeature(fid);
1794
+ // let name = node.GetStringValue(names);
1795
+ // if (name && window.viewPoint) {
1796
+ // // try {
1797
+ // // setTimeout(() => {
1798
+ // // window.open(`/datas/pdf/${name}.pdf`)
1799
+ // // }, 100);
1800
+ // // } catch (error) {
1801
+ // // console.log(error);
1802
+ // // }
1803
+ // // cb(name);
1804
+ // }
1805
+ // });
1806
+ var compositeSymbol = new Gaea.CompositeSymbol(); // 组合符号
1807
+ compositeSymbol.AddSymbol(icomSymbol); // 加入图标符号
1808
+ compositeSymbol.AddSymbol(textSymbol); // 加入文字符号
1809
+ // HeightOffset = 100000,
1810
+ FeatureRenderer.Symbol = compositeSymbol; //设置渲染器的符号
1811
+ flayer.FeatureRenderer = FeatureRenderer; //设置图层中的渲染器, 即FeatureRenderer
1812
+ flayer.EnableCollision = true;
1813
+ flayer.EnablePick = true;
1814
+ FeatureRenderer.SelectedCallBackMessage((message, pos, name) => {
1815
+ cb1(name);
1816
+ console.log(message, pos, name, "---1111111");
1817
+ });
1818
+ console.log("---22222");
1819
+
1820
+ flayer.FeatureRenderer = FeatureRenderer;
1821
+ // flayer.FeatureRenderer = FeatureRenderer;
1822
+ // flayer.EnablePick = true
1823
+ // Gaea.World.Instance.CollisionManager.AddFeatureLayer(flayer);
1824
+ // flayer.EnableCollision = true;
1825
+ Gaea.World.Instance.RenderableObjectList.AddLast(flayer);
1826
+ flayerArr.push(flayer);
1827
+ cb(flayerArr);
1828
+ console.log("------添加geojson----完成", flayerArr);
1829
+ // });
1830
+ }
1831
+ );
1832
+ }
1833
+ removeGeoJson(symbolElement) {
1834
+ // debugger
1835
+ Gaea.World.Instance.RenderableObjectList.Remove(symbolElement);
1836
+ }
1837
+
1838
+ /**
1839
+ * 仅转换数组中第三个、第五个、第六个值(索引2、4、5)为角度
1840
+ * @param {number[]} values - 输入的数值数组,长度需至少为6
1841
+ * @returns {number[]} 转换后的数组(原数组不会被修改)
1842
+ */
1843
+ convertSpecificValues(values) {
1844
+ // 检查输入是否为数组且长度足够
1845
+ if (!Array.isArray(values) || values.length < 6) {
1846
+ throw new Error("输入必须是长度至少为6的数组");
1847
+ }
1848
+
1849
+ // 复制原数组,避免修改原数据
1850
+ const result = [...values];
1851
+ // 弧度转角度的换算系数(180/π)
1852
+ const radToDeg = 180 / Math.PI;
1853
+
1854
+ // 转换第三个值(索引2)
1855
+ result[2] = values[2] * radToDeg;
1856
+ // 转换第五个值(索引4)
1857
+ result[4] = values[4] * radToDeg;
1858
+ // 转换第六个值(索引5)
1859
+ result[5] = values[5] * radToDeg;
1860
+
1861
+ return result;
1862
+ }
1863
+
1864
+ /**
1865
+ * 高级定位
1866
+ * @param {Number} numStr 定位字符串
1867
+ * @return {void}
1868
+ **/
1869
+ SetPosition = (numStr) => {
1870
+ // 转换为纯数字数组
1871
+ const numArray = numStr
1872
+ .split(',') // 按逗号分割为字符串数组 → ["27.3436...", " 120.4490...", ...]
1873
+ .map(item => item.trim()) // 去除每个元素的前后空格 → ["27.3436...", "120.4490...", ...]
1874
+ .map(Number); // 转为数值类型 → [27.3436..., 120.4490..., ...]
1875
+ const camera = Gaea.World.Instance.DefaultCamera;
1876
+ // let posList = this.convertSpecificValues(numArray)
1877
+ camera.SetPosition2(numArray[0], numArray[1], numArray[2], numArray[3], numArray[4], numArray[5]);
1878
+ };
1879
+
1880
+ //记录当前坐标
1881
+ favorite = (cb = () => { }) => {
1882
+ var uri = Gaea.GaeaCamera.ConvertBy(Gaea.World.Instance.DefaultCamera).Favorite();
1883
+ cb(uri);
1884
+ return uri;
1885
+ };
1886
+ //定位到uri位置
1887
+ favoritePosition = (uri) => {
1888
+ var camera = Gaea.World.Instance.DefaultCamera;
1889
+ camera.GotoFavorite(uri);
1890
+ };
1891
+ //同步加载地形
1892
+ promiseTerrain = (url) => {
1893
+ return new Promise((resolve, reject) => {
1894
+ Gaea.World.Instance.InitTerrainServer2(url, () => {
1895
+ resolve();
1896
+ });
1897
+ });
1898
+ };
1899
+ /**
1900
+ * 加载地形
1901
+ * @param {String} url
1902
+ * @return {void}
1903
+ */
1904
+ addInitTerrainServer = () => {
1905
+ return new Promise(async (res, rej) => {
1906
+ let tarrainKeys = Object.keys(TerrainList);
1907
+ if (tarrainKeys.length === 0) {
1908
+ res();
1909
+ } else {
1910
+ for (let i = 0; i < tarrainKeys.length; i++) {
1911
+ const item = tarrainKeys[i];
1912
+ console.log(item);
1913
+ const urlItem = TerrainList[item];
1914
+ console.log(urlItem);
1915
+ await this.promiseTerrain(urlItem);
1916
+ if (i === tarrainKeys.length - 1) {
1917
+ res();
1918
+ }
1919
+ }
1920
+ }
1921
+ });
1922
+ };
1923
+ //使用三角网生成云图
1924
+ addDtsjw = async (params, callback = () => { }) => {
1925
+ const { imgList, res } = params;
1926
+ console.log("三角网url", imgList, res);
1927
+
1928
+ //设置三角网范围
1929
+ // var url = "http://localhost:9878/txt/output(1).json"
1930
+ vt = new Gaea.VertextGeometryElement();
1931
+ vt.DisplayType = Gaea.VertextGeometryElementDisplayType.Triangles; // 展示模式[Line(线模式),Triangles(面模式)]
1932
+ vt.NeedNormal = true; // 是否需要计算法线
1933
+ vt.VertextCoordinates = Gaea.VertextType.LatLon;
1934
+ vt.ParseJsonToObject(res);
1935
+ let i = 1;
1936
+ vt.Visible = false;
1937
+ Gaea.World.Instance.RenderableObjectList.AddLast(vt);
1938
+ vt.Commit();
1939
+
1940
+ vt.OnModelInit(async () => {
1941
+ let id1;
1942
+ let id2;
1943
+ let tex1;
1944
+ let tex2;
1945
+ //设置抬升高度
1946
+ vt.TranslateObjectLocal(new Gaea.Vector3(0, 5000, 0));
1947
+ // vt.GeographyPosition = new Gaea.Vector3(35, 127, 2000); // 修改模型位置
1948
+ const isometricRendering = new Gaea.EquivocalRenderingMaterial();
1949
+ isometricRendering.TrianglesInterpolationValue = 0; //插值系数
1950
+ isometricRendering.Transparency = 0.6;
1951
+ isometricRendering.RenderingType =
1952
+ Gaea.EquivocalRenderingType.PictureTrianglesInterpolation; // 渲染模式[Line(线渲染),ValueTriangles(值渲染),ValueTrianglesInterpolation(值插值渲染)]
1953
+ isometricRendering.UseUV = true;
1954
+ // isometricRendering.LinesColor = new Gaea.Color(1, 0.5, 0, 1); // 线渲染模式下的线颜色
1955
+ var spatial = Gaea.Spatial.ConvertBy(vt.GetChild(0));
1956
+ var meshInstance = Gaea.MeshInstance.ConvertBy(spatial.GetChild(0));
1957
+ meshInstance.CastShadow = 0; // 取消阴影
1958
+ meshInstance.MaterialOverride = isometricRendering;
1959
+
1960
+ //改变图片的逻辑
1961
+ const changeImg = async () => {
1962
+ if (i % 2 === 1) {
1963
+ await this.LoadResourceFromUrl(
1964
+ imageUrlApi + imgList[i - 1].baseUrl,
1965
+ imgList[i - 1].fileName
1966
+ );
1967
+ await this.LoadResourceFromUrl(
1968
+ imageUrlApi + imgList[i].baseUrl,
1969
+ imgList[i].fileName
1970
+ );
1971
+ vt.Visible = true;
1972
+ id1 = Gaea.GaeaResourceLoader.Instance.GetResource(
1973
+ imgList[i - 1].fileName
1974
+ );
1975
+ tex1 = new Gaea.Texture(false);
1976
+ tex1.InstanceID = id1 + "";
1977
+ // tex1.Flags = 0;
1978
+ id2 = Gaea.GaeaResourceLoader.Instance.GetResource(
1979
+ imgList[i].fileName
1980
+ );
1981
+ tex2 = new Gaea.Texture(false);
1982
+ tex2.InstanceID = id2 + "";
1983
+ // tex2.Flags = 0;
1984
+ }
1985
+
1986
+ if (i % 2 === 0) {
1987
+ await this.LoadResourceFromUrl(
1988
+ imageUrlApi + imgList[i - 1].baseUrl,
1989
+ imgList[i - 1].fileName
1990
+ );
1991
+ await this.LoadResourceFromUrl(
1992
+ imageUrlApi + imgList[i].baseUrl,
1993
+ imgList[i].fileName
1994
+ );
1995
+ id1 = Gaea.GaeaResourceLoader.Instance.GetResource(
1996
+ imgList[i - 1].fileName
1997
+ );
1998
+ tex1 = new Gaea.Texture(false);
1999
+ tex1.InstanceID = id2 + "";
2000
+ // tex1.Flags = 0;
2001
+ id2 = Gaea.GaeaResourceLoader.Instance.GetResource(
2002
+ imgList[i].fileName
2003
+ );
2004
+ tex2 = new Gaea.Texture(false);
2005
+ tex2.InstanceID = id1 + "";
2006
+ // tex2.Flags = 0;
2007
+ }
2008
+
2009
+ // meshInstance.RotateObjectLocal(Gaea.Vector3.Left, Gaea.Mathf.Deg2Rad(180)); // 旋转模型
2010
+ isometricRendering.DeduceValueTexture(tex1, tex2);
2011
+
2012
+ if (isometricRendering.TrianglesInterpolationValue === 0) {
2013
+ isometricRendering.TrianglesInterpolationValue === 1;
2014
+ } else if (isometricRendering.TrianglesInterpolationValue === 1) {
2015
+ isometricRendering.TrianglesInterpolationValue === 0;
2016
+ }
2017
+ callback(imgList[i].collectTime);
2018
+
2019
+ if (i >= imgList.length - 1) {
2020
+ i = 1;
2021
+ } else {
2022
+ i++;
2023
+ }
2024
+ };
2025
+
2026
+ // const changeImg = async () => {
2027
+ // if (i % 2 === 1) {
2028
+ // await this.LoadResourceFromUrl(
2029
+ // imgList[i - 1].imageUrl,
2030
+ // imgList[i - 1].fileName
2031
+ // );
2032
+ // await this.LoadResourceFromUrl(
2033
+ // imgList[i].imageUrl,
2034
+ // imgList[i].fileName
2035
+ // );
2036
+ // vt.Visible = true
2037
+ // id1 = Gaea.GaeaResourceLoader.Instance.GetResource(
2038
+ // imgList[i - 1].fileName
2039
+ // );
2040
+ // tex1 = new Gaea.Texture(false);
2041
+ // tex1.InstanceID = id1 + "";
2042
+ // // tex1.Flags = 0;
2043
+ // id2 = Gaea.GaeaResourceLoader.Instance.GetResource(
2044
+ // imgList[i].name
2045
+ // );
2046
+ // tex2 = new Gaea.Texture(false);
2047
+ // tex2.InstanceID = id2 + "";
2048
+ // // tex2.Flags = 0;
2049
+ // }
2050
+
2051
+ // if (i % 2 === 0) {
2052
+ // await this.LoadResourceFromUrl(
2053
+ // imgList[i - 1].imageUrl,
2054
+ // imgList[i - 1].fileName
2055
+ // );
2056
+ // await this.LoadResourceFromUrl(
2057
+ // imgList[i].imageUrl,
2058
+ // imgList[i].fileName
2059
+ // );
2060
+ // id1 = Gaea.GaeaResourceLoader.Instance.GetResource(
2061
+ // imgList[i - 1].fileName
2062
+ // );
2063
+ // tex1 = new Gaea.Texture(false);
2064
+ // tex1.InstanceID = id2 + "";
2065
+ // // tex1.Flags = 0;
2066
+ // id2 = Gaea.GaeaResourceLoader.Instance.GetResource(
2067
+ // imgList[i].fileName
2068
+ // );
2069
+ // tex2 = new Gaea.Texture(false);
2070
+ // tex2.InstanceID = id1 + "";
2071
+ // // tex2.Flags = 0;
2072
+ // }
2073
+
2074
+ // // meshInstance.RotateObjectLocal(Gaea.Vector3.Left, Gaea.Mathf.Deg2Rad(180)); // 旋转模型
2075
+ // isometricRendering.DeduceValueTexture(tex1, tex2);
2076
+
2077
+ // if (isometricRendering.TrianglesInterpolationValue === 0) {
2078
+ // isometricRendering.TrianglesInterpolationValue === 1
2079
+ // } else if (isometricRendering.TrianglesInterpolationValue === 1) {
2080
+ // isometricRendering.TrianglesInterpolationValue === 0
2081
+ // }
2082
+ // callback(imgList[i].date)
2083
+
2084
+ // if (i >= imgList.length - 1) {
2085
+ // i = 1
2086
+ // } else {
2087
+ // i++
2088
+ // }
2089
+ // }
2090
+ changeImg();
2091
+ ytTimer = setInterval(changeImg, 2000);
2092
+ });
2093
+ };
2094
+ //移除三角网
2095
+ removeDtsjw = () => {
2096
+ Gaea.World.Instance.RenderableObjectList.Remove(vt);
2097
+ if (ytTimer) {
2098
+ clearInterval(ytTimer);
2099
+ }
2100
+ };
2101
+
2102
+ // //监听鼠标点击事件
2103
+ // addMouseUp = (cb = null) => {
2104
+ // this.mouserUp = Gaea.World.Instance.OnMouseUp((p, b) => {
2105
+ // if (b == 1) {
2106
+ // console.log(b);
2107
+ // var camera = Gaea.World.Instance.DefaultCamera;
2108
+ // var screenpos = new Gaea.Vector2(p.x, p.y);
2109
+ // var spacepos = Gaea.GaeaMath.ProjectPosition(screenpos);
2110
+ // var latlonalt = Gaea.GaeaMath.CartesianToSphericalDeg(spacepos);
2111
+ // var spacepos2 = Gaea.GaeaMath.SphericalToCartesianDeg(latlonalt);
2112
+ // var screenpos2 = Gaea.GaeaMath.UnProjectPosition(spacepos2);
2113
+
2114
+ // //屏幕坐标
2115
+ // console.log("屏幕坐标--------", screenpos.instance);
2116
+ // //屏幕空间转笛卡尔坐标
2117
+ // console.log("屏幕空间转笛卡尔坐标------", spacepos.instance);
2118
+ // //经纬度坐标
2119
+ // console.log("经纬度坐标------", latlonalt.instance);
2120
+ // //还原笛卡尔坐标
2121
+ // console.log("还原笛卡尔坐标------", spacepos2.instance);
2122
+ // //还原为屏幕坐标
2123
+ // console.log("还原为屏幕坐标------", screenpos2.instance);
2124
+ // // 鼠标高度
2125
+ // console.log("鼠标高度------", camera.Altitude);
2126
+
2127
+ // cb(latlonalt.instance, screenpos.instance, camera.Altitude);
2128
+ // }
2129
+ // });
2130
+ // };
2131
+ // //移除鼠标点击事件
2132
+ // removeMouseUp = () => {
2133
+ // if (this.mouserUp) {
2134
+ // Gaea.World.Instance.ClearEvent(this.mouserUp);
2135
+ // this.mouserUp = null;
2136
+ // }
2137
+ // };
2138
+ // //监听滚动事件
2139
+ // addMouseWhill = (cb = null) => {
2140
+ // this.mouserWheel = Gaea.World.Instance.OnMouseWheel((p, b) => {
2141
+ // // console.log(b, p);
2142
+ // if (p == 1 || p == -1) {
2143
+ // var zHeight = Gaea.World.Instance.DefaultCamera.Altitude;
2144
+ // // console.log('高度变化-------', zHeight,);
2145
+ // cb(zHeight);
2146
+ // }
2147
+ // });
2148
+ // };
2149
+ // //移除监听滚动事件
2150
+ // removeMouserWheel = () => {
2151
+ // if (this.mouserWheel) {
2152
+ // Gaea.World.Instance.ClearEvent(this.mouserWheel);
2153
+ // this.mouserWheel = null;
2154
+ // }
2155
+ // };
2156
+ // //添加鼠标移动事件
2157
+ // addMouseMove = (cb = null) => {
2158
+ // this.mouseMove = Gaea.World.Instance.OnMouseMove((p, b) => {
2159
+ // if (b == 1) {
2160
+ // var screenpos = new Gaea.Vector2(p.x, p.y);
2161
+ // var spacepos = Gaea.GaeaMath.ProjectPosition(screenpos);
2162
+ // var latlonalt = Gaea.GaeaMath.CartesianToSphericalDeg(spacepos);
2163
+ // var spacepos2 = Gaea.GaeaMath.SphericalToCartesianDeg(latlonalt);
2164
+ // var screenpos2 = Gaea.GaeaMath.UnProjectPosition(spacepos2);
2165
+
2166
+ // //屏幕坐标
2167
+ // console.log(screenpos.instance);
2168
+ // //屏幕空间转笛卡尔坐标
2169
+ // console.log(spacepos.instance);
2170
+ // //经纬度坐标
2171
+ // console.log(latlonalt.instance);
2172
+ // //还原笛卡尔坐标
2173
+ // console.log(spacepos2.instance);
2174
+ // //还原为屏幕坐标
2175
+ // console.log(screenpos2.instance);
2176
+ // // Gaea.World.Instance.ClearEvent(move)
2177
+ // // Gaea.World.Instance.ClearEvent(up)
2178
+
2179
+ // cb(latlonalt.instance, screenpos.instance);
2180
+ // // this.point = latlonalt.instance
2181
+ // // console.log(this.point);
2182
+ // }
2183
+ // });
2184
+ // };
2185
+ // //移除鼠标移动事件
2186
+ // removeMouseMove = () => {
2187
+ // if (this.mouseMove) {
2188
+ // Gaea.World.Instance.ClearEvent(this.mouseMove);
2189
+ // this.mouseMove = null;
2190
+ // }
2191
+ // };
2192
+
2193
+ // 模型发光
2194
+ setRiverGltfElementEmission = (
2195
+ elementArr,
2196
+ { floor, color, emissionEnergy, emissionOperator, waterLevel }
2197
+ ) => {
2198
+ const root = elementArr[0].Root.GetChild(floor);
2199
+
2200
+ const rootInstance = Gaea.MeshInstance.ConvertBy(root),
2201
+ activeMaterial = rootInstance.GetActiveMaterial(0),
2202
+ SpatialMaterial = Gaea.SpatialMaterial.ConvertBy(activeMaterial);
2203
+
2204
+ SpatialMaterial.EmissionEnabled = true;
2205
+
2206
+ SpatialMaterial.Emission = new Gaea.Color(
2207
+ color[0] / 255,
2208
+ color[1] / 255,
2209
+ color[2] / 255,
2210
+ color[3]
2211
+ );
2212
+
2213
+ SpatialMaterial.EmissionEnergy = emissionEnergy;
2214
+
2215
+ SpatialMaterial.EmissionOperator = emissionOperator;
2216
+
2217
+ // elementArr.forEach((item) => {
2218
+ //   var v = new Gaea.Vector3(0, waterLevel, 0);
2219
+ //   item.Root.TranslateObjectLocal(v);
2220
+ // });
2221
+ };
2222
+
2223
+ /**
2224
+ * @param {String} name 模型的名称
2225
+ * @param {String} url 模型的请求位置
2226
+ * @param {Object} position 模型的位置
2227
+ * @param {Object} size 模型的大小
2228
+ * @param {Boolean} show 是否展示当前模型
2229
+ * @param {Boolean} enablePick 当前模型是否触发点击事件
2230
+ * @param {Boolean} useAbsoluteHeight 是否使用绝对定位
2231
+ * @param {Array} children 主模型下的子模型
2232
+ * @param {Array} billboard 主模型下某层的面片
2233
+ * @param {Function} clickCallBack 模型点击事件回调
2234
+ */
2235
+ AddGltf = ({
2236
+ name,
2237
+ url,
2238
+ position,
2239
+ rotate,
2240
+ size,
2241
+
2242
+ show = true,
2243
+ childBillboard,
2244
+ enablePick,
2245
+ useAbsoluteHeight = true,
2246
+ children,
2247
+ billboard,
2248
+ clickChilrenNameArray,
2249
+ emissionConfig = [],
2250
+ initFun = () => { },
2251
+ clickCallBack = () => { },
2252
+ clickChilrenCallBack = () => { },
2253
+ }) => {
2254
+ return new Promise(async (res, rej) => {
2255
+ const element = new Gaea.GLTFElement();
2256
+
2257
+ // 是否使用绝对定位
2258
+ element.UseAbsoluteHeight = useAbsoluteHeight;
2259
+
2260
+ // 模型请求地址
2261
+ element.ResourceName = url;
2262
+
2263
+ console.log("模型开始加载:" + name);
2264
+ console.log(new Date().Format("yyyy-MM-dd HH:mm:ss"));
2265
+
2266
+ element.OnModelInit(async () => {
2267
+ var n = element.Root.GetChildCount();
2268
+ if (name.includes('YPDP0')) {
2269
+ for (var i = 0; i < n; i++) {
2270
+ var meshinstance = Gaea.MeshInstance.ConvertBy(element.Root.GetChild(i))
2271
+ var count = meshinstance.Mesh.GetSurfaceCount();
2272
+ for (var j = 0; j < count; j++) {
2273
+ var meshInstance_mtl = Gaea.SpatialMaterial.ConvertBy(meshinstance.Mesh.SurfaceGetMaterial(j));
2274
+ meshInstance_mtl.FlagsUnshaded = true;
2275
+ }
2276
+ }
2277
+ }
2278
+ console.log(new Date().Format("yyyy-MM-dd HH:mm:ss"));
2279
+ console.log("模型加载完毕:" + name);
2280
+ // 模型初始化方法
2281
+ if (initFun) {
2282
+ initFun();
2283
+ }
2284
+ // 模型点击
2285
+ element.EnablePick = enablePick;
2286
+ Gaea.QueryServer.Instance.Enable = enablePick;
2287
+
2288
+ // 模型定位
2289
+ element.GeographyPosition = new Gaea.Vector3(
2290
+ position.x,
2291
+ position.y,
2292
+ position.z
2293
+ );
2294
+
2295
+ // 模型旋转
2296
+ element.TiltHeadingBank = new Gaea.Vector3(
2297
+ rotate[0],
2298
+ rotate[1],
2299
+ rotate[2]
2300
+ );
2301
+
2302
+ // 模型缩放
2303
+ element.Root.Scale = new Gaea.Vector3(size[0], size[1], size[2]);
2304
+
2305
+ // 模型命名
2306
+ element.Root.Name = name;
2307
+
2308
+ // 在当前模型下添加子模型
2309
+ if (children && children.length != 0) {
2310
+ let childrenElement = [];
2311
+ children.forEach(async (item) => {
2312
+ console.log(name);
2313
+
2314
+ switch (item.type) {
2315
+ case "gltf":
2316
+ childrenElement.push(await this.addChildrenGltf(element, item));
2317
+ element.childrenElement = childrenElement;
2318
+ break;
2319
+ case "Billboard":
2320
+ this.addChildrenBillboard(element, item);
2321
+ break;
2322
+ }
2323
+ });
2324
+ }
2325
+
2326
+ // 在当前模型下某层添加面片
2327
+ if (billboard && billboard.length != 0) {
2328
+ billboard.forEach((item) => {
2329
+ this.addBillBoardByGltfFloor(element, item);
2330
+ });
2331
+ }
2332
+
2333
+ // 添加当前模型需要点击的子元素名称
2334
+ if (clickChilrenNameArray && clickChilrenNameArray.length != 0) {
2335
+ clickChilrenNameArray.forEach((item) => {
2336
+ var ins = Gaea.MeshInstance.ConvertBy(
2337
+ element.GetMeshInstanceByName(item)
2338
+ );
2339
+
2340
+ Gaea.QueryServer.Instance.AddHitMeshInstance(element, ins);
2341
+ });
2342
+ }
2343
+
2344
+ element.OnHitElement((childName, pos) => {
2345
+ clickCallBack(childName, pos);
2346
+ });
2347
+
2348
+ element.OnHitChildElement((childName, pos) => {
2349
+ console.log(childName);
2350
+ clickChilrenCallBack(childName);
2351
+ });
2352
+
2353
+ if (childBillboard && childBillboard.length) {
2354
+ let childBillboardList = [];
2355
+ childBillboard.forEach(async (item) => {
2356
+ childBillboardList.push(await this.test(element, item));
2357
+ });
2358
+
2359
+ element.ChildrenBillboardArr = childBillboardList;
2360
+ }
2361
+ // 模型是否展示
2362
+ element.Root.Visible = show;
2363
+ await res(element);
2364
+ });
2365
+
2366
+ Gaea.World.Instance.RenderableObjectList.AddLast(element);
2367
+
2368
+ setTimeout(() => {
2369
+ res(element);
2370
+ }, 20 * 1000);
2371
+ });
2372
+ };
2373
+ /**
2374
+ * 本地资源加载(tscn)
2375
+ * @param {string} resourcePath - 资源路径,如 "res://assets/gltf/box.tscn"
2376
+ * @param {Gaea.Vector3} position - 模型位置的经纬度和高度,格式为 Vector3(lat, lon, height)
2377
+ * @param {Gaea.Vector3} scale - 模型缩放比例,格式为 Vector3(x, y, z)
2378
+ * @param {string} [name] - 模型名称(可选)
2379
+ * @returns {Promise<void>} - 无返回值
2380
+ * @example
2381
+ * // 加载一个 box 模型到指定位置
2382
+ * const position = new Gaea.Vector3(27.200503, 120.465629, 25.6);
2383
+ * const scale = new Gaea.Vector3(1, 1, 1);
2384
+ * await AddLocalResource("res://assets/gltf/box.tscn", position, scale, "MyBox");
2385
+ */
2386
+ AddLocalResource = async (resourcePath, position, scale, name) => {
2387
+ const scene = Gaea.GaeaResourceLoader.Instance.LoadLoaclResource(resourcePath)
2388
+ const node = Gaea.PackedScene.ConvertBy(scene)
2389
+ var inst = Gaea.Spatial.ConvertBy(node.Instance(0));
2390
+ var pos = new Gaea.Vector3(position.x, position.y, position.z); // 模型位置
2391
+ var spacepos2 = Gaea.GaeaMath.SphericalToCartesianDeg(pos);
2392
+ var deg = Gaea.GaeaMath.SphericalToGlobeRoationYZX(pos);
2393
+ inst.Translate(spacepos2);
2394
+ // inst.Rotation = Gaea.GaeaMath.RotationFromCartesianToSpherical(x, y).GetEuler();
2395
+ inst.Scale = new Gaea.Vector3(scale[0], scale[1], scale[2]);
2396
+ inst.RotationDegrees = deg;
2397
+ console.log(spacepos2, resourcePath, name, 'namename');
2398
+ console.log(deg);
2399
+ console.log(scale);
2400
+ // inst.Name = iconUrl;
2401
+ Gaea.World.Instance.AddChild(inst, false);
2402
+ }
2403
+
2404
+ /**
2405
+ * 修改tscn模型参数
2406
+ * @param {string} name - 节点名称
2407
+ * @param {number} rotateX - X轴旋转角度(度数)
2408
+ * @param {number} rotateY - Y轴旋转角度(度数)
2409
+ * @param {number} rotateZ - Z轴旋转角度(度数)
2410
+ * @param {number} translateX - X轴位移
2411
+ * @param {number} translateY - Y轴位移
2412
+ * @param {number} translateZ - Z轴位移
2413
+ */
2414
+ updateTSCNPamars = ({ name, rotateX = 0, rotateY = 0, rotateZ = 0, translateX = 0, translateY = 0, translateZ = 0 }) => {
2415
+ const node = Gaea.World.Instance.GetNode(name);
2416
+ console.log(node, 'node');
2417
+ var inst = Gaea.MeshInstance.ConvertBy(node);
2418
+
2419
+ // 转换角度为弧度
2420
+ const radX = rotateX / 180 * 3.14;
2421
+ const radY = rotateY / 180 * 3.14;
2422
+ const radZ = rotateZ / 180 * 3.14;
2423
+
2424
+ // 应用旋转(按XYZ顺序)
2425
+ if (rotateX !== 0) inst.RotateObjectLocal(new Gaea.Vector3(1, 0, 0), radX);
2426
+ if (rotateY !== 0) inst.RotateObjectLocal(new Gaea.Vector3(0, 1, 0), radY);
2427
+ if (rotateZ !== 0) inst.RotateObjectLocal(new Gaea.Vector3(0, 0, 1), radZ);
2428
+
2429
+ // 应用位移
2430
+ if (translateX !== 0 || translateY !== 0 || translateZ !== 0) {
2431
+ inst.TranslateObjectLocal(new Gaea.Vector3(translateX, translateY, translateZ));
2432
+ }
2433
+
2434
+ console.log(inst);
2435
+ return inst;
2436
+ }
2437
+
2438
+ /**
2439
+ * 修改模型配置
2440
+ * @param {*} element 模型
2441
+ * @param {*} position 坐标
2442
+ * @param {*} rotate 旋转
2443
+ * @param {*} size 大小
2444
+ */
2445
+ updateElementPosition = ({ element, position, rotate, size }) => {
2446
+ element.GeographyPosition = new Gaea.Vector3(
2447
+ position.x,
2448
+ position.y,
2449
+ position.z
2450
+ );
2451
+
2452
+ if (rotate?.length > 0) {
2453
+ element.TiltHeadingBank = new Gaea.Vector3(
2454
+ rotate[0],
2455
+ rotate[1],
2456
+ rotate[2]
2457
+ );
2458
+ }
2459
+
2460
+ // element.Root.Scale = new Gaea.Vector3(size[0], size[1], size[2]);
2461
+ };
2462
+
2463
+ /**
2464
+ * 修改标记配置
2465
+ * @param {*} element 模型
2466
+ * @param {*} position 坐标
2467
+ */
2468
+ updateScreenPosition = ({ element, position }) => {
2469
+ element.GeographyPosition = new Gaea.Vector3(position.x, position.y, position.z);
2470
+
2471
+ };
2472
+
2473
+ /**
2474
+ * @description: 缓动动画
2475
+ * @param {Object} element 模型或者面片
2476
+ * @param {Object} Scale 需要变化的大小
2477
+ * @param {Object} Position 需要变化的位置
2478
+ * @param {Object} translation 模型相对位置的变化
2479
+ * @param {number} time 需要变化的时间
2480
+ * @param {Object} Door 开门关门
2481
+ * @param {Object} floor 门的层级
2482
+ */
2483
+ Tweentest = (
2484
+ element,
2485
+ Scale = {},
2486
+ Position = {},
2487
+ translation = {},
2488
+ time,
2489
+ Door = {},
2490
+ floor = 0
2491
+ ) => {
2492
+ if (Object.values(Scale).length) {
2493
+ const scale = {
2494
+ x: element.Scale.x,
2495
+ y: element.Scale.y,
2496
+ z: element.Scale.z,
2497
+ };
2498
+ const tweenScale = new Tween(scale)
2499
+ .to(Scale, time)
2500
+ .easing(Easing.Quadratic.InOut) // 改用直接导入的 Easing
2501
+ .onUpdate(() => {
2502
+ element.Scale = new Gaea.Vector3(scale.x, scale.y, scale.z);
2503
+ })
2504
+ .start()
2505
+ .onStart(() => {
2506
+ if (Scale.x !== 0.1) {
2507
+ element.Visible = true;
2508
+ }
2509
+ })
2510
+ .onComplete(() => {
2511
+ if (Scale.x === 0.1) {
2512
+ element.Visible = false;
2513
+ }
2514
+ this.tweenGroup.remove(tweenScale);
2515
+ });
2516
+ this.tweenGroup.add(tweenScale);
2517
+ }
2518
+
2519
+ if (Object.values(Position).length) {
2520
+ const GeographyPosition = {
2521
+ x: element.GeographyPosition.x,
2522
+ y: element.GeographyPosition.y,
2523
+ z: element.GeographyPosition.z,
2524
+ };
2525
+ const tweenPosition = new Tween(GeographyPosition)
2526
+ .to(Position, time)
2527
+ .easing(Easing.Quadratic.InOut) // 改用 Easing
2528
+ .onUpdate(() => {
2529
+ element.GeographyPosition = new Gaea.Vector3(
2530
+ GeographyPosition.x,
2531
+ GeographyPosition.y,
2532
+ GeographyPosition.z
2533
+ );
2534
+ })
2535
+ .start()
2536
+ .onComplete(() => {
2537
+ this.tweenGroup.remove(tweenPosition);
2538
+ });
2539
+ this.tweenGroup.add(tweenPosition);
2540
+ }
2541
+
2542
+ if (Object.values(Door).length) {
2543
+ const doorMesh = element.Root.GetChild(floor),
2544
+ meshInstance = new Gaea.MeshInstance();
2545
+ meshInstance.InstanceID = doorMesh.InstanceID;
2546
+ const DoorAngle = {
2547
+ x: meshInstance.RotationDegrees.x,
2548
+ y: meshInstance.RotationDegrees.y,
2549
+ z: meshInstance.RotationDegrees.z,
2550
+ };
2551
+
2552
+ const tweenDoor = new Tween(DoorAngle)
2553
+ .to(Door, time)
2554
+ .easing(Easing.Quadratic.InOut) // 改用 Easing
2555
+ .onUpdate(() => {
2556
+ meshInstance.RotationDegrees = new Gaea.Vector3(
2557
+ DoorAngle.x,
2558
+ DoorAngle.y,
2559
+ DoorAngle.z
2560
+ );
2561
+ })
2562
+ .start()
2563
+ .onComplete(() => {
2564
+ this.tweenGroup.remove(tweenDoor);
2565
+ });
2566
+ this.tweenGroup.add(tweenDoor);
2567
+ }
2568
+
2569
+ if (Object.values(translation).length) {
2570
+ let Translation;
2571
+ if (element.Root) {
2572
+ Translation = {
2573
+ x: element.Root.Translation.x,
2574
+ y: element.Root.Translation.y,
2575
+ z: element.Root.Translation.z,
2576
+ };
2577
+ } else {
2578
+ Translation = {
2579
+ x: element.Translation.x,
2580
+ y: element.Translation.y,
2581
+ z: element.Translation.z,
2582
+ };
2583
+ }
2584
+
2585
+ const tweenTranslation = new Tween(Translation)
2586
+ .to(translation, time)
2587
+ .easing(Easing.Quadratic.InOut) // 改用 Easing
2588
+ .onUpdate(() => {
2589
+ if (element.Root) {
2590
+ element.Root.Translation = new Gaea.Vector3(
2591
+ Translation.x,
2592
+ Translation.y,
2593
+ Translation.z
2594
+ );
2595
+ } else {
2596
+ element.Translation = new Gaea.Vector3(
2597
+ Translation.x,
2598
+ Translation.y,
2599
+ Translation.z
2600
+ );
2601
+ }
2602
+ })
2603
+ .start()
2604
+ .onComplete(() => {
2605
+ this.tweenGroup.remove(tweenTranslation);
2606
+ });
2607
+ this.tweenGroup.add(tweenTranslation);
2608
+ }
2609
+ };
2610
+
2611
+ //创建vt3对象
2612
+ createGaeaVt3 = ({ x, y, z }) => {
2613
+ return new Gaea.Vector3(x, y, z);
2614
+ };
2615
+ //移除模型
2616
+ removeGltf = (gltfElement) => {
2617
+ Gaea.World.Instance.RenderableObjectList.Remove(gltfElement);
2618
+ };
2619
+ //添加可点击的点
2620
+ addFeaturePoint = async (featureObj, callback = () => { }) => {
2621
+ const {
2622
+ pointData,
2623
+ iconUrl,
2624
+ fieldText,
2625
+ HeightOffset,
2626
+ VisibleRange,
2627
+ onClick,
2628
+ } = featureObj;
2629
+ if (iconUrl) {
2630
+ let name = getFlieName(iconUrl);
2631
+ await LoadResourceAsync(iconUrl);
2632
+ var id = Gaea.GaeaResourceLoader.Instance.GetResource(name);
2633
+ var tex = new Gaea.Texture(false);
2634
+ tex.InstanceID = id + "";
2635
+ }
2636
+ var pos = pointData["geometry"]["coordinates"];
2637
+ console.log(pointData);
2638
+ var Position = new Gaea.Vector3(pos[1], pos[0], 0);
2639
+ var posArray = [Position];
2640
+ var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Point, posArray);
2641
+ var Element = new Gaea.PointGeometryElement();
2642
+ var IconMarkSymbol = new Gaea.IconMarkSymbol();
2643
+ IconMarkSymbol.MarkSize = 40;
2644
+ IconMarkSymbol.Icon = tex;
2645
+ var TextSymbol = new Gaea.TextMarkSymbol();
2646
+ TextSymbol.MarkSize = 22;
2647
+ TextSymbol.Field = fieldText;
2648
+ TextSymbol.Anchor = Gaea.AnchorType.Down;
2649
+
2650
+ var CompositeSymbol = new Gaea.CompositeSymbol();
2651
+ CompositeSymbol.AddSymbol(TextSymbol);
2652
+ CompositeSymbol.AddSymbol(IconMarkSymbol);
2653
+
2654
+ Element.Symbol = CompositeSymbol;
2655
+ Element.Shape = geometry;
2656
+
2657
+ var fields = new Gaea.Fields();
2658
+ var field = new Gaea.Field();
2659
+ field.Name = fieldText;
2660
+ fields.AddField(field);
2661
+ Element.Feature.SetFields(fields);
2662
+ var value = pointData["properties"][fieldText];
2663
+ Element.Feature.SetStringValue(fieldText, value);
2664
+ if (VisibleRange) {
2665
+ Element.VisibleRange = new Gaea.Vector2(VisibleRange[0], VisibleRange[1]);
2666
+ }
2667
+ Element.EnableEdit = false; //不允许编辑
2668
+ Element.EnablePick = true; //不允许点击
2669
+ Element.NeedIntersectWithMesh = false;
2670
+ Element.SelectedCallBack((ro, ins, selected, pos, startId, surfaceid) => {
2671
+ if (selected) {
2672
+ onClick(pointData.properties);
2673
+ }
2674
+ });
2675
+ Gaea.World.Instance.RenderableObjectList.AddLast(Element);
2676
+ callback(Element);
2677
+ };
2678
+
2679
+ /**
2680
+ * 加载水面
2681
+ */
2682
+ async addWaterHandle({ gltfUrl, Position }) {
2683
+ var water_mtl = Gaea.GaeaResourceLoader.Instance.LoadLoaclResource("res://assets/material/river2.tres")
2684
+ var material = Gaea.ShaderMaterial.ConvertBy(water_mtl)
2685
+
2686
+ var element = new Gaea.GLTFElement();
2687
+ //模型名称
2688
+ element.ResourceName = gltfUrl;
2689
+ var elv = Gaea.World.Instance.DefaultTerrainAccessor.GetElevationByCurrentViewRangeAt(Position.x, Position.y); //根据经纬度获取高程
2690
+ var pos = new Gaea.Vector3(Position.x, Position.y, Position.z); //模型位置
2691
+ console.log(Gaea.GaeaMath.SphericalToCartesianDeg(pos), 'Gaea.GaeaMath.SphericalToCartesianDeg1(pos);');
2692
+
2693
+ element.GeographyPosition = pos;
2694
+ element.OnModelInit(() => {
2695
+ var n = element.GetChildCount();
2696
+ for (var i = 0; i < n; i++) {
2697
+ var meshinstance = Gaea.MeshInstance.ConvertBy(element.Root.GetChild(i))
2698
+ var count = meshinstance.Mesh.GetSurfaceCount();
2699
+ for (var j = 0; j < count; j++) {
2700
+ meshinstance.Mesh.SurfaceSetMaterial(j, material)
2701
+ }
2702
+ }
2703
+ element.Scale = new Gaea.Vector3(0.05, 0.05, 0.05); //模型放大
2704
+
2705
+ Gaea.World.Instance.SetMtlVector3(material, "uv_scale", new Gaea.Vector3(-0.3, -0.3, 1));
2706
+ Gaea.World.Instance.SetMtlFloat(material, "flow_speed", 0.4);
2707
+ // Gaea.World.Instance.SetMtlColor(material, "color_shallow", new Gaea.Color(127 / 255, 111 / 255, 75 / 255, 1));
2708
+ // Gaea.World.Instance.SetMtlColor(material, "color_deep", new Gaea.Color(127 / 255, 111 / 255, 75 / 255, 1));
2709
+ // Gaea.World.Instance.SetMtlFloat(material, "normal_scale", 0);
2710
+ // Gaea.World.Instance.SetMtlFloat(material, "roughness", 0);
2711
+ Gaea.World.Instance.SetMtlFloat(material, "transparency_clarity", 0);
2712
+ });
2713
+ Gaea.World.Instance.RenderableObjectList.AddLast(element);
2714
+
2715
+ // return riverData;
2716
+ }
2717
+ //坐标转换
2718
+ GaeaMath = (x, y, z) => {
2719
+ var space = Gaea.GaeaMath.SphericalToCartesianDeg1(
2720
+ x,
2721
+ y,
2722
+ Gaea.World.Instance.WorldRadius + 20 + z
2723
+ ); //设置xyz
2724
+ return space;
2725
+ };
2726
+ //添加3dtils
2727
+ add3dtils = (tilesObj) => {
2728
+ let { tilName, jsonUrl, height } = tilesObj;
2729
+ const tdtile = new Gaea.Gaea3DTileset();
2730
+ tdtile.IsZUp = true;
2731
+ if (height) {
2732
+ tdtile.LocalOffset = new Gaea.Vector3(0, height, 0);
2733
+ }
2734
+ tdtile.InitTileSet(tilName, jsonUrl);
2735
+ // tdtile.CameraWidthRatio = 0
2736
+ // tdtile.UseLight = false;
2737
+ tdtile.UseLight = false;
2738
+ tdtile.RecalculateNormals = false;
2739
+ // 是否计算法线
2740
+ tdtile.RecalculateNormals = true;
2741
+ // 是否开启光照
2742
+ tdtile.UseLight = false;
2743
+ // // tdtile.Layers = 3
2744
+ // // else
2745
+ // // tdtile.UseLight = true
2746
+ // // // tdtile.CameraWidthRatio = 1.3
2747
+ // // // tdtile.CameraWidthRatio = window.configData.pipeViewValue
2748
+ // // tdtile.CameraWidthRatio = 1
2749
+ // // tdtile.AutoCutTileChildrenMode = true
2750
+ // // tdtile.AutoCutTileChildrenPerLength = 1000
2751
+ // // tdtile.ShowWithClipBox = false
2752
+
2753
+ // // tdtile.CameraWidthRatio = 1.3
2754
+ // // tdtile.EnablePick = false
2755
+ // // Gaea.QueryServer.Instance.Enable = true
2756
+ // 开启裁剪
2757
+ // tdtile.EnablePick = true;
2758
+ Gaea.World.Instance.RenderableObjectList.AddLast(tdtile);
2759
+ //倾斜跳层关闭
2760
+ tdtile.SkipLevelOfDetail = false;
2761
+ console.log(`倾斜${tilName}加载成功`);
2762
+ return tdtile;
2763
+ };
2764
+ //移除3dtils
2765
+ remove3dtils = ({ tilName, tilData }) => {
2766
+ // tilData.Delete();
2767
+ Gaea.World.Instance.RenderableObjectList.Remove(tilData);
2768
+ console.log("tilData" + tilData);
2769
+ console.log(`倾斜${tilName}移除成功`);
2770
+ };
2771
+ //加载默认资源
2772
+ InitFontTexture = (params) => {
2773
+ return new Promise((res, rej) => {
2774
+ var over = Gaea.TextTextureManager.Instance.OnInitFontTexture((ok) => {
2775
+ if (ok) {
2776
+ res();
2777
+ } else {
2778
+ rej();
2779
+ }
2780
+ Gaea.TextTextureManager.Instance.ClearEvent(over);
2781
+ });
2782
+ Gaea.TextTextureManager.Instance.InitFontTexture();
2783
+ });
2784
+ };
2785
+
2786
+ //添加流动的线
2787
+ addFlowLine = async (flowLineObj, callback = () => { }) => {
2788
+ const {
2789
+ iconUrl,
2790
+ lineData,
2791
+ LineWidth,
2792
+ EeightOffset,
2793
+ EnablePick = false,
2794
+ LineColor = [1, 0, 0, 1],
2795
+ EnableEdit = false,
2796
+ } = flowLineObj;
2797
+ const flieName = getFlieName(iconUrl);
2798
+ const ok = await this.LoadResourceFromUrl(iconUrl, flieName);
2799
+ if (!ok) return console.error("图标加载失败");
2800
+ const id = Gaea.GaeaResourceLoader.Instance.GetResource(flieName);
2801
+ const tex = new Gaea.Texture(false);
2802
+ tex.InstanceID = id + "";
2803
+ tex.Flags = 0;
2804
+ const line = lineData.map((item) => {
2805
+ return new Gaea.Vector3(item[0], item[1], 30);
2806
+ });
2807
+ const geomety = Gaea.Geometry.Create1(Gaea.GeometryType.Polyline, line);
2808
+ const lineElement = new Gaea.LineGeometryElement();
2809
+
2810
+ const lineSymbol = new Gaea.LineSymbol();
2811
+ lineSymbol.LineColor = new Gaea.Color(
2812
+ LineColor[0],
2813
+ LineColor[1],
2814
+ LineColor[2],
2815
+ LineColor[3]
2816
+ );
2817
+ //流动速度
2818
+ lineSymbol.FlowVelocity = 0.5;
2819
+ //箭头个数
2820
+ lineSymbol.RepeatTimes = 100;
2821
+ lineSymbol.LineWidth = 15;
2822
+ lineSymbol.HeightOffset = 0;
2823
+ lineSymbol.IsFlowing = true;
2824
+ //深度检测
2825
+ lineSymbol.DepthTestEnable = false;
2826
+ lineSymbol.LineTexture = tex;
2827
+ lineSymbol.EmissionPower = 1.0;
2828
+
2829
+ lineElement.NeedIntersectWithMesh = false;
2830
+ lineElement.Symbol = lineSymbol;
2831
+ lineElement.Shape = geomety;
2832
+ lineElement.EnableEdit = false;
2833
+ lineElement.EnablePick = false;
2834
+ lineElement.VisibleRange = new Gaea.Vector2(0, 100000);
2835
+ Gaea.World.Instance.RenderableObjectList.AddLast(lineElement);
2836
+ callback(lineElement);
2837
+ };
2838
+ removeFlowLine = (lineElement) => {
2839
+ Gaea.World.Instance.RenderableObjectList.Remove(lineElement);
2840
+ };
2841
+ //画要素线
2842
+ addFeatureLine = (featureObj, callback = () => { }, onClick = () => { }) => {
2843
+ const {
2844
+ lineData,
2845
+ EnablePick,
2846
+ EnableEdit,
2847
+ NeedIntersectWithMesh,
2848
+ LineWidth,
2849
+ IsFlowing,
2850
+ LineStyle,
2851
+ Priority,
2852
+ HeightOffset,
2853
+ InitialLineColor,
2854
+ SelectedLineColor,
2855
+ VisibleMinHeight,
2856
+ VisibleMaxHeight,
2857
+ } = featureObj;
2858
+ //线数据
2859
+ const lineList = [];
2860
+
2861
+ for (let index = 0; index < lineData.length; index++) {
2862
+ const element = lineData[index];
2863
+ let p = null;
2864
+ if (HeightOffset) {
2865
+ p = new Gaea.Vector3(
2866
+ element[1],
2867
+ element[0],
2868
+ Gaea.World.Instance.WorldRadius + HeightOffset
2869
+ );
2870
+ } else {
2871
+ let height = Gaea.World.Instance.DefaultTerrainAccessor.GetElevationAt(
2872
+ element[1],
2873
+ element[0],
2874
+ 20
2875
+ );
2876
+ p = new Gaea.Vector3(
2877
+ element[1],
2878
+ element[0],
2879
+ Gaea.World.Instance.WorldRadius + height
2880
+ );
2881
+ }
2882
+ lineList.push(p);
2883
+ }
2884
+
2885
+ var Space = lineList; // 构成线的数据,数据形式为经纬度加地形高度
2886
+ var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Polyline, Space); // 创建 GeometryLine 对象
2887
+ var Element = new Gaea.LineGeometryElement(); // 创建 LineGeometryElement 对象
2888
+ Element.Shape = geometry; // 赋值,该赋值操作需要最先被执行
2889
+ // Element.EnablePick = true;
2890
+ Element.EnablePick = EnablePick ? EnablePick : false; // 允许点击
2891
+ Element.EnableEdit = EnableEdit ? EnableEdit : false; // 允许编辑
2892
+ Element.NeedIntersectWithMesh = NeedIntersectWithMesh
2893
+ ? NeedIntersectWithMesh
2894
+ : false; // 允许在3Dtiles、管线、挖方等位置编辑
2895
+ Element.InitialLineColor = InitialLineColor
2896
+ ? parseColorString(InitialLineColor)
2897
+ : parseColorString("rgba(255,0,0,1)");
2898
+ // //************ 样式设置 ***************//
2899
+ var OUL = Gaea.LineSymbol.ConvertBy(Element.Symbol); // 线的样式设置
2900
+ OUL.LineWidth = LineWidth ? LineWidth : 1; // 线宽
2901
+ OUL.IsFlowing = IsFlowing ? IsFlowing : false; // 是否流动
2902
+ OUL.LineStyle = LineStyle ? LineStyle : 0; // 实线,这里有两种形式,0实线和1虚线
2903
+ OUL.Priority = Priority ? Priority : 3; // 线的优先级
2904
+ OUL.EmissionPower = 100;
2905
+ Element.SelectedCallBack((a, b, c, d, e, f) => {
2906
+ // debugger
2907
+ if (c) {
2908
+ //获取选中element
2909
+ const selectelement = new Gaea.LineGeometryElement(false);
2910
+ selectelement.InstanceID = a + "";
2911
+ console.log(123);
2912
+ const lineData = selectelement.GetLineData();
2913
+ onClick(lineData);
2914
+ }
2915
+ });
2916
+ // Element.InitialLineColor = parseColorString(InitialLineColor) || parseColorString('Red'); // 初始线的颜色以及透明度
2917
+ // Element.SelectedLineColor = parseColorString(SelectedLineColor) || parseColorString('Green'); // 选中线后的颜色以及透明度
2918
+ Element.Visible = true;
2919
+ // Element.VisibleRange = new Gaea.Vector2(VisibleMinHeight || 0, VisibleMaxHeight || 99999999); // 可视范围
2920
+ Gaea.World.Instance.RenderableObjectList.AddLast(Element); // 加入到场景
2921
+ callback(Element);
2922
+ };
2923
+ //移除线
2924
+ removeFeatureLine = (lineElement) => {
2925
+ Gaea.World.Instance.RenderableObjectList.Remove(lineElement);
2926
+ };
2927
+ //读取geojson绘制线
2928
+ addGeoJsonFetureLine = async (url, lineStyle = {}, callback = () => { }) => {
2929
+ const { StartColor, EndColor, HeightOffset, LineWidth } = lineStyle;
2930
+ var Symbol = new Gaea.LineSymbol(); //创建线符号
2931
+ Symbol.LineWidth = LineWidth ? LineWidth : 1.5; //设置宽度
2932
+ Symbol.HeightOffset = 100; //设置高度偏移
2933
+ Symbol.EmissionPower = 100;
2934
+ // var geojsonFile = "等值线.geojson"; //设置保存时的文件名,要带拓展名
2935
+ let geojsonFile = getFlieName(url);
2936
+ var res = "user://resources/"; //设置保存目录
2937
+ await this.LoadResourceFromUrl(url, geojsonFile);
2938
+ var ws = Gaea.WorkspaceFactory.OpenFromFile(res + geojsonFile);
2939
+ var fclass = ws.OpenFeatureClass(true, false); //读取文件,构建FeatureClass
2940
+ var flayer = new Gaea.FeatureLayer(); //创建一个FeatureLayer图层
2941
+ var FeatureRenderer = new Gaea.GradedRenderer(); //创建一个渲染器
2942
+ FeatureRenderer.GradedField = "OBJECTID";
2943
+ // FeatureRenderer.StartColor = new Gaea.Color(1, 0, 0, 1);
2944
+ FeatureRenderer.StartColor = StartColor
2945
+ ? parseColorString(StartColor)
2946
+ : parseColorString("rgba(255,0,0,1)");
2947
+ // FeatureRenderer.EndColor = new Gaea.Color(1, 0, 0, 1);
2948
+ FeatureRenderer.EndColor = EndColor
2949
+ ? parseColorString(EndColor)
2950
+ : parseColorString("rgba(255,0,0,1)");
2951
+ FeatureRenderer.GradedNumber = 5;
2952
+ FeatureRenderer.Symbol = Symbol; //设置渲染器的符号
2953
+ // flayer.VisibleRange = new Gaea.Vector2(0, 1000000); //设置可见高度范围
2954
+ flayer.FeatureClass = fclass; //设置图层中的数据,即fclass
2955
+ flayer.FeatureRenderer = FeatureRenderer; //设置图层中的渲染器, 即FeatureRenderer
2956
+ Gaea.World.Instance.RenderableObjectList.AddLast(flayer); //将图层添加到可渲染对象列表
2957
+ callback(flayer);
2958
+ };
2959
+ //读取geojson线数据
2960
+ addSymbolLine = async () => {
2961
+ const Symbol = new Gaea.LineSymbol();
2962
+ Symbol.LineWidth = 1.5; //设置宽度
2963
+ Symbol.LineColor = new Gaea.Color(1, 0, 0, 0.5);
2964
+ Symbol.HeightOffset = 110;
2965
+ Symbol.EmissionPower = 100;
2966
+ const geojsonFile = "保护范围线.geojson";
2967
+ const res = "user://resources/";
2968
+ Gaea.GaeaResourceLoader.Instance.LoadResourceFromUrl1(
2969
+ "http://localhost:9878/geojson/保护范围线.geojson",
2970
+ geojsonFile,
2971
+ (code, msg) => {
2972
+ const ws = Gaea.WorkspaceFactory.OpenFromFile(res + geojsonFile);
2973
+ const fclass = ws.OpenFeatureClass(true, false);
2974
+ const flayer = new Gaea.FeatureLayer();
2975
+ const featureRenderer = new Gaea.SimpleFeatureRenderer();
2976
+ featureRenderer.Symbol = Symbol;
2977
+ flayer.VisibleRange = new Gaea.Vector2(0, 10000000);
2978
+ flayer.FeatureClass = fclass;
2979
+ flayer.FeatureRenderer = featureRenderer;
2980
+ Gaea.World.Instance.RenderableObjectList.AddLast(flayer);
2981
+ }
2982
+ );
2983
+ };
2984
+
2985
+ /**
2986
+ * @description: 屏幕标记
2987
+ * @param {String} name 标记名称
2988
+ * @param {Boolean} show 标记是否可见
2989
+ * @param {String} url 标记背景图
2990
+ * @param {Object} position 标记位置
2991
+ * @param {Array} size 标记大小[宽,高]
2992
+ * @param {Array} offset 标记偏移[左,上]
2993
+ * @param {Array} text 标记内容文本
2994
+ * @param {Number} anchorType 点方位(详情见index.js => AnchorType)
2995
+ * @param {Array} visibleRange 标记可见范围[min,max]
2996
+ * @param {Boolean} DrawLine 是否带线
2997
+ * @param {Boolean} EnablePick 是否点击
2998
+ * @param {Function} clickCallBack 标记点击方法
2999
+ */
3000
+ addScreenIcon = async ({
3001
+ name,
3002
+ show = true,
3003
+ url = "",
3004
+ position,
3005
+ size = [100, 50],
3006
+ offset = [0, 0],
3007
+ text = [],
3008
+ anchorType = Gaea.AnchorType.LeftDown,
3009
+ visibleRange = [10, 50000],
3010
+ CameraAltitudeRange = [],
3011
+ DrawLine = false,
3012
+ LineStyle = {
3013
+ lineWidth: 3,
3014
+ lineColor: [255, 76, 76],
3015
+ pointWidth: 3,
3016
+ pointColor: [255, 76, 76],
3017
+
3018
+ },
3019
+ EnablePick = true,
3020
+ divId = "",
3021
+ clickCallBack = () => { },
3022
+ elementName = "",
3023
+ elementChildrenIndex = 0
3024
+ }) => {
3025
+ if (url) {
3026
+ await this.LoadResourceFromUrl(`${serveLocal}/icon/labelImg/${url}`, url);
3027
+ }
3028
+ const screen = new Gaea.ScreenGUIElement();
3029
+ screen.Name = name;
3030
+ screen.Visible = show;
3031
+ screen.UseAutoVisible();
3032
+ if (divId) {
3033
+ screen.DivID = divId;
3034
+ const dom = document.getElementById(screen.DivID);
3035
+ const root = new Gaea.Control();
3036
+ root.MouseFilter = 2;
3037
+ root.RectSize = new Gaea.Vector2(dom.clientWidth, dom.clientHeight);
3038
+ screen.Root = root;
3039
+ } else {
3040
+ screen.Root = this.InitUI(text, size, url);
3041
+ }
3042
+
3043
+ // 标签默认位置为左上角
3044
+ if (offset.length) {
3045
+ screen.ScreenOffset = new Gaea.Vector2(offset[0], offset[1]); // 偏移位置
3046
+ }
3047
+
3048
+ screen.ConnectAnchor = anchorType; // 点方位
3049
+ // 是否点击
3050
+ screen.EnablePick = true;
3051
+ screen.LineWidth = screen.AnchorPointSize = LineStyle.lineWidth; // 线条和圆点粗细
3052
+ screen.LineColor = new Gaea.Color(LineStyle.lineColor[0] / 255, LineStyle.lineColor[1] / 255, LineStyle.lineColor[2] / 255, 1); // 线条颜色
3053
+ screen.AnchorPointColor = new Gaea.Color(LineStyle.pointColor[0] / 255, LineStyle.pointColor[1] / 255, LineStyle.pointColor[2] / 255, 1); // 圆点颜色
3054
+ // 是否带线
3055
+ screen.DrawLine = DrawLine;
3056
+
3057
+ // 可见范围
3058
+ if (visibleRange.length) {
3059
+ screen.VisibleRange = new Gaea.Vector2(visibleRange[0], visibleRange[1]);
3060
+ }
3061
+
3062
+ // 可见范围
3063
+ if (CameraAltitudeRange.length) {
3064
+ screen.CameraAltitudeRange = new Gaea.Vector2(CameraAltitudeRange[0], CameraAltitudeRange[1]);
3065
+ }
3066
+
3067
+ screen.OnHitElement = () => {
3068
+ clickCallBack();
3069
+ };
3070
+
3071
+ // 标签的地理坐标
3072
+ if (!elementName) {
3073
+ screen.GeographyPosition = new Gaea.Vector3(
3074
+ position.x,
3075
+ position.y,
3076
+ position.z
3077
+ );
3078
+ Gaea.World.Instance.RenderableObjectList.AddLast(screen);
3079
+ } else {
3080
+ let elementObj;
3081
+ const { element } = gltfList.value.find(
3082
+ (item) => item.name === elementName
3083
+ );
3084
+ elementObj = element.Root.GetChild(elementChildrenIndex);
3085
+ elementObj.AddChild(screen, false);
3086
+ }
3087
+ return screen;
3088
+ };
3089
+
3090
+ clearScreen = (screen) => {
3091
+ Gaea.World.Instance.RenderableObjectList.Remove(screen);
3092
+ }
3093
+
3094
+ /**
3095
+ * 通过URL加载资源,并存储为Name
3096
+ * @param {string} url
3097
+ * @param {string} name
3098
+ * @returns {number} 资源ID
3099
+ */
3100
+ LoadResourceFromUrl = (url, name) => {
3101
+ return new Promise((res, rej) => {
3102
+ Gaea.GaeaResourceLoader.Instance.LoadResourceFromUrl1(
3103
+ url,
3104
+ name,
3105
+ (code, msg) => {
3106
+ if (code == 200) {
3107
+ res(true);
3108
+ } else {
3109
+ console.log(msg);
3110
+ rej(false);
3111
+ }
3112
+ }
3113
+ );
3114
+ // var rfid = Gaea.GaeaResourceLoader.Instance.OnLoadResourceFromUrl((code, id) => {
3115
+ // if (code == 200) {
3116
+ // res(id)
3117
+ // } else {
3118
+ // rej(id)
3119
+ // }
3120
+ // Gaea.GaeaResourceLoader.Instance.ClearEvent(rfid)
3121
+ // })
3122
+ // console.log("资源保存成功!");
3123
+ });
3124
+ };
3125
+
3126
+ /***
3127
+ * 添加图片标注
3128
+ * @param {String} image bs64图片地址||图片路径
3129
+ * @param {Array} extent 图片的位置
3130
+ * @return {Number} 图片的id
3131
+ */
3132
+ addImage = async ({ terrainList, extent }) => {
3133
+ Gaea.DecalManager.Instance.PixelToHeightMode =
3134
+ Gaea.PixelToHeightModeEnum.Proportion;
3135
+ Gaea.World.Instance.VerticalExaggeration = 1;
3136
+
3137
+ const terrainName = `${uuid()}地形图.png`;
3138
+ await this.LoadResourceFromUrl(terrainList[0], terrainName);
3139
+ var item = new Gaea.DecalItem();
3140
+ item.ChangeRange(extent[0], extent[1], extent[2], extent[3]);
3141
+
3142
+ item.BaseMapType = 1;
3143
+
3144
+ item.BaseMapPath = `user://resources/${terrainName}`;
3145
+
3146
+ Gaea.DecalManager.Instance.AddItem(item);
3147
+
3148
+ this.dxyb_Arr.push(item);
3149
+ };
3150
+
3151
+ /**
3152
+ * @description: 地形演变
3153
+ * @param {Array<String>} terrainArr 地形图
3154
+ * @param {Number} time 演变速度
3155
+ * @param {Number} verticalExaggeration 夸张倍数
3156
+ */
3157
+ addImageYb = async ({
3158
+ terrainList,
3159
+ extent,
3160
+ verticalExaggeration = 1,
3161
+ minMax,
3162
+ baseMapType,
3163
+ }) => {
3164
+ let item = new Gaea.DecalItem();
3165
+ let item2 = new Gaea.DecalItem();
3166
+ for (var i = 0; i < terrainList.length; i++) {
3167
+ const arr = terrainList[i].split("/");
3168
+ var name = arr[arr.length - 1];
3169
+ await this.LoadResourceFromUrl(terrainList[i], name);
3170
+ }
3171
+ await this.LoadResourceFromUrl(`${serveLocal}/image/色带.png`, `色带.png`);
3172
+ Gaea.DecalManager.Instance.PixelToHeightMode =
3173
+ Gaea.PixelToHeightModeEnum.Absolute;
3174
+ Gaea.DecalManager.Instance.TerrainMapInterpolationValue = 1;
3175
+ Gaea.World.Instance.VerticalExaggeration = verticalExaggeration;
3176
+ item.ChangeRange(extent[0], extent[1], extent[2], extent[3]);
3177
+ item.BaseMapPath = "user://resources/色带.png";
3178
+ let itemArr = terrainList[0].split("/");
3179
+ item.TerrainMapPath = `user://resources/${itemArr[itemArr.length - 1]}`;
3180
+ item.TerrainMinMaxValue = new Gaea.Vector2(0, 232);
3181
+ item.TerrainInvalidValue = 0;
3182
+ item.BaseMapType = 2;
3183
+ Gaea.DecalManager.Instance.AddItem(item);
3184
+
3185
+ item2.ChangeRange(extent[0], extent[1], extent[2], extent[3]);
3186
+ let item2Arr = terrainList[1].split("/");
3187
+ item2.TerrainMapPath = `user://resources/${item2Arr[item2Arr.length - 1]}`;
3188
+ item2.TerrainMinMaxValue = new Gaea.Vector2(0.06, 47);
3189
+ item2.TerrainInvalidValue = 0;
3190
+ item2.BaseMapType = 2;
3191
+ Gaea.DecalManager.Instance.AddItem(item2);
3192
+ // this.changeHeight(0, item, item2, terrainList);
3193
+
3194
+ this.dxyb_Arr.push(item, item2);
3195
+
3196
+ return this.dxyb_Arr;
3197
+ };
3198
+ terrainInterpolationValueChange = (value) => {
3199
+ Gaea.DecalManager.Instance.TerrainMapInterpolationValue = value;
3200
+ };
3201
+ //移除地形演变数据
3202
+ removeTerrainItem = () => {
3203
+ if (this.dxyb_Interval) {
3204
+ clearInterval(this.dxyb_Interval);
3205
+ this.dxyb_Interval = null;
3206
+ }
3207
+
3208
+ this.dxyb_Arr.forEach((element) => {
3209
+ Gaea.DecalManager.Instance.RemoveItem(element);
3210
+ });
3211
+
3212
+ this.dxyb_Arr = [];
3213
+ };
3214
+
3215
+ /**
3216
+ * @description: 视角锁定模式切换
3217
+ * @param {Boolean} mode 锁定模式是否开启
3218
+ * @param {Object} element 需要锁定的模型
3219
+ * @param {Array} Offset3D 从当前点视角看向模型中心点
3220
+ * @return {*}
3221
+ */
3222
+ lockedModesSwitch = (
3223
+ mode,
3224
+ element,
3225
+ Offset3D = [0, 1.1, 0],
3226
+ MinMaxZoom3D = [1.1, 1.1],
3227
+ LockEye = false,
3228
+ GaeaCameraNearFar = [0.1, 1000000000000000],
3229
+ ) => {
3230
+ if (mode) {
3231
+ const ev = new Gaea.EntityView();
3232
+ // const sp = Gaea.Spatial.ConvertBy(element.Root.GetChild(0));
3233
+ ev.Offset3D = new Gaea.Vector3(Offset3D[0], Offset3D[1], Offset3D[2]);
3234
+ ev.LockEye = LockEye;
3235
+ ev.MinMaxZoom3D = new Gaea.Vector2(MinMaxZoom3D[0], MinMaxZoom3D[1]);
3236
+ // ev.GaeaCameraNearFar = new Gaea.Vector2(GaeaCameraNearFar[0], GaeaCameraNearFar[1]);
3237
+ ev.Init(element);
3238
+ if (element) {
3239
+ Gaea.World.Instance.CameraController.LockedEntity = ev;
3240
+ }
3241
+ iconLayerVisible.value = false;
3242
+ return ev
3243
+ } else {
3244
+ Gaea.World.Instance.CameraController.LockedEntity = null;
3245
+ ScreenIconList.value.forEach(item => {
3246
+ if (!item.type) {
3247
+ item.element.UseAutoVisible();
3248
+ item.element.EnablePick = true;
3249
+ }
3250
+ })
3251
+ }
3252
+ };
3253
+
3254
+ // FlyOver = () => {
3255
+ // return new Promise((res, rej) => {
3256
+ // Gaea.World.Instance.DefaultCamera.OnFlyOver = () => {
3257
+ // Gaea.World.Instance.DefaultCamera.OnFlyOver = null;
3258
+ // res();
3259
+ // };
3260
+ // });
3261
+ // };
3262
+
3263
+ FlyOver(callback) {
3264
+ const camera = Gaea.World.Instance.DefaultCamera;
3265
+ camera.OnFlyOverCallBack(() => {
3266
+ console.log("飞行结束");
3267
+ if (callback) {
3268
+ callback();
3269
+ }
3270
+ });
3271
+ }
3272
+
3273
+ /**
3274
+ * @description: gltf模型轨迹动画
3275
+ * @param {Array} trackList 动画轨迹坐标
3276
+ * @param {Object} animationConfig 动画配置
3277
+ * @param {String} animationConfig.animationName 动画名称
3278
+ * @param {String} animationConfig.animationType 动画类型(时间 time & 速度 speed)
3279
+ * @param {Number} animationConfig.animationPlaySpeed 动画时长/动画速度
3280
+ * @param {Boolean} animationConfig.animationLoop 动画循环
3281
+ * @param {Object} element 设置动画的gltf对象
3282
+ * @return {*}
3283
+ */
3284
+ gtlfAnimationPlayer = (trackList, animationConfig, element) => {
3285
+ console.log(animationConfig);
3286
+ // 更新当前模型位置坐标
3287
+ element.GeographyPosition = new Gaea.Vector3(
3288
+ trackList[0].x,
3289
+ trackList[0].y,
3290
+ trackList[0].z
3291
+ );
3292
+ let animationPlayer;
3293
+ // 设置动画参数
3294
+ const { animationName, animationType, animationPlaySpeed, animationLoop } =
3295
+ animationConfig;
3296
+
3297
+ // 创建动画轨迹
3298
+ const line = trackList.map(
3299
+ (item) => new Gaea.Vector3(item.x, item.y, item.z)
3300
+ );
3301
+ let bezierCurve = new Gaea.LineCurve();
3302
+ for (let i = 0; i < line.length; i++) {
3303
+ let control = Gaea.GaeaMath.SphericalToCartesianDeg1(
3304
+ line[i].x,
3305
+ line[i].y,
3306
+ line[i].z
3307
+ );
3308
+ bezierCurve.AddValue(i, control);
3309
+ }
3310
+ // 插值动画配置
3311
+ bezierCurve.Step = 20;
3312
+ bezierCurve.Interpolate(true);
3313
+ bezierCurve.CalculateLengthAfterInterpolation();
3314
+
3315
+ let animation;
3316
+
3317
+ // 动画以速度播放还是时间播放
3318
+ if (animationType === "speed") {
3319
+ animation = bezierCurve.ToAnimationBySpeed(
3320
+ animationName,
3321
+ animationPlaySpeed,
3322
+ element.Scale
3323
+ );
3324
+ } else if (animationType === "time") {
3325
+ animation = bezierCurve.ToAnimationByTime(
3326
+ animationName,
3327
+ true,
3328
+ animationPlaySpeed,
3329
+ element.Scale
3330
+ );
3331
+ }
3332
+
3333
+ // 设置动画是否循环
3334
+ // if (animationLoop) {
3335
+ // animation.Loop = true;
3336
+ // }
3337
+ // console.log(element.Root.GetPath());
3338
+ animation.TrackSetPath(0, element.GetPath());
3339
+ animationPlayer = new Gaea.AnimationPlayer();
3340
+ animationPlayer.AddAnimation(animationName, animation);
3341
+ element.AddChild(animationPlayer, false);
3342
+
3343
+ // if (true) {
3344
+
3345
+ // } else {
3346
+ // animationPlayer = Gaea.AnimationPlayer.ConvertBy(element.GetChild(1));
3347
+ // }
3348
+ Gaea.World.Instance.PlayAnimation(animationPlayer, animationName);
3349
+ return animationPlayer;
3350
+ };
3351
+
3352
+ // 模型平移动画
3353
+ gltfPlayer = (element, targetPos, time = 5) => {
3354
+ // 返回一个 Promise 对象
3355
+ return new Promise((resolve, reject) => {
3356
+ // 先做参数校验,避免无效执行
3357
+ if (!element || !element.TranslateObjectLocal) {
3358
+ reject(new Error('无效的元素对象:缺少 TranslateObjectLocal 方法'));
3359
+ return;
3360
+ }
3361
+ if (!targetPos || typeof targetPos.x !== 'number' || typeof targetPos.y !== 'number' || typeof targetPos.z !== 'number') {
3362
+ reject(new Error('无效的目标位置:必须包含数字类型的 x/y/z 属性'));
3363
+ return;
3364
+ }
3365
+
3366
+ const frameRate = 60; // 帧率(可替换为引擎实际帧率,如 Gaea.Engine.frameRate)
3367
+ const totalFrames = time * frameRate; // 总帧数 = 时长 × 帧率
3368
+ let currentFrame = 0;
3369
+
3370
+ // 总相对位移:从 (0,0,0) 到目标位置的总距离(直接等于目标位置)
3371
+ const totalRelativeOffset = { ...targetPos };
3372
+
3373
+ // 记录已累加的总位移(关键:避免相对位移叠加混乱)
3374
+ let currentCumulativeOffset = { x: 0, y: 0, z: 0 };
3375
+
3376
+ try {
3377
+ // 第一步:纯相对位移重置到 (0,0,0)(抵消之前可能的位移)
3378
+ element.TranslateObjectLocal(new Gaea.Vector3(-currentCumulativeOffset.x, -currentCumulativeOffset.y, -currentCumulativeOffset.z));
3379
+ currentCumulativeOffset = { x: 0, y: 0, z: 0 }; // 重置累计记录
3380
+
3381
+ // 每帧固定小步位移(总位移 ÷ 总帧数,匀速核心)
3382
+ const fixedStep = {
3383
+ x: totalRelativeOffset.x / totalFrames,
3384
+ y: totalRelativeOffset.y / totalFrames,
3385
+ z: totalRelativeOffset.z / totalFrames,
3386
+ };
3387
+
3388
+ // 帧循环:逐帧累加相对位移
3389
+ const moveStep = () => {
3390
+ // 动画结束:补差确保精准到达目标
3391
+ if (currentFrame >= totalFrames) {
3392
+ const finalCompensate = {
3393
+ x: totalRelativeOffset.x - currentCumulativeOffset.x,
3394
+ y: totalRelativeOffset.y - currentCumulativeOffset.y,
3395
+ z: totalRelativeOffset.z - currentCumulativeOffset.z,
3396
+ };
3397
+ element.TranslateObjectLocal(new Gaea.Vector3(finalCompensate.x, finalCompensate.y, finalCompensate.z));
3398
+ currentCumulativeOffset = { ...totalRelativeOffset };
3399
+ const result = {
3400
+ success: true,
3401
+ targetPos,
3402
+ actualPos: currentCumulativeOffset,
3403
+ message: `匀速动画完成,已到达目标位置:${JSON.stringify(targetPos)}`
3404
+ };
3405
+ console.log(result.message);
3406
+ // 动画完成,resolve Promise
3407
+ resolve(result);
3408
+ return;
3409
+ }
3410
+
3411
+ // 执行当前帧相对位移(累加小步)
3412
+ element.TranslateObjectLocal(new Gaea.Vector3(fixedStep.x, fixedStep.y, fixedStep.z));
3413
+
3414
+ // 更新累计位移(确保下次计算补差准确)
3415
+ currentCumulativeOffset.x += fixedStep.x;
3416
+ currentCumulativeOffset.y += fixedStep.y;
3417
+ currentCumulativeOffset.z += fixedStep.z;
3418
+
3419
+ currentFrame++;
3420
+ // 继续下一帧(优先用引擎自带帧循环,如 Gaea.Engine.onUpdate(moveStep))
3421
+ requestAnimationFrame(moveStep);
3422
+ };
3423
+
3424
+ // 启动动画
3425
+ moveStep();
3426
+ } catch (error) {
3427
+ // 捕获执行过程中的异常,reject Promise
3428
+ reject(new Error(`动画执行出错:${error.message}`));
3429
+ }
3430
+ });
3431
+ };
3432
+
3433
+ // 旋转动画
3434
+ FlyAroundPoint = (element, targetAngle, time, callbacks = {}) => {
3435
+ const {
3436
+ onStart = () => { },
3437
+ onUpdate = () => { },
3438
+ onComplete = () => { }
3439
+ } = callbacks;
3440
+
3441
+ if (!targetAngle || !element) {
3442
+ console.warn("参数无效");
3443
+ onComplete(null);
3444
+ return;
3445
+ }
3446
+
3447
+ // 用来记录上一帧角度,计算差值
3448
+ let lastAngle = 0;
3449
+ let currentAngle = 0;
3450
+
3451
+ // TWEEN 动画
3452
+ const tween = new Tween({ angle: 0 })
3453
+ .to({ angle: targetAngle }, time)
3454
+ .easing(Easing.Quadratic.InOut)
3455
+ .onStart(() => {
3456
+ console.log("动画开始");
3457
+ onStart();
3458
+ })
3459
+ .onUpdate((obj) => {
3460
+ // 拿到当前插值角度
3461
+ currentAngle = obj.angle;
3462
+
3463
+ // 只传【差值】,不是传总角度!
3464
+ const delta = currentAngle - lastAngle;
3465
+
3466
+ element.RotateObjectLocal(new Gaea.Vector3(0, 1, 0), delta);
3467
+
3468
+ lastAngle = currentAngle;
3469
+ onUpdate(currentAngle);
3470
+ })
3471
+ .onComplete(() => {
3472
+ console.log("动画完成");
3473
+ onComplete(targetAngle);
3474
+ this.tweenGroup.remove(tween);
3475
+ });
3476
+
3477
+ this.tweenGroup.add(tween);
3478
+ tween.start();
3479
+ };
3480
+
3481
+ /**
3482
+ * 测量工具
3483
+ * @param {string} type 绘制的类型, 支持地表距离,空间距离,高度,面积
3484
+ * @param {boolean} isNeedTilePipe 是否选择3Dtiles,管线,默认为false
3485
+ * @param {boolean} isNeedAutoClearToop 是否切换工具时自动清除element
3486
+ * @param {Gaea.Color} outlinecolor 字体外边框颜色
3487
+ * @param {number} outlinesize 外边框大小
3488
+ * @param {number} size 字体大小
3489
+ * @param {Gaea.Vector2} GUIVisibleRange gui可见高度范围
3490
+ * @param {function} cb 回调函数
3491
+ */
3492
+ MeasureToolsWithoutVolume = async (
3493
+ type,
3494
+ isNeedTilePipe = false,
3495
+ isNeedAutoClearToop = true,
3496
+ outlinecolor = new Gaea.Color(1, 0, 0, 1),
3497
+ outlinesize = 1,
3498
+ size = 13,
3499
+ GUIVisibleRange = new Gaea.Vector2(0, 350000),
3500
+ cb = () => { }
3501
+ ) => {
3502
+ try {
3503
+ //声明地表距离测量工具
3504
+ console.log("MyMethod:", type);
3505
+ const tool = new types[type]();
3506
+ // 是否可以选中3Dtiles、管线,默认为false
3507
+ tool.NeedIntersectWithMesh = isNeedTilePipe;
3508
+ // 是否在切换工具时自动清除Element,默认为true
3509
+ tool.DeleteElementOnDispose = isNeedAutoClearToop;
3510
+ // 外边框大小
3511
+ tool.MeasureFont.OutlineSize = outlinesize;
3512
+ //字体外边框颜色
3513
+ tool.MeasureFont.OutlineColor = outlinecolor;
3514
+ //字体大小
3515
+ tool.MeasureFont.Size = size;
3516
+ // GUI可见高度范围设置
3517
+ tool.GUIVisibleRange = GUIVisibleRange;
3518
+ Gaea.World.Instance.SetCurrentTool(tool);
3519
+ // 回调函数
3520
+ const items = {
3521
+ tool: tool,
3522
+ isVolume: false,
3523
+ };
3524
+ // debugger
3525
+ cb(items);
3526
+ } catch (error) {
3527
+ console.error("出错了:", error.message);
3528
+ }
3529
+ };
3530
+
3531
+ /**
3532
+ * 清除球工具对象
3533
+ */
3534
+ ClearToolsWithoutVolume = async () => {
3535
+ Gaea.World.Instance.SetCurrentTool(null);
3536
+ };
3537
+
3538
+ /**
3539
+ *
3540
+ * @param {string} type 绘制的类型, 支持地表距离,空间距离,高度,面积
3541
+ * @param {number} height 深度
3542
+ * @param {boolean} isNeedTilePipe 是否选择3Dtiles,管线,默认为false
3543
+ * @param {boolean} isNeedAutoClearToop 是否切换工具时自动清除element
3544
+ * @param {Gaea.Color} outlinecolor 字体外边框颜色
3545
+ * @param {number} outlinesize 外边框大小
3546
+ * @param {number} size 字体大小
3547
+ * @param {Gaea.Vector2} GUIVisibleRange gui可见高度范围
3548
+ * @param {function} cb 回调函数
3549
+ */
3550
+ MeasureToolsVolume = async (
3551
+ type,
3552
+ height,
3553
+ isNeedTilePipe = false,
3554
+ isNeedAutoClearToop = true,
3555
+ outlinecolor = new Gaea.Color(1, 0, 0, 1),
3556
+ outlinesize = 1,
3557
+ size = 13,
3558
+ GUIVisibleRange = new Gaea.Vector2(0, 350000),
3559
+ cb = () => { }
3560
+ ) => {
3561
+ try {
3562
+ //画面工具
3563
+ const tool = new types[type]();
3564
+ // 是否可以选中3Dtiles、管线,默认为false
3565
+ tool.NeedIntersectWithMesh = isNeedTilePipe;
3566
+ // 是否在切换工具时自动清除Element,默认为true
3567
+ tool.DeleteElementOnDispose = isNeedAutoClearToop;
3568
+ // 外边框大小
3569
+ tool.MeasureFont.OutlineSize = outlinesize;
3570
+ //字体外边框颜色
3571
+ tool.MeasureFont.OutlineColor = outlinecolor;
3572
+ //字体大小
3573
+ tool.MeasureFont.Size = size;
3574
+ // GUI可见高度范围设置
3575
+ tool.GUIVisibleRange = GUIVisibleRange;
3576
+ if (height != null) {
3577
+ tool.holeDepth = height;
3578
+ }
3579
+ //工具挂载在世界节点
3580
+ Gaea.World.Instance.SetCurrentTool(tool);
3581
+ let elements = [];
3582
+ let holeitem = null;
3583
+ tool.OverDrawCallback = () => {
3584
+ holeitem = tool._Holeitem;
3585
+ // CurrentElement = tool.Element;
3586
+ // elements.push(CurrentElement);
3587
+ elements.push(tool.Element);
3588
+ // 回调函数
3589
+ const items = {
3590
+ elements: elements,
3591
+ holeitem: holeitem,
3592
+ isVolume: true,
3593
+ };
3594
+ console.log("Volume OverDrawCallBack:", items);
3595
+ // debugger;
3596
+ cb(items);
3597
+ };
3598
+ } catch (error) {
3599
+ console.error("出错了:", error.message);
3600
+ }
3601
+ };
3602
+
3603
+ /**
3604
+ *
3605
+ * @param {array} eles 元素列表
3606
+ * @param {*} holeitem 空洞
3607
+ */
3608
+ ClearVolume = async (eles, holeitem) => {
3609
+ //清除所有对象
3610
+ Gaea.World.Instance.SetCurrentTool(null);
3611
+ console.log("长度:", eles.length);
3612
+ //清除前端获取到的Element对象
3613
+ eles.forEach((element) => {
3614
+ Gaea.World.Instance.RenderableObjectList.Remove(element);
3615
+ });
3616
+ if (holeitem != null) {
3617
+ Gaea.ExcavationManager.Instance.RemoveItem(holeitem);
3618
+ }
3619
+ Gaea.ExcavationManager.Instance.Clear();
3620
+ if (Gaea.QueryServer.Instance != null) {
3621
+ if (Gaea.QueryServer.Instance.ClipBox.InstanceID != null) {
3622
+ Gaea.QueryServer.Instance.ClipBox.QueueFree();
3623
+ Gaea.QueryServer.Instance.ClipBox = null;
3624
+ }
3625
+ }
3626
+ };
3627
+
3628
+ /**
3629
+ * 测量工具
3630
+ * @param {string} type 绘制的类型, 支持地表距离,空间距离,高度,面积
3631
+ * @param {boolean} isNeedTilePipe 是否选择3Dtiles,管线,默认为false
3632
+ * @param {boolean} isNeedAutoClearToop 是否切换工具时自动清除element
3633
+ * @param {Gaea.Color} outlinecolor 字体外边框颜色
3634
+ * @param {number} outlinesize 外边框大小
3635
+ * @param {number} size 字体大小
3636
+ * @param {Gaea.Vector2} GUIVisibleRange gui可见高度范围
3637
+ * @param {function} cb 回调函数
3638
+ */
3639
+ MeasureTools = async (
3640
+ type,
3641
+ isVolume = false,
3642
+ height = 13,
3643
+ isNeedTilePipe = false,
3644
+ isNeedAutoClearToop = true,
3645
+ outlinecolor = new Gaea.Color(1, 0, 0, 1),
3646
+ outlinesize = 1,
3647
+ size = 13,
3648
+ GUIVisibleRange = new Gaea.Vector2(0, 350000),
3649
+ cb = () => { }
3650
+ ) => {
3651
+ if (isVolume) {
3652
+ this.MeasureToolsVolume(
3653
+ type,
3654
+ height,
3655
+ isNeedTilePipe,
3656
+ isNeedAutoClearToop,
3657
+ outlinecolor,
3658
+ outlinesize,
3659
+ size,
3660
+ GUIVisibleRange,
3661
+ (items) => {
3662
+ cb(items);
3663
+ }
3664
+ );
3665
+ } else {
3666
+ this.MeasureToolsWithoutVolume(
3667
+ type,
3668
+ isNeedTilePipe,
3669
+ isNeedAutoClearToop,
3670
+ outlinecolor,
3671
+ outlinesize,
3672
+ size,
3673
+ GUIVisibleRange,
3674
+ (items) => {
3675
+ cb(items);
3676
+ }
3677
+ );
3678
+ }
3679
+ };
3680
+ /**
3681
+ *
3682
+ * @param {boolean} isVolume 是否清理体积工具
3683
+ * @param {Gaea.Element} eles element对象
3684
+ * @param {*} holeitem 空洞对象
3685
+ */
3686
+ ClearMeasure = (isVolume, items = null) => {
3687
+ if (isVolume) {
3688
+ this.ClearVolume(items.elements, items.holeitem);
3689
+ } else {
3690
+ this.ClearToolsWithoutVolume();
3691
+ }
3692
+ };
3693
+ Dig = async (depth = 5, cb = () => { }) => {
3694
+ const tool = new Gaea.DigTool();
3695
+ Gaea.World.Instance.SetCurrentTool(tool);
3696
+ let box = null;
3697
+ let _Holeitem = null;
3698
+ tool.OverDraw = () => {
3699
+ if (box) {
3700
+ Gaea.World.Instance.RemoveChild(box);
3701
+ }
3702
+ if (_Holeitem) {
3703
+ Gaea.ExcavationManager.Instance.RemoveItem(_Holeitem);
3704
+ }
3705
+ var poly = tool.GetPolygon();
3706
+ Gaea.ExcavationManager.Instance.ExposureLength = 0;
3707
+ // 创建挖方对象,参数为(坐标点,地形插值点之间的距离,深度,UV缩放值,是否需要法线材质)
3708
+ _Holeitem = Gaea.ExcavationManager.Instance.CreateItem(
3709
+ poly,
3710
+ 100,
3711
+ depth,
3712
+ 100,
3713
+ true,
3714
+ true
3715
+ );
3716
+ Gaea.ExcavationManager.Instance.AddItem(_Holeitem);
3717
+ Gaea.ExcavationManager.Instance.NeedFence = true;
3718
+
3719
+ if (Gaea.QueryServer.Instance != null) {
3720
+ var mtl = Gaea.GaeaResourceLoader.Instance.LoadLoaclResource(
3721
+ "res://assets/material/mtl1.material"
3722
+ );
3723
+ var spmtl = Gaea.SpatialMaterial.ConvertBy(mtl);
3724
+ spmtl.FlagsUnshaded = false;
3725
+ spmtl.FlagsDisableAmbientLight = false;
3726
+ Gaea.ExcavationManager.Instance.FenceHeight = 10;
3727
+ box = Gaea.World.Instance.SimplePolygonGenerater(
3728
+ poly,
3729
+ false,
3730
+ false,
3731
+ false,
3732
+ false,
3733
+ Gaea.ExcavationManager.Instance.FenceHeight,
3734
+ 0,
3735
+ 2,
3736
+ Gaea.ExcavationManager.Instance.FenceHeight
3737
+ );
3738
+ Gaea.World.Instance.AddChild(box, false);
3739
+ Gaea.QueryServer.Instance.ClipBoxMaterial = spmtl;
3740
+ Gaea.QueryServer.Instance.ClipBox = box;
3741
+ }
3742
+ const item = {
3743
+ holeitem: _Holeitem,
3744
+ };
3745
+ cb(item);
3746
+ };
3747
+ };
3748
+ // 清理挖方
3749
+ Clear = async (item) => {
3750
+ if (item.holeitem) {
3751
+ Gaea.ExcavationManager.Instance.RemoveItem(item._Holeitem);
3752
+ }
3753
+ Gaea.ExcavationManager.Instance.Clear();
3754
+ if (Gaea.QueryServer.Instance != null) {
3755
+ if (Gaea.QueryServer.Instance.ClipBox.InstanceID != null) {
3756
+ Gaea.QueryServer.Instance.ClipBox.QueueFree();
3757
+ Gaea.QueryServer.Instance.ClipBox = null;
3758
+ }
3759
+ }
3760
+ };
3761
+ // 添加3dtiles
3762
+ // 用于添加3dtiles
3763
+ Add3Dtiles = async (tilesObj, isClip, callback = () => { }) => {
3764
+ console.log('Add3Dtiles');
3765
+ let {
3766
+ tilsName,
3767
+ jsonUrl,
3768
+ height
3769
+ } = tilesObj;
3770
+ const tdtile = new Gaea.Gaea3DTileset();
3771
+ // 对象名
3772
+ tdtile.Name = tilsName;
3773
+ // 地址
3774
+ tdtile.TilesetUrl = jsonUrl;
3775
+ // 能否点击
3776
+ tdtile.EnablePick = true;
3777
+ tdtile.UseLight = false;
3778
+ tdtile.SkipLevelOfDetail = false;
3779
+ // NOTE: 告诉球 模型是不是Z朝上的。 让系统知道怎么去加载才能让你的模型是垂直于地表的
3780
+ tdtile.IsZUp = true;
3781
+ tdtile.BaseUrl = jsonUrl.slice(0, jsonUrl.lastIndexOf("/") + 1);
3782
+ //初始化
3783
+ tdtile.InitTileSet(tilsName, jsonUrl);
3784
+ tdtile.EnabledClip = isClip;
3785
+ tdtile.MaximumMemoryUsage = 512;
3786
+ tdtile.MaximumScreenSpaceError = 16;
3787
+ //高度偏移,Vector3的x,y,z表示在三个方向的偏移值
3788
+ // NOTE: LocalOffset的x,y,z的轴向是由加载的模型自己决定朝向的
3789
+ tdtile.LocalOffset = new Gaea.Vector3(0, 0, 0);
3790
+ // tdtile.LocalOffset = new Gaea.Vector3(0, -5, 0);
3791
+ //添加到世界节点
3792
+ Gaea.World.Instance.RenderableObjectList.AddLast(tdtile);
3793
+ callback(tdtile);
3794
+ console.log(`倾斜${tilsName}加载成功`);
3795
+ };
3796
+
3797
+
3798
+ /**
3799
+ *画面方法(有高度,不贴地)
3800
+ *
3801
+ * @param {*} pointList 坐标数组
3802
+ * @param {*} EnablePick 是否点击
3803
+ * @param {*} EnableEdit 是否编辑
3804
+ * @param {*} NeedIntersectWithMesh 允许在3Dtiles、管线、挖方等位置编辑
3805
+ * @param {*} InitialFillColor 画面的颜色
3806
+ * @param {*} HasOutLine 是否存在边线
3807
+ * @param {*} PolygonLineColor 边线的颜色
3808
+ * @memberof App
3809
+ */
3810
+ drawPolygon(pointList, EnablePick, EnableEdit, NeedIntersectWithMesh, InitialFillColor, HasOutLine, PolygonLineColor) {
3811
+ let PolygonElement;
3812
+ // 点数组,(纬度,经度,到球心距离)
3813
+ let Position = pointList.map(item => {
3814
+ return new Gaea.Vector3(item[0], item[1], 50)
3815
+ })
3816
+ // 根据坐标点创建几何对象,参数(几何形状类型,几何数据)
3817
+ var geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Polygon, Position);
3818
+ // 创建PointGeometryElement对象
3819
+ PolygonElement = new Gaea.PolygonGeometryElement();
3820
+ // 赋值
3821
+ PolygonElement.Shape = geometry;
3822
+ // 允许点击
3823
+ PolygonElement.EnablePick = EnablePick;
3824
+ // 允许编辑
3825
+ PolygonElement.EnableEdit = EnableEdit;
3826
+ // 允许在3Dtiles、管线、挖方等位置编辑
3827
+ PolygonElement.NeedIntersectWithMesh = NeedIntersectWithMesh;
3828
+ //开启虚拟点
3829
+ PolygonElement.EnableVirtualPoint = true;
3830
+ PolygonElement.InitialFillColor = new Gaea.Color(InitialFillColor[0], InitialFillColor[1], InitialFillColor[2], 1)
3831
+
3832
+ var PolygonSimpleFillSymbol = Gaea.SimpleFillSymbol.ConvertBy(PolygonElement.Symbol);
3833
+ PolygonSimpleFillSymbol.HasOutLine = HasOutLine;
3834
+ PolygonSimpleFillSymbol.OutLineSymbol.SymbolColor = new Gaea.Color(PolygonLineColor[0], PolygonLineColor[1], PolygonLineColor[2], 1);
3835
+
3836
+ //选中的回调事件
3837
+ PolygonElement.SelectedCallBack((a, b, c, d, e, f) => {
3838
+ if (c) {
3839
+ //获取选中element
3840
+ selectelement = new Gaea.PolygonGeometryElement(false);
3841
+ selectelement.InstanceID = a + "";
3842
+ }
3843
+ });
3844
+ // 将Element加入到场景中
3845
+ Gaea.World.Instance.RenderableObjectList.AddLast(PolygonElement);
3846
+ this.elements.push(PolygonElement);
3847
+ return PolygonElement;
3848
+ }
3849
+
3850
+ /**
3851
+ * 修改面颜色
3852
+ *
3853
+ * @param {*} PolygonElement 面对象
3854
+ * @param {*} PolygonColor 面颜色
3855
+ * @memberof App
3856
+ */
3857
+ updatePolygonColor(PolygonElement, PolygonColor) {
3858
+ PolygonElement.InitialFillColor = new Gaea.Color(PolygonColor[0], PolygonColor[1], PolygonColor[2], 1)
3859
+ }
3860
+
3861
+ /**
3862
+ * 画贴地面
3863
+ *
3864
+ * @param {*} list 贴地面数据数组
3865
+ * @param {*} color 贴地面颜色
3866
+ * @memberof App
3867
+ */
3868
+ AddGroundPolygonByGeojson(list, color) {
3869
+ list.forEach((item) => {
3870
+ var geojsonFile = `${item}.geojson`; //设置保存时的文件名,要带拓展名
3871
+ var geojson_res = "user://resources/"; //设置保存目录
3872
+ //请求geojson文件并保存,加载
3873
+ Gaea.GaeaResourceLoader.Instance.LoadResourceFromUrl1(`${window.location.origin}/geojson/海塘边界/${item}.geojson`, geojsonFile, (code, msg) => {
3874
+ if (code == 200) {
3875
+ var ws = Gaea.WorkspaceFactory.OpenFromFile(geojson_res + geojsonFile); //打开文件
3876
+ var fclass = ws.OpenFeatureClass(true, false); //读取文件,构建FeatureClass
3877
+ var flayer = new Gaea.FeatureLayer(); //创建一个FeatureLayer图层
3878
+ // 贴地面
3879
+ var res = Gaea.GaeaResourceLoader.Instance.LoadLoaclResource("res://assets/shaders/polygonClampGround.shader");
3880
+ var shader = Gaea.Shader.ConvertBy(res);
3881
+ var material = new Gaea.ShaderMaterial();
3882
+ material.Shader = shader;
3883
+ Gaea.World.Instance.SetMtlColor(material, "albedo", new Gaea.Color(color[0] / 255, color[1] / 255, color[2] / 255, 0.5)); //设置颜色
3884
+ var Symbol = new Gaea.GroundPolygonSymbol();
3885
+ Symbol.PrismHeight = 9999;
3886
+ Symbol.GroundPolygonMtl = material;
3887
+ var FeatureRenderer = new Gaea.SimpleFeatureRenderer(); //创建一个渲染器
3888
+ FeatureRenderer.Symbol = Symbol; //设置渲染器的符号
3889
+ flayer.VisibleRange = new Gaea.Vector2(0, 1000000); //设置可见高度范围
3890
+ flayer.FeatureClass = fclass; //设置图层中的数据,即fclass
3891
+ flayer.FeatureRenderer = FeatureRenderer; //设置图层中的渲染器, 即FeatureRenderer
3892
+ flayer.Name = item; //设置图层名称
3893
+ this.groundPolygon.push(item);
3894
+ Gaea.World.Instance.RenderableObjectList.AddLast(flayer); //将图层添加到可渲染对象列表
3895
+ }
3896
+ });
3897
+ });
3898
+ }
3899
+ // 清除贴地面
3900
+ ClearPolygon(name) {
3901
+ var node = Gaea.World.Instance.RenderableObjectList.GetByName(name);
3902
+ if (node != null) {
3903
+ Gaea.World.Instance.RenderableObjectList.Remove(node);
3904
+ this.groundPolygon = [];
3905
+ }
3906
+ }
3907
+
3908
+ AddGroundLineByGeojson = (list, color) => {
3909
+ let that = this;
3910
+
3911
+ list.forEach((item) => {
3912
+ var geojsonFile = `${item}.geojson`; //设置保存时的文件名,要带拓展名
3913
+ var res = "user://resources/"; //设置保存目录
3914
+ //请求geojson文件并保存,加载
3915
+ let existingIndex = this.groundWire.findIndex((item) => item.name == item);
3916
+ if (existingIndex > -1) {
3917
+ console.warn(item, "贴地线已经存在!!");
3918
+ return;
3919
+ }
3920
+ Gaea.GaeaResourceLoader.Instance.LoadResourceFromUrl1(`${window.location.origin}/static/geojson/${item}.geojson`, geojsonFile, (code, msg) => {
3921
+ if (code == 200) {
3922
+ // var geojsonWorkspace = new Gaea.GeojsonWorkspace();
3923
+ // var fclass = geojsonWorkspace.OpenFeatureClassWithGeoJsonStr(res + geojsonFile, true);
3924
+ var ws = Gaea.WorkspaceFactory.OpenFromFile(res + geojsonFile); //打开文件
3925
+ var fclass = ws.OpenFeatureClass(true, false); //读取文件,构建FeatureClass
3926
+ var flayer = new Gaea.FeatureLayer(); //创建一个FeatureLayer图层
3927
+ var Symbol = new Gaea.GroundPolylineSymbol();
3928
+ Symbol.Width = 3;
3929
+ Symbol.LineColor = new Gaea.Color(color[0] / 255, color[1] / 255, color[2] / 255, 1);
3930
+ var FeatureRenderer = new Gaea.SimpleFeatureRenderer(); //创建一个渲染器
3931
+ FeatureRenderer.Symbol = Symbol; //设置渲染器的符号
3932
+ flayer.VisibleRange = new Gaea.Vector2(0, 1000000); //设置可见高度范围
3933
+ flayer.FeatureClass = fclass; //设置图层中的数据,即fclass
3934
+ flayer.FeatureRenderer = FeatureRenderer; //设置图层中的渲染器, 即FeatureRenderer
3935
+ flayer.Name = item; //设置图层名称
3936
+ Gaea.World.Instance.RenderableObjectList.AddLast(flayer); //将图层添加到可渲染对象列表
3937
+ that.groundWire.push({
3938
+ name: item,
3939
+ flayer,
3940
+ });
3941
+ }
3942
+ });
3943
+ });
3944
+ };
3945
+
3946
+ /**
3947
+ * 根据画出的多边形裁剪出地形工具
3948
+ * @param {*} pointList 坐标点数组
3949
+ * @param {*} height 裁剪高度
3950
+ * @param {*} callback 回调函数
3951
+ * @returns
3952
+ */
3953
+ editTerrainTool = (pointList, height, callback) => {
3954
+ // var tool = new Gaea.DigTool();
3955
+ // tool.CutInside = false;
3956
+ // Gaea.World.Instance.SetCurrentTool(tool);
3957
+ var Position = [];
3958
+ if (pointList.length > 0) {
3959
+ pointList.forEach((point) => {
3960
+ Position.push(new Gaea.Vector3(point.x, point.y, point.z));
3961
+ });
3962
+ } else {
3963
+ return false;
3964
+ }
3965
+ var OriginPoint = [];
3966
+ Position.forEach((element) => {
3967
+ OriginPoint.push(Gaea.GaeaMath.SphericalToCartesianDeg(element));
3968
+ });
3969
+ var _Holeitem = Gaea.ExcavationManager.Instance.CreateItem(OriginPoint, 100, height, 1, true, false);
3970
+ if (Gaea.QueryServer.Instance != null) {
3971
+ var box = Gaea.World.Instance.SimplePolygonGenerater(Position, false, false, false, false, Gaea.ExcavationManager.Instance.FenceHeight, 0, 2, 1000);
3972
+ Gaea.World.Instance.AddChild(box, false);
3973
+ Gaea.QueryServer.Instance.ClipBox = box;
3974
+ }
3975
+ Gaea.QueryServer.Instance.ClipInside = true;
3976
+ Gaea.ExcavationManager.Instance.ClipInside3dtiles = false;
3977
+ Gaea.ExcavationManager.Instance.ClipInsideVector = true;
3978
+ Gaea.ExcavationManager.Instance.AddItem(_Holeitem);
3979
+ // var camera = Gaea.World.Instance.DefaultCamera;
3980
+ // camera.SetPosition2(30, 112, 0, 3000, 0, 0);
3981
+ setTimeout(function () {
3982
+ // 调用回调函数
3983
+ if (typeof callback === "function") {
3984
+ callback(_Holeitem);
3985
+ }
3986
+ }, 1000); // 设置延迟为1000毫秒
3987
+ };
3988
+
3989
+ /**
3990
+ * 裁剪还原
3991
+ */
3992
+ restoreTerrain = () => {
3993
+ Gaea.World.Instance.SetCurrentTool(null);
3994
+ if (Gaea.QueryServer.Instance.ClipBox != null) {
3995
+ // Gaea.QueryServer.Instance.ClipBox.QueueFree();
3996
+ Gaea.QueryServer.Instance.ClipBox = null;
3997
+ Gaea.ExcavationManager.Instance.Clear();
3998
+ }
3999
+ };
4000
+
4001
+ Dig() {
4002
+ var mtl = Gaea.GaeaResourceLoader.Instance.LoadLoaclResource(
4003
+ "res://assets/material/围挡.material"
4004
+ );
4005
+ var spmtl = Gaea.SpatialMaterial.ConvertBy(mtl);
4006
+ spmtl.FlagsUnshaded = false;
4007
+ spmtl.FlagsDisableAmbientLight = false;
4008
+ Gaea.ExcavationManager.Instance.FenceHeight = 10;
4009
+ Gaea.QueryServer.Instance.ClipBoxMaterial = spmtl;
4010
+ var digTool = new Gaea.DigTool();
4011
+ digTool.CutInside = false;
4012
+ Gaea.World.Instance.SetCurrentTool(null);
4013
+ Gaea.World.Instance.SetCurrentTool(digTool);
4014
+ Gaea.QueryServer.Instance.ClipInside = true;
4015
+ Gaea.ExcavationManager.Instance.FenceHeight = 50;
4016
+ Gaea.ExcavationManager.Instance.NeedFence = false;
4017
+ Gaea.ExcavationManager.Instance.ExposureLength = 0;
4018
+ }
4019
+
4020
+ AddSea() {
4021
+ var sea = null;
4022
+ const sunObj = Gaea.World.Instance.GetNode("Sun");
4023
+ const sun = Gaea.Sun.ConvertBy(sunObj);
4024
+ sun.TimeScale = 0.0;
4025
+ sun.TimeString = "2022-09-15 12:00:00"
4026
+ var mtl = Gaea.World.Instance.FullScreenQuad.GetWeatherShader();
4027
+ Gaea.World.Instance.SetMtlFloat(mtl, "caustics_scale", 0.158);
4028
+ Gaea.World.Instance.SetMtlFloat(mtl, "caustics_mix", 0.522);
4029
+ Gaea.World.Instance.SetMtlColor(mtl, "fog_color", new Gaea.Color(0.043, 0.17, 0.235, 1.0));
4030
+
4031
+ if (!sea) {
4032
+ sea = new Gaea.DrawOcean()
4033
+ sea.OceanType = 0;
4034
+ sea.FogColor = new Gaea.Color(0.26, 0.39, 0.44, 1.0);
4035
+ sea.FogDepthBegin = 0.0;
4036
+ sea.FogDepthEnd = 1000.0;
4037
+ sea.UnderWaterColor = new Gaea.Color(0.26, 0.39, 0.44, 0.73);
4038
+ sea.MeanHeight = 50.0;
4039
+ sea.SeaBase = new Gaea.Color(0.027, 0.098, 0.173, 1.0);
4040
+ sea.SeaHeight = 0.7;
4041
+ sea.SeaChoppy = 6;
4042
+ sea.SeaFreq = 0.16;
4043
+ // seacolor = new Gaea.Color(0.027, 0.098, 0.173, 1.0);
4044
+ Gaea.World.Instance.AddChild(sea, false);
4045
+ Gaea.World.Instance.HasWater = true;
4046
+ sea.SeaWaterColor = new Gaea.Color(0, 0, 0, 0.78);
4047
+ // seas.push(sea)
4048
+ var f = Gaea.WeatherManager.ConvertBy(Gaea.World.Instance.FullScreenQuad);
4049
+ var mtl = Gaea.ShaderMaterial.ConvertBy(f.GetWeatherShader());
4050
+ mtl.RenderPriority = 120;
4051
+ }
4052
+ //Gaea.World.Instance.DefaultCamera.SetPosition(24.1558538968461, 120.39105397970);
4053
+ // LoadGLTF1();
4054
+ }
4055
+
4056
+ /**
4057
+ * 沿线飞行 - 相机沿路径自动飞行
4058
+ * @param {Array} lineData - 路径点数组,每个点格式 {x: 纬度, y: 经度}
4059
+ * @param {Object} options - 飞行配置选项
4060
+ * @param {number} options.height - 飞行高度(米),默认 150
4061
+ * @param {number} options.step - 插值步数,默认 1000
4062
+ * @param {number} options.duration - 飞行时长(秒),默认 20
4063
+ * @param {number} options.xrotation - X轴旋转角度(俯仰角),默认 -30
4064
+ * @param {boolean} options.lockEye - 是否锁定相机视角,默认 true
4065
+ * @param {number} options.minZoom - 最小缩放距离,默认 0
4066
+ * @param {number} options.maxZoom - 最大缩放距离,默认 400
4067
+ * @returns {Promise} - 飞行完成后 resolve
4068
+ */
4069
+ flyAlongPath = async (lineData, options = {}) => {
4070
+ const opts = {
4071
+ height: 200,
4072
+ step: 1000,
4073
+ duration: 20.0,
4074
+ xrotation: 30,
4075
+ lockEye: false,
4076
+ minZoom: 200,
4077
+ maxZoom: 1000,
4078
+ ...options
4079
+ };
4080
+
4081
+ if (!lineData || lineData.length < 2) {
4082
+ console.error('flyAlongPath: 至少需要2个路径点');
4083
+ return Promise.reject(new Error('至少需要2个路径点'));
4084
+ }
4085
+
4086
+ try {
4087
+ this._cleanupFlyResources();
4088
+
4089
+ const bezierCurve = new Gaea.UniformCubicSpline();
4090
+ for (let i = 0; i < lineData.length; i++) {
4091
+ const control = Gaea.GaeaMath.SphericalToCartesianDeg(
4092
+ new Gaea.Vector3(lineData[i].x, lineData[i].y, opts.height)
4093
+ );
4094
+ bezierCurve.AddValue(i, control);
4095
+ }
4096
+ bezierCurve.Step = opts.step;
4097
+ bezierCurve.Interpolate(true);
4098
+ bezierCurve.CalculateLengthAfterInterpolation();
4099
+
4100
+ const startPos = Gaea.GaeaMath.SphericalToCartesianDeg(
4101
+ new Gaea.Vector3(lineData[0].x, lineData[0].y, opts.height)
4102
+ );
4103
+
4104
+ const mesh = new Gaea.CubeMesh();
4105
+ mesh.Size = new Gaea.Vector3(1, 1, 1);
4106
+
4107
+ const mtl = new Gaea.SpatialMaterial();
4108
+ mtl.AlbedoColor = new Gaea.Color(1, 0, 0, 1);
4109
+ mesh.SurfaceSetMaterial(0, mtl);
4110
+
4111
+ this._flyModelInstance = new Gaea.MeshInstance();
4112
+ this._flyModelInstance.Name = 'flyPathModel';
4113
+ this._flyModelInstance.Visible = false;
4114
+ this._flyModelInstance.Translation = startPos;
4115
+ Gaea.World.Instance.AddChild(this._flyModelInstance, false);
4116
+
4117
+ this._flyEntityView = new Gaea.EntityView();
4118
+ this._flyEntityView.Offset3D = new Gaea.Vector3(
4119
+ -1,
4120
+ 0,
4121
+ Math.tan(opts.xrotation / 180 * Math.PI)
4122
+ );
4123
+ this._flyEntityView.LockEye = opts.lockEye;
4124
+ this._flyEntityView.MinMaxZoom3D = new Gaea.Vector2(opts.minZoom, opts.maxZoom);
4125
+ this._flyEntityView.Init(this._flyModelInstance);
4126
+ Gaea.World.Instance.CameraController.LockedEntity = this._flyEntityView;
4127
+
4128
+ this._flyAnimation = bezierCurve.ToAnimationByTime(
4129
+ 'flyPathAnimation',
4130
+ true,
4131
+ opts.duration,
4132
+ new Gaea.Vector3(1, 1, 1)
4133
+ );
4134
+ this._flyAnimation.TrackSetPath(0, '/root/World/flyPathModel');
4135
+
4136
+ this._flyAnimationPlayer = new Gaea.GaeaAnimationPlayer();
4137
+ this._flyAnimationPlayer.AddAnimation('flyPathAnimation', this._flyAnimation);
4138
+ Gaea.World.Instance.AddChild(this._flyAnimationPlayer, false);
4139
+
4140
+ return new Promise((resolve) => {
4141
+ this._flyAnimationPlayer.PlayWithCallback(
4142
+ 'flyPathAnimation',
4143
+ Gaea.CallbackType.AnimatioFinished,
4144
+ () => {
4145
+ console.log('动画播放完成');
4146
+ resolve();
4147
+ }
4148
+ );
4149
+ });
4150
+ } catch (error) {
4151
+ console.error('flyAlongPath 启动失败:', error);
4152
+ this._cleanupFlyResources();
4153
+ return Promise.reject(error);
4154
+ }
4155
+ };
4156
+
4157
+ /**
4158
+ * 停止沿线飞行
4159
+ */
4160
+ stopFlyAlongPath = () => {
4161
+ try {
4162
+ if (this._flyAnimationPlayer) {
4163
+ this._flyAnimationPlayer.Stop('flyPathAnimation');
4164
+ }
4165
+ } catch (error) {
4166
+ console.error('停止飞行失败:', error);
4167
+ }
4168
+ this._cleanupFlyResources();
4169
+ };
4170
+
4171
+ /**
4172
+ * 清理飞行相关资源
4173
+ * @private
4174
+ */
4175
+ _cleanupFlyResources = () => {
4176
+ try {
4177
+ if (this._flyAnimationPlayer) {
4178
+ Gaea.World.Instance.RemoveChild(this._flyAnimationPlayer);
4179
+ this._flyAnimationPlayer = null;
4180
+ }
4181
+ if (this._flyEntityView) {
4182
+ this._flyEntityView = null;
4183
+ }
4184
+ if (this._flyModelInstance) {
4185
+ Gaea.World.Instance.RemoveChild(this._flyModelInstance);
4186
+ this._flyModelInstance = null;
4187
+ }
4188
+ Gaea.World.Instance.CameraController.LockedEntity = null;
4189
+ this._flyAnimation = null;
4190
+ } catch (error) {
4191
+ console.error('清理飞行资源失败:', error);
4192
+ }
4193
+ };
4194
+
4195
+ /**
4196
+ * 根据经纬度坐标在指定位置放置图标标记(仅图标,无文字)
4197
+ * @param {Object} options - 配置选项
4198
+ * @param {number} options.lat - 纬度
4199
+ * @param {number} options.lng - 经度
4200
+ * @param {number} options.alt - 高度(米),默认 0
4201
+ * @param {number} options.iconSize - 图标大小,默认 150
4202
+ * @param {boolean} options.enablePick - 是否可点击,默认 true
4203
+ * @returns {Promise<Object>} - 返回创建的 element
4204
+ */
4205
+ addPointIcon = async (options = {}) => {
4206
+ const {
4207
+ lat = '27.158573',
4208
+ lng = '120.4972157',
4209
+ alt = 0,
4210
+ iconSize = 500,
4211
+ enablePick = true
4212
+ } = options;
4213
+
4214
+ if (lat == null || lng == null) {
4215
+ console.error('addPointIcon: lat 和 lng 不能为空');
4216
+ return null;
4217
+ }
4218
+
4219
+ // 加载 .res 图标文件(仅首次)
4220
+ const resName = 'pointIcon.res';
4221
+ if (!this._pointIconLoaded) {
4222
+ const resUrl = `${serveLocal}/static/1111.res`;
4223
+ const loaded = await LoadResourceFromUrl(resUrl, resName);
4224
+ if (!loaded) {
4225
+ console.error('addPointIcon: 加载 .res 图标文件失败');
4226
+ return null;
4227
+ }
4228
+ this._pointIconLoaded = true;
4229
+ }
4230
+
4231
+ const texId = Gaea.GaeaResourceLoader.Instance.GetResource(resName);
4232
+ const tex = new Gaea.Texture(false);
4233
+ tex.InstanceID = texId + '';
4234
+
4235
+ // 构建坐标
4236
+ const pos = new Gaea.Vector3(lat, lng, alt);
4237
+ const shape = Gaea.Geometry.Create1(Gaea.GeometryType.Point, [pos]);
4238
+
4239
+ const element = new Gaea.PointGeometryElement();
4240
+ element.Shape = shape;
4241
+
4242
+ // 仅图标符号(无文字)
4243
+ const iconMarkSymbol = new Gaea.IconMarkSymbol();
4244
+ iconMarkSymbol.MarkSize = iconSize;
4245
+ iconMarkSymbol.Icon = tex;
4246
+ element.Symbol = iconMarkSymbol;
4247
+
4248
+ element.EnablePick = enablePick;
4249
+ element.EnableEdit = false;
4250
+
4251
+ Gaea.World.Instance.RenderableObjectList.AddLast(element);
4252
+
4253
+ // 托管存储
4254
+ if (!this._pointIconElements) {
4255
+ this._pointIconElements = [];
4256
+ }
4257
+ this._pointIconElements.push(element);
4258
+
4259
+ console.log(element,'elementelementelementelement');
4260
+
4261
+ return element;
4262
+ };
4263
+
4264
+ /**
4265
+ * 批量添加图标标记
4266
+ * @param {Array} pointList - 坐标数组 [{lat, lng, alt?, iconSize?}]
4267
+ * @returns {Promise<Array>} - 返回所有 element 数组
4268
+ */
4269
+ addPointIcons = async (pointList = []) => {
4270
+ const elements = [];
4271
+ for (const point of pointList) {
4272
+ const el = await this.addPointIcon(point);
4273
+ if (el) elements.push(el);
4274
+ }
4275
+ return elements;
4276
+ };
4277
+
4278
+ /**
4279
+ * 清除所有图标标记
4280
+ */
4281
+ clearPointIcons = () => {
4282
+ if (this._pointIconElements && this._pointIconElements.length > 0) {
4283
+ this._pointIconElements.forEach((element) => {
4284
+ Gaea.World.Instance.RenderableObjectList.Remove(element);
4285
+ });
4286
+ this._pointIconElements = [];
4287
+ }
4288
+ };
4289
+
4290
+ /**
4291
+ * 移除指定图标标记
4292
+ * @param {string|number} instanceId - element实例ID
4293
+ */
4294
+ removePointIcon = (instanceId) => {
4295
+ if (!this._pointIconElements || this._pointIconElements.length === 0) return;
4296
+ const idx = this._pointIconElements.findIndex(
4297
+ (ele) => ele.InstanceID === instanceId
4298
+ );
4299
+ if (idx >= 0) {
4300
+ const element = this._pointIconElements[idx];
4301
+ Gaea.World.Instance.RenderableObjectList.Remove(element);
4302
+ this._pointIconElements.splice(idx, 1);
4303
+ }
4304
+ };
4305
+
4306
+ /**
4307
+ * 加载台风路线 - 从逗号分隔的坐标文本批量放置图标
4308
+ * @param {string} routeText - 路线文本,每行格式 "经度,纬度"
4309
+ * @param {number} iconSize - 图标大小,默认 150
4310
+ */
4311
+ addTyphoonRoute = async (routeText, iconSize = 150) => {
4312
+ if (!routeText || !routeText.trim()) {
4313
+ console.warn('addTyphoonRoute: 路线文本为空');
4314
+ return;
4315
+ }
4316
+
4317
+ // 清除旧标注
4318
+ this.clearPointIcons();
4319
+
4320
+ // 解析路线文本,每行格式: 经度,纬度
4321
+ const lines = routeText.trim().split('\n');
4322
+ const points = [];
4323
+ for (const line of lines) {
4324
+ const parts = line.trim().split(/[,,\s]+/);
4325
+ if (parts.length >= 2) {
4326
+ const lng = parseFloat(parts[0]);
4327
+ const lat = parseFloat(parts[1]);
4328
+ if (!isNaN(lat) && !isNaN(lng)) {
4329
+ points.push({ lat, lng, iconSize });
4330
+ }
4331
+ }
4332
+ }
4333
+
4334
+ if (points.length === 0) {
4335
+ console.warn('addTyphoonRoute: 未解析到有效坐标');
4336
+ return;
4337
+ }
4338
+
4339
+ await this.addPointIcons(points);
4340
+ };
4341
+
4342
+ }