@yituengine/keymap 1.0.0
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/LICENSE +201 -0
- package/README.md +148 -0
- package/dist/engine.js +1 -0
- package/dist/types/core/Assets.d.ts +11 -0
- package/dist/types/core/Classification.d.ts +17 -0
- package/dist/types/core/Flatten.d.ts +74 -0
- package/dist/types/core/Status.d.ts +3 -0
- package/dist/types/core/pathAnim.d.ts +27 -0
- package/dist/types/core/transformFun.d.ts +16 -0
- package/dist/types/draw/baseDraw.d.ts +74 -0
- package/dist/types/draw/drawCircle.d.ts +44 -0
- package/dist/types/draw/drawPoint.d.ts +30 -0
- package/dist/types/draw/drawPolygon.d.ts +35 -0
- package/dist/types/draw/drawPolyline.d.ts +35 -0
- package/dist/types/draw/index.d.ts +17 -0
- package/dist/types/effect/cloud.d.ts +34 -0
- package/dist/types/effect/fog.d.ts +44 -0
- package/dist/types/effect/fogPro.d.ts +46 -0
- package/dist/types/effect/index.d.ts +32 -0
- package/dist/types/effect/lensflare.d.ts +38 -0
- package/dist/types/effect/rainy.d.ts +47 -0
- package/dist/types/effect/snowCover.d.ts +50 -0
- package/dist/types/effect/snowFall.d.ts +38 -0
- package/dist/types/event/index.d.ts +12 -0
- package/dist/types/event/menu.d.ts +110 -0
- package/dist/types/event/mousePick.d.ts +57 -0
- package/dist/types/graphic/baseGraphic.d.ts +131 -0
- package/dist/types/graphic/billboardGraphic.d.ts +75 -0
- package/dist/types/graphic/circleGraphic.d.ts +103 -0
- package/dist/types/graphic/customPopupGraphic.d.ts +75 -0
- package/dist/types/graphic/index.d.ts +32 -0
- package/dist/types/graphic/modelGraphic.d.ts +90 -0
- package/dist/types/graphic/polygonGraphic.d.ts +124 -0
- package/dist/types/graphic/polylineGraphic.d.ts +100 -0
- package/dist/types/graphic/popupGraphic.d.ts +85 -0
- package/dist/types/layer/graphicLayer.d.ts +96 -0
- package/dist/types/layer/heatmapLayer/heatmapRenderer.d.ts +39 -0
- package/dist/types/layer/heatmapLayer.d.ts +113 -0
- package/dist/types/layer/index.d.ts +14 -0
- package/dist/types/layer/tilesetLayer.d.ts +107 -0
- package/dist/types/main.d.ts +68 -0
- package/dist/types/map/defaultInteractions.d.ts +26 -0
- package/dist/types/map/index.d.ts +254 -0
- package/dist/types/material/LightingFlow.d.ts +63 -0
- package/dist/types/material/PolylineDashed.d.ts +68 -0
- package/dist/types/material/TextureFlow.d.ts +94 -0
- package/dist/types/material/Wave.d.ts +75 -0
- package/dist/types/material/index.d.ts +20 -0
- package/dist/types/measure/baseMeasure.d.ts +93 -0
- package/dist/types/measure/index.d.ts +18 -0
- package/dist/types/measure/measureArea.d.ts +46 -0
- package/dist/types/measure/measureCutFill.d.ts +69 -0
- package/dist/types/measure/measureDistance.d.ts +50 -0
- package/dist/types/measure/measureHeight.d.ts +47 -0
- package/dist/types/primitive/ClassificationPrimitive.d.ts +72 -0
- package/dist/types/primitive/Tube.d.ts +38 -0
- package/dist/types/primitive/Wall.d.ts +47 -0
- package/dist/types/primitive/basePrimitive.d.ts +42 -0
- package/dist/types/primitive/index.d.ts +16 -0
- package/dist/types/types/general.d.ts +94 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/public.d.ts +11 -0
- package/dist/types/utils/CoordTransform.d.ts +26 -0
- package/dist/types/utils/controlPoint.d.ts +10 -0
- package/dist/types/utils/cutFillAnalysis.d.ts +38 -0
- package/dist/types/utils/graphic.d.ts +45 -0
- package/dist/types/utils/midPoint.d.ts +11 -0
- package/dist/types/utils/rightMenu.d.ts +1 -0
- package/dist/types/utils/tools.d.ts +38 -0
- package/docs/guide/draw-measure.md +97 -0
- package/docs/guide/graphic.md +136 -0
- package/docs/guide/index.md +29 -0
- package/docs/guide/menu.md +101 -0
- package/docs/guide/quick-start.md +74 -0
- package/package.json +58 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# 右键菜单
|
|
2
|
+
|
|
3
|
+
`KeyMap` 会在初始化时注册一个默认 `Menu`。SDK 自己创建菜单 DOM,并挂载到 `viewer.container` 下;业务项目只需要配置菜单项,不需要手写右键菜单 DOM。
|
|
4
|
+
|
|
5
|
+
## 基础用法
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { eventType } from '@yituengine/keymap';
|
|
9
|
+
|
|
10
|
+
const menu = new eventType.Menu();
|
|
11
|
+
|
|
12
|
+
menu.addItem({
|
|
13
|
+
id: 'copy-coordinate',
|
|
14
|
+
label: '复制坐标',
|
|
15
|
+
order: 10,
|
|
16
|
+
show: (context) => Boolean(context.coordinate),
|
|
17
|
+
onClick(context) {
|
|
18
|
+
if (!context.coordinate) return;
|
|
19
|
+
const { lng, lat, alt } = context.coordinate;
|
|
20
|
+
navigator.clipboard.writeText(`${lng},${lat},${alt}`);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
map.on(menu);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
右键命中地球表面时,`context.coordinate` 和 `context.cartesian` 会有值,SDK 会临时显示一个右键锚点图标。右键天空时仍会显示菜单,但坐标为空。
|
|
28
|
+
|
|
29
|
+
## 批量添加和删除
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
menu.addItem([
|
|
33
|
+
{
|
|
34
|
+
id: 'zoom-picked',
|
|
35
|
+
label: '定位到对象',
|
|
36
|
+
order: 20,
|
|
37
|
+
show: (context) => Boolean(context.specObj?.zoomTo),
|
|
38
|
+
onClick(context) {
|
|
39
|
+
context.specObj?.zoomTo?.();
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'remove-picked',
|
|
44
|
+
label: (context) => `删除 ${context.specObj?.name ?? '对象'}`,
|
|
45
|
+
order: 30,
|
|
46
|
+
disabled: (context) => !context.specObj?.destroy,
|
|
47
|
+
onClick(context) {
|
|
48
|
+
context.specObj?.destroy?.();
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
menu.removeItem(['zoom-picked', 'remove-picked']);
|
|
54
|
+
menu.clearItems();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`addItem()` 使用相同 `id` 时会覆盖旧菜单项。`removeItem()` 支持单个 id 或 id 数组。
|
|
58
|
+
|
|
59
|
+
## MenuContext
|
|
60
|
+
|
|
61
|
+
菜单项的 `label`、`show`、`disabled` 和 `onClick` 都会收到同一个上下文:
|
|
62
|
+
|
|
63
|
+
| 字段 | 说明 |
|
|
64
|
+
| ------------ | ------------------------------------------------- |
|
|
65
|
+
| `event` | Cesium 右键事件。 |
|
|
66
|
+
| `coordinate` | WGS84 经纬高,右键天空时为 `null`。 |
|
|
67
|
+
| `cartesian` | Cesium `Cartesian3`,右键天空时为 `null`。 |
|
|
68
|
+
| `map` | 当前 `KeyMap` 实例。 |
|
|
69
|
+
| `menu` | SDK 创建或复用的菜单 DOM 元素。 |
|
|
70
|
+
| `specObj` | 命中的 SDK 资产,如图形、图层登记资产或测量对象。 |
|
|
71
|
+
| `pickedObj` | Cesium 原始 pick 结果。 |
|
|
72
|
+
|
|
73
|
+
## 显示和禁用
|
|
74
|
+
|
|
75
|
+
`show` 决定菜单项是否渲染,`disabled` 决定菜单项是否可点击:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
menu.addItem({
|
|
79
|
+
id: 'edit-picked',
|
|
80
|
+
label: '编辑对象',
|
|
81
|
+
show: (context) => Boolean(context.specObj?.showHandler),
|
|
82
|
+
disabled: (context) => context.map.Status.isMeasure,
|
|
83
|
+
onClick(context) {
|
|
84
|
+
context.specObj?.showHandler?.();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`show` 是同步判断函数,不支持异步请求。需要异步权限或状态时,建议先在业务侧缓存状态,再让 `show` 读取缓存。
|
|
90
|
+
|
|
91
|
+
## 默认控制点删除
|
|
92
|
+
|
|
93
|
+
编辑模式下,SDK 的默认交互会给控制点提供“删除节点”菜单项。折线删除后至少保留 2 个节点,多边形删除后会同步更新面、描边、中点、中心点和 `onChanged` 回调。
|
|
94
|
+
|
|
95
|
+
## 生命周期
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
map.off(menu);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`destroy()` 会隐藏菜单、销毁右键锚点、移除 Cesium 事件和 SDK 自建的菜单 DOM。
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# 快速开始
|
|
2
|
+
|
|
3
|
+
## 安装
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @yituengine/keymap cesium@1.106 vue@^3.2.0
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## 创建容器
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<div
|
|
13
|
+
id="map"
|
|
14
|
+
style="width: 100%; height: 100vh"
|
|
15
|
+
></div>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`initMap(containerId)` 会通过 `document.querySelector` 查找 `#containerId`,所以容器必须在调用前已经挂载到 DOM。
|
|
19
|
+
|
|
20
|
+
## 初始化地图
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { initMap } from '@yituengine/keymap';
|
|
24
|
+
|
|
25
|
+
const map = initMap('map');
|
|
26
|
+
if (!map) throw new Error('地图初始化失败,请检查容器 id');
|
|
27
|
+
|
|
28
|
+
map.flyTo({
|
|
29
|
+
position: [113.2644, 23.1291, 3000],
|
|
30
|
+
duration: 2,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
第二个参数 `disablePopup` 可用于按业务状态临时禁用默认弹窗:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const map = initMap('map', () => isDrawing.value || isEditing.value);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`disablePopup` 只影响默认弹窗和部分分类 Primitive 的点击颜色处理,不会关闭图形 `onClick`、右键菜单、编辑拖拽或悬停高亮。
|
|
41
|
+
|
|
42
|
+
## 添加图层和图形
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import * as Cesium from 'cesium';
|
|
46
|
+
import { initMap, layer, graphic } from '@yituengine/keymap';
|
|
47
|
+
|
|
48
|
+
const map = initMap('map');
|
|
49
|
+
if (!map) throw new Error('地图初始化失败');
|
|
50
|
+
|
|
51
|
+
const businessLayer = new layer.GraphicLayer({ name: '业务图层' });
|
|
52
|
+
map.addLayer(businessLayer);
|
|
53
|
+
|
|
54
|
+
const point = new graphic.BillboardGraphic({
|
|
55
|
+
name: '项目位置',
|
|
56
|
+
position: Cesium.Cartesian3.fromDegrees(113.2644, 23.1291, 30),
|
|
57
|
+
image: '/icons/location.svg',
|
|
58
|
+
width: 32,
|
|
59
|
+
height: 32,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
businessLayer.addGraphic(point);
|
|
63
|
+
point.flyTo();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 销毁
|
|
67
|
+
|
|
68
|
+
在单页应用组件卸载时销毁地图:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
map.destroy();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`destroy()` 会清理默认交互、图层、数据源和 Cesium Viewer。
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yituengine/keymap",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Cesium 1.106 based 3D GIS engine SDK",
|
|
5
|
+
"main": "./dist/engine.js",
|
|
6
|
+
"module": "./dist/engine.js",
|
|
7
|
+
"types": "./dist/types/main.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/main.d.ts",
|
|
12
|
+
"import": "./dist/engine.js",
|
|
13
|
+
"default": "./dist/engine.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"docs/guide"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "rollup -c build/rollup.config.dev.js -w",
|
|
24
|
+
"build": "rollup -c build/rollup.config.js && npm run build:types",
|
|
25
|
+
"build:types": "tsc -p tsconfig.types.json && node build/rewrite-dts-aliases.mjs",
|
|
26
|
+
"doc": "typedoc --options typedoc.json",
|
|
27
|
+
"doc:api": "typedoc --options typedoc.json",
|
|
28
|
+
"doc:check": "typedoc --options typedoc.json --treatWarningsAsErrors",
|
|
29
|
+
"prepack": "npm run build",
|
|
30
|
+
"typecheck": "tsc"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rollup/plugin-alias": "^5.1.1",
|
|
34
|
+
"@rollup/plugin-babel": "^6.1.0",
|
|
35
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
37
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
38
|
+
"@rollup/plugin-url": "^8.0.2",
|
|
39
|
+
"@types/lodash-es": "^4.17.12",
|
|
40
|
+
"prettier": "^3.8.1",
|
|
41
|
+
"rollup": "^4.17.2",
|
|
42
|
+
"rollup-plugin-javascript-obfuscator": "^1.0.4",
|
|
43
|
+
"rollup-plugin-obfuscator": "^1.1.0",
|
|
44
|
+
"rollup-plugin-serve": "^1.1.1",
|
|
45
|
+
"tslib": "^2.8.1",
|
|
46
|
+
"typedoc": "^0.28.20",
|
|
47
|
+
"typescript": "^5.9.2",
|
|
48
|
+
"vue": "3.2.26"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@turf/turf": "^7.3.2",
|
|
52
|
+
"cesium": "1.106",
|
|
53
|
+
"lodash-es": "^4.18.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"vue": ">=3.2.0 <4.0.0"
|
|
57
|
+
}
|
|
58
|
+
}
|