Skip to content

Commit a892b0e

Browse files
committedDec 21, 2023
docs: 文档更新
1 parent 1b8e961 commit a892b0e

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"use"
1010
],
1111
"license": "MIT",
12+
"homepage": "https://github.com/Hxy1992/vue3-use-cesium",
1213
"publishConfig": {
1314
"directory": "packages/vue3-use-cesium"
1415
},

‎packages/vue3-use-cesium/README.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# vue3-use-cesium
2+
3+
基于 Vue3、Typescrip、Cesium 的组件库。
4+
5+
### 功能 📖
6+
7+
基于 pnpm workspace、vite、glup、rollup 脚手架,依赖 Vue3、Cesium 开发的 CBB 公共库——vue3-use-cesium
8+
有以下特点/功能:
9+
10+
- 可支持 Cesium 库的按需加载
11+
- 基于 vue3 传送组件,实现多页面复用单个 Cesium 实例,防止频繁切换地图导致的卡顿,非首次地图无感加载
12+
- 支持封装 hook,使用简单
13+
- 支持地形、事件管理、图层管理、图层弹窗等
14+
- 支持地图工具(主页、底图图层、放大缩小、二三维切换等)、地图状态信息(鼠标位置、相机信息)
15+
- 支持标绘功能,绘制点线面、贴地/贴模型绘制等等,结果可输出 geojson
16+
- 支持测量功能,坐标测量(椭球/地形/模型)、距离测量(椭球/地形/模型/贴地/贴模型) 、面积测量(椭球/地形/模型/贴地/贴模型) 、高度差测量(地形/模型) 、三角测量(地形/模型)
17+
- 支持点聚合
18+
- 支持场景书签
19+
- 支持常用 Primitive 材质,如光电扫描球、颜色扫描球、雷达扫描、扩散圆、渐变墙、闪烁线等等
20+
21+
关于 Cesium 版本兼容性,已在 1.81 和 1.105 版本进行验证。
22+
23+
### 快速开始 📔
24+
25+
- **安装**
26+
27+
```bash
28+
yarn add vue3-use-cesium # npm i vue3-use-cesium --save
29+
```
30+
31+
- **使用**
32+
33+
1. 引入组件和样式
34+
35+
在 App.vue 中使用组件,示例如下:
36+
37+
```vue
38+
<template>
39+
<router-view></router-view>
40+
<z-map-base />
41+
</template>
42+
<script setup lang="ts">
43+
import { ZMapBase } from "vue3-use-cesium";
44+
</script>
45+
```
46+
47+
在 main.js 引入样式:
48+
49+
```typescript
50+
import "vue3-use-cesium/style";
51+
```
52+
53+
2. 在路由拦截中加载初始化并加载 Cesium.js
54+
55+
```typescript
56+
import { initMap } from "vue3-use-cesium";
57+
// 路由拦截
58+
router.beforeEach(async (to, from, next) => {
59+
// ...
60+
61+
// 如果页面包含地图则加载Cesium.js
62+
if (to.meta.hasMap) {
63+
await initMap([`/CesiumV1.105/Cesium.js`, `/CesiumV1.105/Widgets/widgets.css`], {
64+
imagery: "gd-img"
65+
});
66+
}
67+
68+
// ...
69+
next();
70+
});
71+
```
72+
73+
3. 定义 hooks(可选)
74+
75+
```typescript
76+
import { onBeforeUnmount, onMounted } from "vue";
77+
import { setToTarget, setVisible, clearMapElements, clearMapEvents, getViewer } from "vue3-use-cesium";
78+
79+
/**
80+
* 基础地图使用
81+
* @param selector div的id / body
82+
* @param mapCreated 成功回调(返回Viewer)
83+
*/
84+
export const useBaseMap = (selector: string, mapCreated?: (viewer: any) => void) => {
85+
onMounted(() => {
86+
setToTarget(selector);
87+
setVisible(true);
88+
if (mapCreated) {
89+
mapCreated(getViewer());
90+
}
91+
});
92+
onBeforeUnmount(() => {
93+
clearMapElements();
94+
clearMapEvents();
95+
setVisible(false);
96+
setToTarget("body");
97+
});
98+
};
99+
```
100+
101+
4. 页面使用
102+
103+
```vue
104+
<template>
105+
<!-- 只有一个顶层div -->
106+
<div class="bbox">
107+
<!-- 地图容器不能是顶层div -->
108+
<div id="my-map">
109+
<!-- 地图弹窗... -->
110+
</div>
111+
<!-- 地图面板等... -->
112+
</div>
113+
</template>
114+
115+
<script setup lang="ts">
116+
import { useBaseMap } from "@/hooks/useCesium";
117+
118+
// 地图初始化
119+
useBaseMap("#my-map", viewer => {
120+
console.log(viewer);
121+
});
122+
</script>
123+
```

‎packages/vue3-use-cesium/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "vue3-use-cesium",
33
"author": "Hxy1992",
4-
"version": "0.0.7",
4+
"version": "0.0.8",
55
"description": "在 Vue3 中简洁、快速的使用 Cesium",
66
"main": "lib/index.js",
77
"module": "es/index.mjs",
88
"types": "es/index.d.ts",
99
"unpkg": "dist/index.min.js",
1010
"jsdelivr": "dist/index.min.js",
11+
"homepage": "https://github.com/Hxy1992/vue3-use-cesium",
1112
"exports": {
1213
".": {
1314
"dev": "./src/index.ts",

0 commit comments

Comments
 (0)
Please sign in to comment.