@metagl/sdk-plotting 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -63,9 +63,11 @@ npm install @metagl/sdk-plotting@file:../../sdk-plotting/publish
63
63
 
64
64
  #### 2. Vite 项目配置要点
65
65
 
66
- ##### 2.1 Cesium 别名映射
66
+ ##### 2.1 Cesium 别名映射 + 排除预打包
67
67
 
68
- sdk-plotting 打包时将 Cesium 标记为 external(全局变量 `Cesium`),但 Vite 按模块名解析时需要映射:
68
+ sdk-plotting 打包时将 Cesium 标记为 external(全局变量 `Cesium`)。Vite 预打包时需要做两件事:
69
+ - 将 `Cesium` 别名指向**浏览器 ESM 构建**(不能用 `cesium` 包名,否则会解析到 `index.cjs` Node.js 入口,导致 `__dirname is not defined` 错误)
70
+ - 将 `@metagl/sdk-plotting` 排除预打包(避免 Vite 重新解析已打包好的 UMD 内部依赖)
69
71
 
70
72
  ```js
71
73
  // vite.config.js
@@ -75,8 +77,8 @@ import path from 'path'
75
77
  export default defineConfig({
76
78
  resolve: {
77
79
  alias: {
78
- // 关键:将 UMD external 'Cesium' 映射到 npm 包名 'cesium'
79
- 'Cesium': 'cesium',
80
+ // 关键:必须指向浏览器 ESM 入口,不能用 'cesium'(会解析到 Node.js index.cjs)
81
+ 'Cesium': path.resolve(__dirname, 'node_modules/cesium/Source/Cesium.js'),
80
82
  }
81
83
  },
82
84
  define: {
@@ -84,11 +86,16 @@ export default defineConfig({
84
86
  CESIUM_BASE_URL: JSON.stringify('/cesium')
85
87
  },
86
88
  optimizeDeps: {
87
- include: ['cesium']
89
+ include: ['cesium'],
90
+ // 关键:排除已打包的 UMD 包,避免 Vite 重新解析其内部依赖
91
+ exclude: ['@metagl/sdk-plotting']
88
92
  }
89
93
  })
90
94
  ```
91
95
 
96
+ > **为什么不能写 `'Cesium': 'cesium'`?**
97
+ > Vite 按包名解析 `cesium` 时会读取 `package.json` 的 `main` 字段,指向 `index.cjs`——这是一个 Node.js CommonJS 入口,包含 `__dirname`、`path.join` 等浏览器不可用的 API。运行时会报 `ReferenceError: __dirname is not defined`。必须直接指向 `Source/Cesium.js` 浏览器构建。
98
+
92
99
  ##### 2.2 静态资源拷贝
93
100
 
94
101
  sdk-plotting 的 `resources/` 目录(图片、纹理等)需要通过 `vite-plugin-static-copy` 或其他方式复制到构建输出:
@@ -258,8 +265,9 @@ cd publish && npm publish --access public # 发布
258
265
  - **LACDT 未定义**:确保 `lacdt.plotting.js` 在 Cesium 之后加载
259
266
 
260
267
  ### npm import 方式
268
+ - **`__dirname is not defined`**:Cesium 别名不能写 `'cesium'`(会解析到 Node.js `index.cjs`),必须指向 `Source/Cesium.js` 浏览器入口
269
+ - **白屏无报错**:Vite 缓存了旧依赖路径,需删除 `node_modules/.vite/` 后重启(从 `file:` 引用切换到 npm 版本时必做)
261
270
  - **Cannot assign to "e" because it is a constant**:构建产物问题,需重新 `npm run build`
262
- - **Cesium could not be resolved**:在 `vite.config.js` 中添加 `'Cesium': 'cesium'` 别名
263
271
  - **SDK 无法扩展 Cesium**:UMD 格式的 SDK 会扩展 `window.Cesium`,需在 import 之前确保 Cesium 已挂载到 `window`,且对象未被 `Object.freeze()`
264
272
 
265
273
  ## 许可证
@@ -3589,7 +3589,7 @@ class Tools {
3589
3589
  }
3590
3590
 
