Skip to content

Commit ef84fe7

Browse files
committed
feat(vue-cesium): ✨ adapt for compatibility with dc-sdk version 3.x.
1 parent 4e74217 commit ef84fe7

File tree

9 files changed

+293
-25
lines changed

9 files changed

+293
-25
lines changed

CHANGELOG.en-US.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
## Changelog
22

3+
### 3.2.6
4+
5+
_2024-02-29_
6+
7+
#### New feature
8+
9+
- Added formatting functions to the `vc-measurements` component for measurement results. `distanceFormatter`, `areaFormatter`, `angleFormatter`.
10+
- Adapt for compatibility with dc-sdk version 3.x.
11+
12+
#### Bug fixes
13+
14+
- Fixed the issue that parameter configuration of areaMeasurementOpts in the vc-measurements component, setting both showAngleLabel and showDistanceLabel to false, results in an error.[#518](https://github.com/zouyaoji/vue-cesium/issues/518)
15+
- Fixed the issue that Cesium.VERSION being undefined, causing an error.
16+
17+
318
### 3.2.5
419

520
_2023-12-27_

CHANGELOG.zh-CN.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
## 更新日志
22

3+
### 3.2.6
4+
5+
_2024-02-29_
6+
7+
#### 新特性
8+
9+
- `vc-measurements` 组件为量算结果添加格式化函数。`distanceFormatter``areaFormatter``angleFormatter`
10+
- 适配 `dc-sdk` 3.x 版本。
11+
12+
#### Bug 修复
13+
14+
- 修复 `vc-measurements` 组件 `areaMeasurementOpts` 的参数同时配置 `showAngleLabel``showDistanceLabel``false` 报错。[#518](https://github.com/zouyaoji/vue-cesium/issues/518)
15+
- 修复使用超图扩展Cesium包引入因没有 Cesium.VERSION 引起的报错问题。
16+
317
### 3.2.5
418

519
_2023-12-27_
620

721
#### Bug 修复
822

9-
- `vc-graphics-polygon` 组件使用 ref、reactive 包裹 hierarchy 参数后浏览器崩溃问题。
10-
- 原生 Cesium 下 `vc-provider-imagery-supermap`加载超图 iserver 的地图服务报错问题。
23+
- `vc-graphics-polygon` 组件使用 ref、reactive 包裹 hierarchy 参数后浏览器崩溃问题。
24+
- 原生 Cesium 下 `vc-provider-imagery-supermap`加载超图 iserver 的地图服务报错问题。
1125
- `vc-navigation-sm` 组件四个方向按钮连续点击不生效的问题。**【去掉了双击外圆盘回正北的功能】**
1226

1327
### 3.2.4
@@ -16,7 +30,7 @@ _2023-10-23_
1630

1731
#### Bug 修复
1832

19-
- 3.2.3 npm 发布错误,用3.2.4代替
33+
- 3.2.3 npm 发布错误,用 3.2.4 代替
2034

2135
### 3.2.3
2236

packages/components/viewer/src/defaultProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Mars3dConfig, VcCamera, VcContextOptions } from '@vue-cesium/utils/types'
1+
import type { Mars3dConfig, DCConfig, VcCamera, VcContextOptions } from '@vue-cesium/utils/types'
22
import type { PropType } from 'vue'
33
import { VcSkeletonProps } from '../../ui'
44
import { VcViewerCreatorFunction } from './useViewer'
@@ -207,5 +207,6 @@ export default {
207207
},
208208
viewerCreator: Function as PropType<VcViewerCreatorFunction>,
209209
mars3dConfig: Object as PropType<Mars3dConfig>,
210+
dcConfig: Object as PropType<DCConfig>,
210211
containerId: String
211212
}

