Skip to content

Commit

Permalink
fix: the Cesium version number comparison method is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyaoji committed Feb 1, 2023
1 parent d7d562f commit 0812f05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/components/viewer/src/useViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
VcViewerProvider,
Mars3dConfig
} from '@vue-cesium/utils/types'
import { setViewerCamera } from '@vue-cesium/utils/cesium-helpers'
import { compareCesiumVersion, setViewerCamera } from '@vue-cesium/utils/cesium-helpers'
import useLog from '@vue-cesium/composables/private/use-log'
import { useEvents } from '@vue-cesium/composables'
import { getMars3dConfig as getDefaultMars3dConfig } from './loadUtil'
Expand Down Expand Up @@ -659,7 +659,7 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter
vcInstance.viewerElement = (viewer as any)._element
vcInstance.mounted = true

if (Cesium.VERSION >= '1.83') {
if (compareCesiumVersion(Cesium.VERSION, '1.83')) {
viewer.scene.globe.terrainExaggeration = options.terrainExaggeration
}

Expand Down
19 changes: 19 additions & 0 deletions packages/utils/cesium-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,3 +1065,22 @@ export function heightToLevel(altitude: number) {

return Math.round(D + (A - D) / (1 + Math.pow(altitude / C, B)))
}

export function compareCesiumVersion(a, b) {
const vAs = a.split('.').map(v => Number(v))
const bVersionA = vAs[0]
const lVersionA = vAs[1]
const vBs = b.split('.').map(v => Number(v))
const bVersionB = vBs[0]
const lVersionB = vBs[1]

if (bVersionA > bVersionB) {
return true
}

if (bVersionA === bVersionB && lVersionA >= lVersionB) {
return true
}

return false
}

0 comments on commit 0812f05

Please sign in to comment.