@metagl/sdk-plotting 0.0.4 → 0.0.6

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
@@ -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
- // 初始化 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);
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>
@@ -207,39 +217,203 @@ module.exports = {
207
217
 
208
218
  ## 快速开始
209
219
 
210
- 初始化并创建一个点:
220
+ ### 初始化引擎
211
221
 
212
222
  ```js
213
223
  // UMD 方式
214
- const plotting = new LACDT.Plotting({ viewer });
224
+ const engine = new LACDT.Engine('cesiumContainer');
215
225
 
216
226
  // npm import 方式
217
- import { Plotting } from '@metagl/sdk-plotting';
218
- const plotting = new Plotting({ viewer });
227
+ import { Engine } from '@metagl/sdk-plotting';
228
+ const engine = new Engine('cesiumContainer');
229
+ ```
230
+
231
+ ### 创建标绘元素的两种方式
219
232
 
220
- // 创建点
221
- const marker = plotting.createPoint({
222
- position: [116.397389, 39.908860],
223
- style: { color: '#ff0000', size: 12 }
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
+ }
224
253
  });
225
- plotting.add(marker);
254
+
255
+ // 示例 3:带分类 + 自定义样式
256
+ engine.plot.createPlot({
257
+ properties: { color: '#00FF00' }
258
+ }, '基本元素', '箭头', '双箭头');
226
259
  ```
227
260
 
228
- ## 基本 API(概览)
229
-
230
- - **Plotting(options)**
231
- - `viewer`: Cesium Viewer 实例
232
- - `zIndex`, `defaultStyle`
233
- - **createPoint**({ position, style })
234
- - **createLine**({ positions, style })
235
- - **createPolygon**({ positions, style })
236
- - **createLabel**({ position, text, style })
237
- - **add**(feature) / **remove**(feature) / **clear**()
238
- - **edit**(feature) / **stopEdit**()
239
- - **toGeoJSON**() / **fromGeoJSON**(geojson)
240
- - **on**(event, handler) / **off**(event, handler)
241
-
242
- 常见事件:`click`、`dblclick`、`pointermove`、`editstart`、`editend`、`create`
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` 类型列表:**
347
+
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);
373
+ });
374
+ ```
375
+
376
+ ## graphicLayer 常用 API
377
+
378
+ ```js
379
+ // 删除单个对象
380
+ engine.graphicLayer.remove(leaf);
381
+
382
+ // 删除所有对象
383
+ engine.graphicLayer.removeAll();
384
+
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
+ ```
243
417
 
244
418
  ## 构建
245
419
 
@@ -3589,7 +3589,7 @@ class Tools {
3589
3589
  }
3590
3590
 
3591
3591
  class AnimationConfig {
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)[];
3592
+ static animationRegister: (typeof SingleAnimation | typeof StateChangeAnimation | typeof CameraSetAnimation | 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 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)[];
18708
+ static animationRegister: (typeof SingleAnimation | typeof StateChangeAnimation | typeof CameraSetAnimation | 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
  }