@metagl/sdk-plotting 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -86
- package/lacdt.plotting.d.ts +2 -2
- package/lacdt.plotting.js +1 -1
- package/package.json +1 -1
- package/types/Models/AnimationConfig.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,86 +1,267 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<script src="
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
plotting.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
# @metagl/sdk-plotting
|
|
2
|
+
|
|
3
|
+
GeovisEarth SDK Plotting 模块,为 GeovisEarth Web SDK 提供矢量绘制、标注与图形交互的封装组件,支持在 Cesium 地图上创建、编辑与管理点、线、面、标注等图形要素。
|
|
4
|
+
|
|
5
|
+
## 两种使用方式
|
|
6
|
+
|
|
7
|
+
### 方式一:HTML script 标签引入(UMD 方式)
|
|
8
|
+
|
|
9
|
+
适用于传统 HTML 页面,通过 `<script>` 标签直接引入,通过全局变量 `LACDT` 访问 API。
|
|
10
|
+
|
|
11
|
+
**前置依赖:** 需先引入 Cesium。
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<!DOCTYPE html>
|
|
15
|
+
<html lang="zh">
|
|
16
|
+
<head>
|
|
17
|
+
<meta charset="utf-8" />
|
|
18
|
+
<!-- 1. 引入 Cesium -->
|
|
19
|
+
<link href="https://io-qos.geovisearth.com/getfile/46/brainsim-cdn/open/cesiumjs/1.136/Widgets/widgets.css" rel="stylesheet">
|
|
20
|
+
<script src="https://io-qos.geovisearth.com/getfile/46/brainsim-cdn/open/cesiumjs/1.136/Cesium.js"></script>
|
|
21
|
+
|
|
22
|
+
<!-- 2. 引入 sdk-plotting(线上 CDN 或本地文件) -->
|
|
23
|
+
<script src="https://io-qos.geovisearth.com/getfile/46/brainsim-cdn/open/sdk/lacdt.plotting.js"></script>
|
|
24
|
+
<!-- 本地引入:<script src="./lib/lacdt.plotting.js"></script> -->
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
<div id="cesiumContainer" style="width:100%;height:100%"></div>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
// 初始化 Cesium
|
|
31
|
+
const viewer = new Cesium.Viewer('cesiumContainer');
|
|
32
|
+
|
|
33
|
+
// 3. 通过全局对象 LACDT 使用 plotting
|
|
34
|
+
const plotting = new LACDT.Plotting({ viewer });
|
|
35
|
+
|
|
36
|
+
// 使用 API 创建要素
|
|
37
|
+
const point = plotting.createPoint({
|
|
38
|
+
position: [116.397389, 39.908860]
|
|
39
|
+
});
|
|
40
|
+
plotting.add(point);
|
|
41
|
+
</script>
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**资源文件说明:** 打包产物中 `resources/` 目录包含图片、纹理等静态资源,需与 JS 文件保持相对路径关系。如果自定义了部署路径,需确保 `resources/` 目录可被访问。
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 方式二:npm import 引入(ESM 方式)
|
|
51
|
+
|
|
52
|
+
适用于 Vue/Vite/Webpack 等现代前端工程化项目,通过 ES Module 动态导入。
|
|
53
|
+
|
|
54
|
+
#### 1. 安装
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# npm 官方源
|
|
58
|
+
npm install @metagl/sdk-plotting
|
|
59
|
+
|
|
60
|
+
# 或本地 file 引用(开发调试阶段)
|
|
61
|
+
npm install @metagl/sdk-plotting@file:../../sdk-plotting/publish
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### 2. Vite 项目配置要点
|
|
65
|
+
|
|
66
|
+
##### 2.1 Cesium 别名映射
|
|
67
|
+
|
|
68
|
+
sdk-plotting 打包时将 Cesium 标记为 external(全局变量 `Cesium`),但 Vite 按模块名解析时需要映射:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
// vite.config.js
|
|
72
|
+
import { defineConfig } from 'vite'
|
|
73
|
+
import path from 'path'
|
|
74
|
+
|
|
75
|
+
export default defineConfig({
|
|
76
|
+
resolve: {
|
|
77
|
+
alias: {
|
|
78
|
+
// 关键:将 UMD external 的 'Cesium' 映射到 npm 包名 'cesium'
|
|
79
|
+
'Cesium': 'cesium',
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
define: {
|
|
83
|
+
// Cesium 静态资源路径
|
|
84
|
+
CESIUM_BASE_URL: JSON.stringify('/cesium')
|
|
85
|
+
},
|
|
86
|
+
optimizeDeps: {
|
|
87
|
+
include: ['cesium']
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
##### 2.2 静态资源拷贝
|
|
93
|
+
|
|
94
|
+
sdk-plotting 的 `resources/` 目录(图片、纹理等)需要通过 `vite-plugin-static-copy` 或其他方式复制到构建输出:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
// vite.config.js
|
|
98
|
+
import { viteStaticCopy } from 'vite-plugin-static-copy'
|
|
99
|
+
|
|
100
|
+
export default defineConfig({
|
|
101
|
+
plugins: [
|
|
102
|
+
viteStaticCopy({
|
|
103
|
+
targets: [
|
|
104
|
+
// Cesium 静态资源
|
|
105
|
+
{
|
|
106
|
+
src: 'node_modules/cesium/Build/Cesium/*',
|
|
107
|
+
dest: 'cesium'
|
|
108
|
+
},
|
|
109
|
+
// sdk-plotting 资源
|
|
110
|
+
{
|
|
111
|
+
src: 'node_modules/@metagl/sdk-plotting/resources',
|
|
112
|
+
dest: 'resources'
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
],
|
|
117
|
+
// 如果代码中通过 /lib/resources 路径请求资源,配置代理
|
|
118
|
+
server: {
|
|
119
|
+
proxy: {
|
|
120
|
+
'/lib/resources': {
|
|
121
|
+
target: 'http://localhost:9521',
|
|
122
|
+
changeOrigin: true,
|
|
123
|
+
rewrite: (path) => path.replace('/lib/resources', '/resources')
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
##### 2.3 入口文件加载
|
|
131
|
+
|
|
132
|
+
UMD 格式需要通过动态 import 加载,并在加载后将全局变量 `LACDT` 和 `window.Cesium` 暴露出来:
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
// main.js
|
|
136
|
+
import { createApp } from 'vue'
|
|
137
|
+
import App from './App.vue'
|
|
138
|
+
|
|
139
|
+
// 解冻 Cesium(使 sdk-plotting 能扩展 Cesium 对象)
|
|
140
|
+
function makeExtensible(obj) {
|
|
141
|
+
const newObj = Object.create(Object.getPrototypeOf(obj))
|
|
142
|
+
Object.getOwnPropertyNames(obj).forEach(key => {
|
|
143
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key)
|
|
144
|
+
if (descriptor) {
|
|
145
|
+
Object.defineProperty(newObj, key, {
|
|
146
|
+
...descriptor,
|
|
147
|
+
configurable: true,
|
|
148
|
+
writable: true
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
return newObj
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function bootstrap() {
|
|
156
|
+
// 1. 加载 Cesium
|
|
157
|
+
const CesiumModule = await import('cesium')
|
|
158
|
+
let cesium = CesiumModule.default || CesiumModule
|
|
159
|
+
cesium = makeExtensible(cesium)
|
|
160
|
+
window.Cesium = cesium
|
|
161
|
+
|
|
162
|
+
// 2. 加载 sdk-plotting(动态 import)
|
|
163
|
+
await import('@metagl/sdk-plotting')
|
|
164
|
+
|
|
165
|
+
// 3. 此时 LACDT 全局对象已就绪
|
|
166
|
+
const app = createApp(App)
|
|
167
|
+
app.config.globalProperties.$metaGL = window.LACDT
|
|
168
|
+
app.config.globalProperties.$cesium = window.Cesium
|
|
169
|
+
app.mount('#app')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
bootstrap()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### 3. Webpack 项目配置要点
|
|
176
|
+
|
|
177
|
+
Webpack 项目需配置 Cesium 为 external:
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
// webpack.config.js
|
|
181
|
+
module.exports = {
|
|
182
|
+
externals: {
|
|
183
|
+
cesium: 'Cesium'
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 主要功能
|
|
191
|
+
|
|
192
|
+
- 创建点、线、面、文本标注、图标等要素
|
|
193
|
+
- 支持要素样式配置(颜色、宽度、图标、透明度等)
|
|
194
|
+
- 要素编辑(拖拽、顶点编辑、删除)
|
|
195
|
+
- 支持要素分组与图层管理
|
|
196
|
+
- 事件绑定(点击、悬停、编辑开始/结束等)
|
|
197
|
+
- 批量导入/导出 GeoJSON
|
|
198
|
+
- 军事标会、箭头、扇形、椭圆等多种军事图形
|
|
199
|
+
- 热力图、OD 线、三维体(立方体、圆柱体)等分析效果
|
|
200
|
+
|
|
201
|
+
## 快速开始
|
|
202
|
+
|
|
203
|
+
初始化并创建一个点:
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
// UMD 方式
|
|
207
|
+
const plotting = new LACDT.Plotting({ viewer });
|
|
208
|
+
|
|
209
|
+
// npm import 方式
|
|
210
|
+
import { Plotting } from '@metagl/sdk-plotting';
|
|
211
|
+
const plotting = new Plotting({ viewer });
|
|
212
|
+
|
|
213
|
+
// 创建点
|
|
214
|
+
const marker = plotting.createPoint({
|
|
215
|
+
position: [116.397389, 39.908860],
|
|
216
|
+
style: { color: '#ff0000', size: 12 }
|
|
217
|
+
});
|
|
218
|
+
plotting.add(marker);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 基本 API(概览)
|
|
222
|
+
|
|
223
|
+
- **Plotting(options)**
|
|
224
|
+
- `viewer`: Cesium Viewer 实例
|
|
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)
|
|
234
|
+
|
|
235
|
+
常见事件:`click`、`dblclick`、`pointermove`、`editstart`、`editend`、`create`
|
|
236
|
+
|
|
237
|
+
## 构建
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
npm run build # webpack 生产构建
|
|
241
|
+
npm run build:rollup # rollup 构建
|
|
242
|
+
npm run build:dts # 生成类型声明文件
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
构建产物输出到 `lib/` 目录,`npm run build` 会自动将产物复制到 `publish/` 目录。
|
|
246
|
+
|
|
247
|
+
## 发布
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
npm run login # 登录 npm
|
|
251
|
+
cd publish && npm publish --access public # 发布
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## 常见问题
|
|
255
|
+
|
|
256
|
+
### UMD 方式
|
|
257
|
+
- **资源 404**:确保 `resources/` 目录与 `lacdt.plotting.js` 保持正确的相对路径
|
|
258
|
+
- **LACDT 未定义**:确保 `lacdt.plotting.js` 在 Cesium 之后加载
|
|
259
|
+
|
|
260
|
+
### npm import 方式
|
|
261
|
+
- **Cannot assign to "e" because it is a constant**:构建产物问题,需重新 `npm run build`
|
|
262
|
+
- **Cesium could not be resolved**:在 `vite.config.js` 中添加 `'Cesium': 'cesium'` 别名
|
|
263
|
+
- **SDK 无法扩展 Cesium**:UMD 格式的 SDK 会扩展 `window.Cesium`,需在 import 之前确保 Cesium 已挂载到 `window`,且对象未被 `Object.freeze()`
|
|
264
|
+
|
|
265
|
+
## 许可证
|
|
266
|
+
|
|
267
|
+
ISC
|
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 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)[];
|
|
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 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)[];
|
|
18709
18709
|
static animationList: Array<AnimationItem>;
|
|
18710
18710
|
static init(): void;
|
|
18711
18711
|
}
|