3591
3591
  class AnimationConfig {
3592
- static animationRegister: (typeof SingleAnimation | typeof StateChangeAnimation | typeof CssNumberAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | typeof CameraSetAnimation | typeof GeojsonVisibleAnimation | typeof PopulationTimeAnimation | typeof CssMaskAnimation | typeof PathAnimation | typeof CameraRoamAnimation | typeof PageShowAnimation | typeof GxModelAnimation | typeof PathShowAnimation | typeof FollowAnimation | typeof SurroundAnimation | typeof SpiralAnimation | typeof ArrowDirectAnimation | typeof VideoAnimation | typeof AudioAnimation | typeof AutoRotationAnimation | typeof ZoomToFlyAnimation | typeof PolygonMaskAnimation)[];
3592
+ static animationRegister: (typeof SingleAnimation | typeof CameraSetAnimation | typeof StateChangeAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | typeof CssNumberAnimation | typeof GeojsonVisibleAnimation | typeof PopulationTimeAnimation | typeof CssMaskAnimation | typeof PathAnimation | typeof CameraRoamAnimation | typeof PageShowAnimation | typeof GxModelAnimation | typeof PathShowAnimation | typeof FollowAnimation | typeof SurroundAnimation | typeof SpiralAnimation | typeof ArrowDirectAnimation | typeof VideoAnimation | typeof AudioAnimation | typeof AutoRotationAnimation | typeof ZoomToFlyAnimation | typeof PolygonMaskAnimation)[];
3593
3593
  static animationList: Array<AnimationItem>;
3594
3594
  static init(): void;
3595
3595
  }
@@ -18705,7 +18705,7 @@ class Tools {
18705
18705
  }
18706
18706
 
18707
18707
  class AnimationConfig {
18708
- static animationRegister: (typeof SingleAnimation | typeof StateChangeAnimation | typeof CssNumberAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | typeof CameraSetAnimation | typeof GeojsonVisibleAnimation | typeof PopulationTimeAnimation | typeof CssMaskAnimation | typeof PathAnimation | typeof CameraRoamAnimation | typeof PageShowAnimation | typeof GxModelAnimation | typeof PathShowAnimation | typeof FollowAnimation | typeof SurroundAnimation | typeof SpiralAnimation | typeof ArrowDirectAnimation | typeof VideoAnimation | typeof AudioAnimation | typeof AutoRotationAnimation | typeof ZoomToFlyAnimation | typeof PolygonMaskAnimation)[];
18708
+ static animationRegister: (typeof SingleAnimation | typeof CameraSetAnimation | typeof StateChangeAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | typeof CssNumberAnimation | typeof GeojsonVisibleAnimation | typeof PopulationTimeAnimation | typeof CssMaskAnimation | typeof PathAnimation | typeof CameraRoamAnimation | typeof PageShowAnimation | typeof GxModelAnimation | typeof PathShowAnimation | typeof FollowAnimation | typeof SurroundAnimation | typeof SpiralAnimation | typeof ArrowDirectAnimation | typeof VideoAnimation | typeof AudioAnimation | typeof AutoRotationAnimation | typeof ZoomToFlyAnimation | typeof PolygonMaskAnimation)[];
18709
18709
  static animationList: Array<AnimationItem>;
18710
18710
  static init(): void;
18711
18711
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metagl/sdk-plotting",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Geovis Earth SDK Plotting Module",
5
5
  "main": "./lacdt.plotting.js",
6
6
  "module": "./lacdt.plotting.js",
@@ -23,7 +23,7 @@ import { AutoRotationAnimation } from '../PlottingTool/Animation/Items/AutoRotat
23
23
  import { ZoomToFlyAnimation } from '../PlottingTool/Animation/Items/ZoomToFlyAnimation';
24
24
  import { PolygonMaskAnimation } from '../PlottingTool/Animation/Items/PolygonMaskAnimation';
25
25
  export declare class AnimationConfig {
26
- static animationRegister: (typeof SingleAnimation | typeof StateChangeAnimation | typeof CssNumberAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | typeof CameraSetAnimation | typeof GeojsonVisibleAnimation | typeof PopulationTimeAnimation | typeof CssMaskAnimation | typeof PathAnimation | typeof CameraRoamAnimation | typeof PageShowAnimation | typeof GxModelAnimation | typeof PathShowAnimation | typeof FollowAnimation | typeof SurroundAnimation | typeof SpiralAnimation | typeof ArrowDirectAnimation | typeof VideoAnimation | typeof AudioAnimation | typeof AutoRotationAnimation | typeof ZoomToFlyAnimation | typeof PolygonMaskAnimation)[];
26
+ static animationRegister: (typeof SingleAnimation | typeof CameraSetAnimation | typeof StateChangeAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | typeof CssNumberAnimation | typeof GeojsonVisibleAnimation | typeof PopulationTimeAnimation | typeof CssMaskAnimation | typeof PathAnimation | typeof CameraRoamAnimation | typeof PageShowAnimation | typeof GxModelAnimation | typeof PathShowAnimation | typeof FollowAnimation | typeof SurroundAnimation | typeof SpiralAnimation | typeof ArrowDirectAnimation | typeof VideoAnimation | typeof AudioAnimation | typeof AutoRotationAnimation | typeof ZoomToFlyAnimation | typeof PolygonMaskAnimation)[];
27
27
  static animationList: Array<AnimationItem>;
28
28
  static init(): void;
29
29
  }