packages/components/viewer/src/useViewer.ts

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import type {
1717
ViewerWidgetResizedEvent,
1818
VcContextOptions,
1919
VcViewerProvider,
20-
Mars3dConfig
20+
Mars3dConfig,
21+
DCConfig
2122
} from '@vue-cesium/utils/types'
2223
import { compareCesiumVersion, setViewerCamera } from '@vue-cesium/utils/cesium-helpers'
2324
import useLog from '@vue-cesium/composables/private/use-log'
@@ -888,6 +889,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter
888889
const cesiumPath = props.cesiumPath ? props.cesiumPath : globalConfig.value.cesiumPath
889890
const dirName = dirname(cesiumPath)
890891
const mars3dConfig = globalConfig.value.mars3dConfig || props.mars3dConfig
892+
const dcConfig = globalConfig.value.dcConfig || props.dcConfig
891893
if (mars3dConfig) {
892894
// 引入 mars3d
893895
const libsConfig = mars3dConfig.libs || getDefaultMars3dConfig()
@@ -903,6 +905,21 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter
903905
keys[key] = true
904906
loadLibs.push(...libsConfig[key])
905907
}
908+
} else if (dcConfig) {
909+
loadLibs.push(cesiumPath)
910+
loadLibs.push(cesiumPath.replace('dc.min.js', 'dc.min.css'))
911+
912+
loadLibs.push(dcConfig.Cesium)
913+
const dirName = dirname(dcConfig.Cesium)
914+
loadLibs.push(`${dirName}/Widgets/widgets.css`)
915+
916+
if (dcConfig.turf) {
917+
loadLibs.push(dcConfig.turf)
918+
}
919+
920+
if (dcConfig.echarts) {
921+
loadLibs.push(dcConfig.echarts)
922+
}
906923
} else if (cesiumPath.includes('/dc.base.min.js')) {
907924
loadLibs.push(cesiumPath)
908925
loadLibs.push(cesiumPath.replace('/dc.base.min.js', '/dc.core.min.js'))
@@ -915,7 +932,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter
915932
}
916933

