@metagl/sdk-plotting 0.0.3 → 0.0.5
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 +221 -39
- package/lacdt.plotting.d.ts +2 -2
- package/package.json +1 -1
- package/types/Models/AnimationConfig.d.ts +1 -1
package/README.md
CHANGED
|
@@ -27,17 +27,27 @@ GeovisEarth SDK Plotting 模块,为 GeovisEarth Web SDK 提供矢量绘制、
|
|
|
27
27
|
<div id="cesiumContainer" style="width:100%;height:100%"></div>
|
|
28
28
|
|
|
29
29
|
<script>
|
|
30
|
-
//
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
const point =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
// 1. 初始化引擎(自动创建 Cesium Viewer 并挂载到 LACDT)
|
|
31
|
+
const engine = new LACDT.Engine('cesiumContainer');
|
|
32
|
+
|
|
33
|
+
// 2. 方式 A:createPlot 交互绘制
|
|
34
|
+
engine.plot.createPlot({}, '基本元素', '点', '图标点');
|
|
35
|
+
|
|
36
|
+
// 3. 方式 B:graphicLayer API 直接创建
|
|
37
|
+
const point = {
|
|
38
|
+
gvolObject: {
|
|
39
|
+
gvolType: 'EditorPoint',
|
|
40
|
+
properties: {
|
|
41
|
+
color: '#FF0000',
|
|
42
|
+
pixelSize: 20,
|
|
43
|
+
LabelName: '点'
|
|
44
|
+
},
|
|
45
|
+
geometry: {
|
|
46
|
+
coordinates: [116.397389, 39.908860]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
engine.graphicLayer.add(point);
|
|
41
51
|
</script>
|
|
42
52
|
</body>
|
|
43
53
|
</html>
|
|
@@ -63,9 +73,11 @@ npm install @metagl/sdk-plotting@file:../../sdk-plotting/publish
|
|
|
63
73
|
|
|
64
74
|
#### 2. Vite 项目配置要点
|
|
65
75
|
|
|
66
|
-
##### 2.1 Cesium 别名映射
|
|
76
|
+
##### 2.1 Cesium 别名映射 + 排除预打包
|
|
67
77
|
|
|
68
|
-
sdk-plotting 打包时将 Cesium 标记为 external(全局变量 `Cesium
|
|
78
|
+
sdk-plotting 打包时将 Cesium 标记为 external(全局变量 `Cesium`)。Vite 预打包时需要做两件事:
|
|
79
|
+
- 将 `Cesium` 别名指向**浏览器 ESM 构建**(不能用 `cesium` 包名,否则会解析到 `index.cjs` Node.js 入口,导致 `__dirname is not defined` 错误)
|
|
80
|
+
- 将 `@metagl/sdk-plotting` 排除预打包(避免 Vite 重新解析已打包好的 UMD 内部依赖)
|
|
69
81
|
|
|
70
82
|
```js
|
|
71
83
|
// vite.config.js
|
|
@@ -75,8 +87,8 @@ import path from 'path'
|
|
|
75
87
|
export default defineConfig({
|
|
76
88
|
resolve: {
|
|
77
89
|
alias: {
|
|
78
|
-
//
|
|
79
|
-
'Cesium': 'cesium',
|
|
90
|
+
// 关键:必须指向浏览器 ESM 入口,不能用 'cesium'(会解析到 Node.js 的 index.cjs)
|
|
91
|
+
'Cesium': path.resolve(__dirname, 'node_modules/cesium/Source/Cesium.js'),
|
|
80
92
|
}
|
|
81
93
|
},
|
|
82
94
|
define: {
|
|
@@ -84,11 +96,16 @@ export default defineConfig({
|
|
|
84
96
|
CESIUM_BASE_URL: JSON.stringify('/cesium')
|
|
85
97
|
},
|
|
86
98
|
optimizeDeps: {
|
|
87
|
-
include: ['cesium']
|
|
99
|
+
include: ['cesium'],
|
|
100
|
+
// 关键:排除已打包的 UMD 包,避免 Vite 重新解析其内部依赖
|
|
101
|
+
exclude: ['@metagl/sdk-plotting']
|
|
88
102
|
}
|
|
89
103
|
})
|
|
90
104
|
```
|
|
91
105
|
|
|
106
|
+
> **为什么不能写 `'Cesium': 'cesium'`?**
|
|
107
|
+
> Vite 按包名解析 `cesium` 时会读取 `package.json` 的 `main` 字段,指向 `index.cjs`——这是一个 Node.js CommonJS 入口,包含 `__dirname`、`path.join` 等浏览器不可用的 API。运行时会报 `ReferenceError: __dirname is not defined`。必须直接指向 `Source/Cesium.js` 浏览器构建。
|
|
108
|
+
|
|
92
109
|
##### 2.2 静态资源拷贝
|
|
93
110
|
|
|
94
111
|
sdk-plotting 的 `resources/` 目录(图片、纹理等)需要通过 `vite-plugin-static-copy` 或其他方式复制到构建输出:
|
|
@@ -200,39 +217,203 @@ module.exports = {
|
|
|
200
217
|
|
|
201
218
|
## 快速开始
|
|
202
219
|
|
|
203
|
-
|
|
220
|
+
### 初始化引擎
|
|
204
221
|
|
|
205
222
|
```js
|
|
206
223
|
// UMD 方式
|
|
207
|
-
const
|
|
224
|
+
const engine = new LACDT.Engine('cesiumContainer');
|
|
208
225
|
|
|
209
226
|
// npm import 方式
|
|
210
|
-
import {
|
|
211
|
-
const
|
|
227
|
+
import { Engine } from '@metagl/sdk-plotting';
|
|
228
|
+
const engine = new Engine('cesiumContainer');
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### 创建标绘元素的两种方式
|
|
232
|
+
|
|
233
|
+
#### 方式 A:`createPlot` 交互绘制(按分类选择)
|
|
234
|
+
|
|
235
|
+
通过 `engine.plot.createPlot()` 按分类树选择图形类型,支持鼠标在地图上交互绘制。
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
// 示例 1:按分类选择类型,鼠标交互绘制
|
|
239
|
+
engine.plot.createPlot({}, '基本元素', '点', '图标点');
|
|
240
|
+
engine.plot.createPlot({}, '基本元素', '线', '直线');
|
|
241
|
+
engine.plot.createPlot({}, '基本元素', '面', '多边形');
|
|
242
|
+
|
|
243
|
+
// 示例 2:带自定义样式参数
|
|
244
|
+
engine.plot.createPlot({
|
|
245
|
+
gvolType: 'Ellipsoid',
|
|
246
|
+
properties: {
|
|
247
|
+
color: '#FF0000',
|
|
248
|
+
radius: 100
|
|
249
|
+
},
|
|
250
|
+
geometry: {
|
|
251
|
+
coordinates: [86, 30]
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// 示例 3:带分类 + 自定义样式
|
|
256
|
+
engine.plot.createPlot({
|
|
257
|
+
properties: { color: '#00FF00' }
|
|
258
|
+
}, '基本元素', '箭头', '双箭头');
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**分类树结构(一级 / 二级 / 三级):**
|
|
262
|
+
|
|
263
|
+
| 一级分类 | 二级分类 | 三级分类 |
|
|
264
|
+
|---|---|---|
|
|
265
|
+
| 基本元素 | 点 | 图标点 |
|
|
266
|
+
| | 线 | 直线、曲线、流动线、箭头线、航线 |
|
|
267
|
+
| | 面 | 多边形、矩形、圆形 |
|
|
268
|
+
| | 文字 | 标签文字、路径文字、贴地文字、富文本 |
|
|
269
|
+
| | 箭头 | 双箭头、集结地、进攻方向、进攻方向尾、分队战斗行动、分队战斗行动尾、粗单直箭头、粗单尖头箭头、细直箭头 |
|
|
270
|
+
| | 其它 | 立方体、动态波、雷达 |
|
|
271
|
+
| | 粒子 | 烟特效、爆炸、喷泉 |
|
|
272
|
+
| 图片 | — | 各种图片标注 |
|
|
273
|
+
| 模型 | — | 各种 3D 模型 |
|
|
274
|
+
|
|
275
|
+
#### 方式 B:`engine.graphicLayer.add()` API 直接创建
|
|
276
|
+
|
|
277
|
+
通过 JSON 参数直接创建标绘元素,代码精确控制样式和位置,无需交互。
|
|
278
|
+
|
|
279
|
+
```js
|
|
280
|
+
// 示例 1:创建点
|
|
281
|
+
const point = {
|
|
282
|
+
gvolObject: {
|
|
283
|
+
gvolType: 'EditorPoint',
|
|
284
|
+
properties: {
|
|
285
|
+
color: '#FF0000',
|
|
286
|
+
pixelSize: 20,
|
|
287
|
+
outlineShow: true,
|
|
288
|
+
outlineWidth: 2,
|
|
289
|
+
outlineColor: '#FFFFFF',
|
|
290
|
+
LabelName: '点'
|
|
291
|
+
},
|
|
292
|
+
geometry: {
|
|
293
|
+
coordinates: [86, 30] // [经度, 纬度]
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const result = engine.graphicLayer.add(point);
|
|
298
|
+
|
|
299
|
+
// 示例 2:创建线
|
|
300
|
+
const line = {
|
|
301
|
+
gvolObject: {
|
|
302
|
+
gvolType: 'EditorPolyline',
|
|
303
|
+
properties: {
|
|
304
|
+
color: '#3388ff',
|
|
305
|
+
width: 3,
|
|
306
|
+
LabelName: '线'
|
|
307
|
+
},
|
|
308
|
+
geometry: {
|
|
309
|
+
coordinates: [
|
|
310
|
+
[116.39, 39.90],
|
|
311
|
+
[116.40, 39.91],
|
|
312
|
+
[116.41, 39.90]
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
engine.graphicLayer.add(line);
|
|
318
|
+
|
|
319
|
+
// 示例 3:创建多边形
|
|
320
|
+
const polygon = {
|
|
321
|
+
gvolObject: {
|
|
322
|
+
gvolType: 'EditorPolygon',
|
|
323
|
+
properties: {
|
|
324
|
+
color: '#00FF00',
|
|
325
|
+
materialType: 'Color',
|
|
326
|
+
LabelName: '多边形'
|
|
327
|
+
},
|
|
328
|
+
geometry: {
|
|
329
|
+
coordinates: [
|
|
330
|
+
[116.39, 39.90],
|
|
331
|
+
[116.40, 39.90],
|
|
332
|
+
[116.40, 39.91],
|
|
333
|
+
[116.39, 39.91],
|
|
334
|
+
[116.39, 39.90] // 首尾闭合
|
|
335
|
+
]
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
engine.graphicLayer.add(polygon);
|
|
340
|
+
|
|
341
|
+
// 示例 4:批量创建
|
|
342
|
+
const batchData = [pointData, lineData, polygonData];
|
|
343
|
+
engine.graphicLayer.add(batchData);
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**常用 `gvolType` 类型列表:**
|
|
212
347
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
348
|
+
| gvolType | 说明 | coordinates 格式 |
|
|
349
|
+
|---|---|---|
|
|
350
|
+
| `EditorPoint` | 图标点 | `[经度, 纬度]` |
|
|
351
|
+
| `EditorText` | 贴地文字 | `[经度, 纬度]` |
|
|
352
|
+
| `EditorPolyline` | 折线 | `[[经度, 纬度], ...]` |
|
|
353
|
+
| `EditorPolygon` | 多边形 | `[[经度, 纬度], ...]` |
|
|
354
|
+
| `EditorCircle` | 圆形 | `[经度, 纬度]` + 半径 |
|
|
355
|
+
| `EditorRectangle` | 矩形 | 对角两点坐标 |
|
|
356
|
+
| `EditorEllipse` | 椭圆 | `[经度, 纬度]` |
|
|
357
|
+
| `EditorSector` | 扇形 | `[经度, 纬度]` |
|
|
358
|
+
| `EditorArrow` | 箭头 | `[[经度, 纬度], ...]` |
|
|
359
|
+
| `EditorCube` | 立方体 | `[经度, 纬度, 高度]` |
|
|
360
|
+
|
|
361
|
+
## 编辑与交互
|
|
362
|
+
|
|
363
|
+
```js
|
|
364
|
+
// 开启编辑模式
|
|
365
|
+
engine.plot.open();
|
|
366
|
+
|
|
367
|
+
// 关闭编辑模式
|
|
368
|
+
engine.plot.close();
|
|
369
|
+
|
|
370
|
+
// 编辑完成后回调
|
|
371
|
+
engine.plot.onPick((data) => {
|
|
372
|
+
console.log('编辑变更:', data);
|
|
217
373
|
});
|
|
218
|
-
plotting.add(marker);
|
|
219
374
|
```
|
|
220
375
|
|
|
221
|
-
##
|
|
376
|
+
## graphicLayer 常用 API
|
|
377
|
+
|
|
378
|
+
```js
|
|
379
|
+
// 删除单个对象
|
|
380
|
+
engine.graphicLayer.remove(leaf);
|
|
222
381
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
- `zIndex`, `defaultStyle` 等
|
|
226
|
-
- **createPoint**({ position, style })
|
|
227
|
-
- **createLine**({ positions, style })
|
|
228
|
-
- **createPolygon**({ positions, style })
|
|
229
|
-
- **createLabel**({ position, text, style })
|
|
230
|
-
- **add**(feature) / **remove**(feature) / **clear**()
|
|
231
|
-
- **edit**(feature) / **stopEdit**()
|
|
232
|
-
- **toGeoJSON**() / **fromGeoJSON**(geojson)
|
|
233
|
-
- **on**(event, handler) / **off**(event, handler)
|
|
382
|
+
// 删除所有对象
|
|
383
|
+
engine.graphicLayer.removeAll();
|
|
234
384
|
|
|
235
|
-
|
|
385
|
+
// 导出为 JSON(可用于保存和反序列化)
|
|
386
|
+
const json = engine.graphicLayer.toJson();
|
|
387
|
+
|
|
388
|
+
// 从 JSON 导入
|
|
389
|
+
engine.graphicLayer.fromJson(json);
|
|
390
|
+
|
|
391
|
+
// 按 ID 查找
|
|
392
|
+
const obj = engine.graphicLayer.getById('some-guid');
|
|
393
|
+
|
|
394
|
+
// 按名称查找
|
|
395
|
+
const obj = engine.graphicLayer.getNodeByName('点');
|
|
396
|
+
|
|
397
|
+
// 屏幕坐标拾取对象
|
|
398
|
+
const obj = engine.graphicLayer.pickByCoordinate(screenX, screenY);
|
|
399
|
+
|
|
400
|
+
// 获取多边形内的对象
|
|
401
|
+
const items = engine.graphicLayer.getItemsInPolygon(positions);
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
## 事件监听
|
|
405
|
+
|
|
406
|
+
```js
|
|
407
|
+
// 监听添加事件(通过 engine.plot)
|
|
408
|
+
engine.plot.on('add', (sceneObject) => {
|
|
409
|
+
console.log('新对象已添加:', sceneObject);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// 监听删除事件
|
|
413
|
+
engine.plot.on('remove', (gvolObject) => {
|
|
414
|
+
console.log('对象已删除:', gvolObject);
|
|
415
|
+
});
|
|
416
|
+
```
|
|
236
417
|
|
|
237
418
|
## 构建
|
|
238
419
|
|
|
@@ -258,8 +439,9 @@ cd publish && npm publish --access public # 发布
|
|
|
258
439
|
- **LACDT 未定义**:确保 `lacdt.plotting.js` 在 Cesium 之后加载
|
|
259
440
|
|
|
260
441
|
### npm import 方式
|
|
442
|
+
- **`__dirname is not defined`**:Cesium 别名不能写 `'cesium'`(会解析到 Node.js `index.cjs`),必须指向 `Source/Cesium.js` 浏览器入口
|
|
443
|
+
- **白屏无报错**:Vite 缓存了旧依赖路径,需删除 `node_modules/.vite/` 后重启(从 `file:` 引用切换到 npm 版本时必做)
|
|
261
444
|
- **Cannot assign to "e" because it is a constant**:构建产物问题,需重新 `npm run build`
|
|
262
|
-
- **Cesium could not be resolved**:在 `vite.config.js` 中添加 `'Cesium': 'cesium'` 别名
|
|
263
445
|
- **SDK 无法扩展 Cesium**:UMD 格式的 SDK 会扩展 `window.Cesium`,需在 import 之前确保 Cesium 已挂载到 `window`,且对象未被 `Object.freeze()`
|
|
264
446
|
|
|
265
447
|
## 许可证
|
package/lacdt.plotting.d.ts
CHANGED
|
@@ -3589,7 +3589,7 @@ class Tools {
|
|
|
3589
3589
|
}
|
|
3590
3590
|
|
|
3591
3591
|
class AnimationConfig {
|
|
3592
|
-
static animationRegister: (typeof SingleAnimation | typeof
|
|
3592
|
+
static animationRegister: (typeof SingleAnimation | typeof CameraSetAnimation | typeof StateChangeAnimation | typeof CssNumberAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | 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
|
|
18708
|
+
static animationRegister: (typeof SingleAnimation | typeof CameraSetAnimation | typeof StateChangeAnimation | typeof CssNumberAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | 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
|
@@ -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
|
|
26
|
+
static animationRegister: (typeof SingleAnimation | typeof CameraSetAnimation | typeof StateChangeAnimation | typeof CssNumberAnimation | typeof CssPropChangeAnimation | typeof SubtitleAnimation | 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
|
}
|