@yangyongtao/gaea 1.0.1 → 1.0.2

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/GaeaMethods.js +34 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangyongtao/gaea",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Gaea 3D 可视化组件库,包含天气控制、沿线飞行、台风标注、模型加载等功能",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -53,12 +53,36 @@ function rgbToGaeaColor(rgb) {
53
53
  function checkGaea() {
54
54
  const G = window.Gaea;
55
55
  if (!G || !G.World || !G.World.Instance) {
56
- console.warn('Gaea 尚未加载完毕,请确保在 Gaea 初始化之后再调用此方法');
56
+ console.warn('Gaea 尚未加载完毕,请先调用 await GaeaApp.waitForReady()');
57
57
  return null;
58
58
  }
59
59
  return G;
60
60
  }
61
61
 
62
+ /**
63
+ * 等待 Gaea 引擎初始化完毕(轮询 World.Instance)
64
+ * @param {number} timeout - 超时毫秒数,默认 30000
65
+ * @returns {Promise<boolean>}
66
+ */
67
+ async function waitForGaea(timeout = 30000) {
68
+ if (window.Gaea && window.Gaea.World && window.Gaea.World.Instance) {
69
+ return true;
70
+ }
71
+ const start = Date.now();
72
+ return new Promise((resolve) => {
73
+ const timer = setInterval(() => {
74
+ if (window.Gaea && window.Gaea.World && window.Gaea.World.Instance) {
75
+ clearInterval(timer);
76
+ resolve(true);
77
+ } else if (Date.now() - start > timeout) {
78
+ clearInterval(timer);
79
+ console.error('Gaea 初始化超时');
80
+ resolve(false);
81
+ }
82
+ }, 200);
83
+ });
84
+ }
85
+
62
86
 
63
87
  // ==================== GaeaApp 类 ====================
64
88
 
@@ -93,6 +117,15 @@ export class GaeaApp {
93
117
  this._tweenGroup = new Group();
94
118
  }
95
119
 
120
+ /**
121
+ * 静态方法:等待 Gaea 引擎就绪
122
+ * @example await GaeaApp.waitForReady(); // 30s 超时
123
+ * @example await GaeaApp.waitForReady(60000); // 自定义超时
124
+ */
125
+ static waitForReady(timeout) {
126
+ return waitForGaea(timeout);
127
+ }
128
+
96
129
  // ==================== 点标注 ====================
97
130
 
98
131
  /**