917934
const secondaryLibs = loadLibs
918-
if (mars3dConfig) {
935+
if (mars3dConfig || dcConfig) {
919936
// mars3d 必须要等 Cesium 先初始化
920937
const primaryLib = loadLibs.find(v => v.includes('Cesium.js'))
921938
await loadScript(primaryLib)
@@ -934,9 +951,30 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter
934951

935952
return Promise.all(scriptLoadPromises).then(() => {
936953
if (globalThis.Cesium) {
937-
const listener = getInstanceListener(vcInstance, 'cesiumReady')
938-
listener && emit('cesiumReady', globalThis.Cesium)
939-
return globalThis.Cesium
954+
if (globalThis.DC) {
955+
const config: any = {
956+
...dcConfig,
957+
Cesium: globalThis.Cesium
958+
}
959+
if (dcConfig.echarts) {
960+
config.echarts = globalThis.echarts
961+
}
962+
963+
if (dcConfig.turf) {
964+
config.turf = globalThis.turf
965+
}
966+
967+
return globalThis.DC.ready(config).then(() => {
968+
globalThis.Cesium = DC.getLib('Cesium')
969+
const listener = getInstanceListener(vcInstance, 'cesiumReady')
970+
listener && emit('cesiumReady', globalThis.DC)
971+
return globalThis.Cesium
972+
})
973+
} else {
974+
const listener = getInstanceListener(vcInstance, 'cesiumReady')
975+
listener && emit('cesiumReady', globalThis.Cesium)
976+
return globalThis.Cesium
977+
}
940978
} else if (globalThis.XE) {
941979
// 兼容 cesiumlab earthsdk
942980
return globalThis.XE.ready().then(() => {
@@ -947,16 +985,28 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter
947985
})
948986
} else if (globalThis.DC) {
949987
// 兼容 dc-sdk
950-
globalThis.DC.use(globalThis.DcCore.default || globalThis.DcCore)
951-
globalThis.DC.baseUrl = `${dirName}/resources/`
952-
globalThis.DC.ready(() => {
953-
globalThis.Cesium = DC.Namespace.Cesium
954-
955-
const listener = getInstanceListener(vcInstance, 'cesiumReady')
956-
listener && emit('cesiumReady', globalThis.DC)
988+
if (compareCesiumVersion(globalThis.DC.VERSION, '3.0.0')) {
989+
return globalThis.DC.ready({
990+
...dcConfig,
991+
Cesium: globalThis.Cesium
992+
}).then(() => {
993+
globalThis.Cesium = DC.getLib('Cesium')
994+
const listener = getInstanceListener(vcInstance, 'cesiumReady')
995+
listener && emit('cesiumReady', globalThis.DC)
996+
return globalThis.Cesium
997+
})
998+
} else {
999+
globalThis.DC.use(globalThis.DcCore.default || globalThis.DcCore)
1000+
globalThis.DC.baseUrl = `${dirName}/resources/`
1001+
globalThis.DC.ready(() => {
1002+
globalThis.Cesium = DC.Namespace.Cesium
1003+
1004+
const listener = getInstanceListener(vcInstance, 'cesiumReady')
1005+
listener && emit('cesiumReady', globalThis.DC)
1006+
return globalThis.Cesium
1007+
})
9571008
return globalThis.Cesium
958-
})
959-
return globalThis.Cesium
1009+
}
9601010
} else {
9611011
reject(new Error('VueCesium ERROR: ' + 'Error loading CesiumJS!'))
9621012
}
@@ -1578,6 +1628,10 @@ export interface VcViewerProps {
15781628
* for mars3d only.
15791629
*/
15801630
mars3dConfig?: Mars3dConfig
1631+
/**
1632+
* for dc-sdk 3.0+ only.
1633+
*/
1634+
dcConfig?: DCConfig
15811635
/**
15821636
* Specifies the container id of the viewer.
15831637
*/

packages/utils/config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
/*
22
* @Author: zouyaoji@https://github.com/zouyaoji
33
* @Date: 2021-10-27 15:54:11
4-
* @LastEditTime: 2022-09-06 01:10:05
5-
* @LastEditors: zouyaoji
4+
* @LastEditTime: 2024-02-28 22:52:54
5+
* @LastEditors: zouyaoji 370681295@qq.com
66
* @Description:
7-
* @FilePath: \vue-cesium@next\packages\utils\config.ts
7+
* @FilePath: \vue-cesium\packages\utils\config.ts
88
*/
99
import type { Language } from '@vue-cesium/locale'
1010
import type { InjectionKey, Ref } from 'vue'
11-
import type { Mars3dConfig } from './types'
11+
import type { Mars3dConfig, DCConfig } from './types'
1212

1313
const hasSymbol = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'
1414
export interface ConfigProviderContext {
1515
cesiumPath?: string
1616
accessToken?: string
1717
locale?: Language
1818
mars3dConfig?: Mars3dConfig // for mars3d
19+
dcConfig?: DCConfig // for dc-sdk 3.0+
1920
reloadMode?: 'once' | 'all'
2021
__scriptPromise?: Promise<unknown>
2122
__viewerUnloadingPromise?: Promise<boolean>

packages/utils/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,16 @@ export type Mars3dConfig = {
717717
}
718718
}
719719

720+
export type DCConfig = {
721+
baseUrl: string
722+
Cesium: string
723+
echarts?: string
724+
turf?: string
725+
accessToken?: string
726+
logoImage?: string
727+
logoSize?: [number, number]
728+
}
729+
720730
export type Arrayable<T> = T | T[]
721731
export type Awaitable<T> = Promise<T> | T
722732

website/docs/zh-CN/analyses/vc-measurements.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,12 @@ ctrl + 右键取消绘制。
159159
[108.95573, 34.21761],
160160
[108.95499, 34.21761]
161161
]
162-
]
162+
],
163+
showAngleLabel: false,
164+
showDistanceLabel: false,
165+
areaFormatter: (value, defaultUnits, defaultLocale, defaultDecimals) => {
166+
return `${(value * 0.0015).toFixed(4)}`
167+
}
163168
},
164169
pointMeasurementOpts3: {
165170
measureUnits: {

0 commit comments

Comments
 (0)