Skip to content

Commit

Permalink
fix(vue-cesium): 🐛 cesiumJS 1.121 Breaking Changes
Browse files Browse the repository at this point in the history
closed #598
  • Loading branch information
zouyaoji committed Oct 9, 2024
1 parent 34df34c commit e6e6974
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Feature from './Feature'
import PickedFeatures from './PickedFeatures'
import { isArray } from '@vue-cesium/utils/util'
import { pickImageryLayerFeatures } from './util'
import { compareCesiumVersion } from '@vue-cesium/utils/cesium-helpers'

export default function (instance: VcComponentInternalInstance, props, $services: VcViewerProvider) {
// state
Expand Down Expand Up @@ -289,7 +290,10 @@ export default function (instance: VcComponentInternalInstance, props, $services

const computeScreenSpacePosition = (position: Cesium.Cartesian3, result: Cesium.Cartesian2) => {
const { viewer } = $services
return Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene, position, result)

return compareCesiumVersion(Cesium.VERSION, '1.121')
? Cesium.SceneTransforms.worldToWindowCoordinates(viewer.scene, position, result)
: Cesium.SceneTransforms['wgs84ToWindowCoordinates'](viewer.scene, position, result)
}

const update = () => {
Expand Down
24 changes: 19 additions & 5 deletions packages/components/controls/vc-overview-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { computed, createCommentVNode, defineComponent, getCurrentInstance, h, o
import VcViewer, { VcViewerProps, VcViewerRef } from '@vue-cesium/components/viewer'
import { hSlot } from '@vue-cesium/utils/private/render'
import { commonEmits } from '@vue-cesium/utils/emits'
import { makeColor } from '@vue-cesium/utils/cesium-helpers'
import { compareCesiumVersion, makeColor } from '@vue-cesium/utils/cesium-helpers'

export const overviewProps = {
position: {
Expand Down Expand Up @@ -170,10 +170,24 @@ export default defineComponent({
const wsPosition = Cartesian3.fromRadians(parentCameraRectangle.west, parentCameraRectangle.south)
const esPosition = Cartesian3.fromRadians(parentCameraRectangle.east, parentCameraRectangle.south)
const scene = overviewViewer.scene
const wnWindowPosition = SceneTransforms.wgs84ToWindowCoordinates(scene, wnPosition)
const enWindowPosition = SceneTransforms.wgs84ToWindowCoordinates(scene, enPosition)
const wsWindowPosition = SceneTransforms.wgs84ToWindowCoordinates(scene, wsPosition)
const esWindowPosition = SceneTransforms.wgs84ToWindowCoordinates(scene, esPosition)

compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates(scene, wnPosition)
: SceneTransforms['wgs84ToWindowCoordinates'](scene, wnPosition)

const wnWindowPosition = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates(scene, wnPosition)
: SceneTransforms['wgs84ToWindowCoordinates'](scene, wnPosition)
const enWindowPosition = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates(scene, enPosition)
: SceneTransforms['wgs84ToWindowCoordinates'](scene, enPosition)

const wsWindowPosition = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates(scene, wsPosition)
: SceneTransforms['wgs84ToWindowCoordinates'](scene, wsPosition)
const esWindowPosition = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates(scene, esPosition)
: SceneTransforms['wgs84ToWindowCoordinates'](scene, esPosition)

if (!defined(wnWindowPosition) || !defined(enWindowPosition) || !defined(wsWindowPosition) || !defined(esWindowPosition)) {
return
Expand Down
4 changes: 4 additions & 0 deletions packages/components/viewer/src/defaultProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export default {
type: Number,
default: 1.0
},
verticalExaggeration: {
type: Number,
default: 1.0
},
shadows: {
type: Boolean,
default: false
Expand Down
6 changes: 5 additions & 1 deletion packages/components/viewer/src/useViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,11 @@ export default function (props: VcViewerProps, ctx, vcInstance: VcComponentInter
vcInstance.mounted = true

if (compareCesiumVersion(Cesium.VERSION, '1.83')) {
viewer.scene.globe.terrainExaggeration = options.terrainExaggeration
if (compareCesiumVersion(Cesium.VERSION, '1.116')) {
viewer.scene.verticalExaggeration = options.verticalExaggeration || options.terrainExaggeration
} else {
viewer.scene.globe['terrainExaggeration'] = options.verticalExaggeration || options.terrainExaggeration
}
}

// vue-cesium 扩展补充
Expand Down
19 changes: 15 additions & 4 deletions packages/composables/use-drawing/use-drawing-polyline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: zouyaoji@https://github.com/zouyaoji
* @Date: 2021-10-21 10:43:32
* @LastEditTime: 2023-05-23 10:21:44
* @LastEditTime: 2024-10-08 23:22:33
* @LastEditors: zouyaoji [email protected]
* @Description:
* @FilePath: \vue-cesium\packages\composables\use-drawing\use-drawing-polyline.ts
Expand All @@ -14,7 +14,13 @@ import { VcCollectionLabel, VcCollectionPoint, VcCollectionPrimitive, VcLabelPro
import { VcBtn, VcTooltip } from '@vue-cesium/components/ui'
import { useLocale } from '../use-locale'
import { DrawStatus, MeasureUnits } from '@vue-cesium/shared'
import { calculateAreaByPostions, getFirstIntersection, getGeodesicDistance, makeCartesian3Array } from '@vue-cesium/utils/cesium-helpers'
import {
calculateAreaByPostions,
compareCesiumVersion,
getFirstIntersection,
getGeodesicDistance,
makeCartesian3Array
} from '@vue-cesium/utils/cesium-helpers'
import type { VcPolylineDrawing } from '@vue-cesium/utils/drawing-types'
import type { VcComponentInternalInstance, VcDrawingProvider, VcReadyObject } from '@vue-cesium/utils/types'
import { reactive, VNode } from 'vue'
Expand Down Expand Up @@ -277,7 +283,9 @@ export default function (props, ctx, cmpName: string) {
const scene = viewer.scene

let startPosition = positions[0]
const positionWindow = SceneTransforms.wgs84ToWindowCoordinates(scene, startPosition, {} as any)
const positionWindow = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates(scene, startPosition, {} as any)
: SceneTransforms['wgs84ToWindowCoordinates'](scene, startPosition, {} as any)

let startPositionWindow = defined(positionWindow)
? Cartesian2.clone(positionWindow, {} as any)
Expand All @@ -290,7 +298,10 @@ export default function (props, ctx, cmpName: string) {
const labels = labelCollection[index]._labels
const labelTotalLength = labels[labels.length - 1]
for (let i = 1; i < positions.length; i++) {
const positionWindow = SceneTransforms.wgs84ToWindowCoordinates(scene, positions[i], {} as any)
const positionWindow = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates(scene, positions[i], {} as any)
: SceneTransforms['wgs84ToWindowCoordinates'](scene, positions[i], {} as any)

if (defined(positionWindow)) {
const l = (startPositionWindow.y - positionWindow.y) / (positionWindow.x - startPositionWindow.x)
if (labels[i - 1] !== labelTotalLength) {
Expand Down
29 changes: 22 additions & 7 deletions packages/composables/use-drawing/use-drawing-segment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: zouyaoji@https://github.com/zouyaoji
* @Date: 2021-10-22 14:09:42
* @LastEditTime: 2024-02-28 17:21:40
* @LastEditTime: 2024-10-08 23:24:06
* @LastEditors: zouyaoji [email protected]
* @Description:
* @FilePath: \vue-cesium\packages\composables\use-drawing\use-drawing-segment.ts
Expand All @@ -23,7 +23,8 @@ import {
getPolylineSegmentPitch,
makeCartesian2,
makeCartesian3Array,
getFirstIntersection
getFirstIntersection,
compareCesiumVersion
} from '@vue-cesium/utils/cesium-helpers'
import { VcSegmentDrawing } from '@vue-cesium/utils/drawing-types'
import type { VcComponentInternalInstance, VcDrawingProvider, VcReadyObject } from '@vue-cesium/utils/types'
Expand Down Expand Up @@ -422,9 +423,14 @@ export default function (props, ctx, cmpName: string) {
endPoint = ellipsoid.cartographicToCartesian(endPointCartographic, endPoint)
}

if (SceneTransforms.wgs84ToWindowCoordinates(scene, positions[0], {} as any).y < movement.y) {
const worldToWindowCoordinates = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates
: SceneTransforms['wgs84ToWindowCoordinates']

if (worldToWindowCoordinates(scene, positions[0], {} as any).y < movement.y) {
surfaceNormal = Cartesian3.negate(surfaceNormal, {} as any)
}

let diffrence = Cartesian3.subtract(endPoint, p1, {} as any)
diffrence = Cartesian3.projectVector(diffrence, surfaceNormal, diffrence)
endPoint = Cartesian3.add(p1, diffrence, endPoint)
Expand Down Expand Up @@ -512,7 +518,12 @@ export default function (props, ctx, cmpName: string) {
const scene = viewer.scene

let startPosition = polyline.positions[0]
const positionWindow = SceneTransforms.wgs84ToWindowCoordinates(scene, startPosition, {} as any)

const worldToWindowCoordinates = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates
: SceneTransforms['wgs84ToWindowCoordinates']

const positionWindow = worldToWindowCoordinates(scene, startPosition, {} as any)

let startPositionWindow = defined(positionWindow)
? Cartesian2.clone(positionWindow, {} as any)
Expand All @@ -527,7 +538,7 @@ export default function (props, ctx, cmpName: string) {

if (!labelTotalLength) return
for (let i = 1; i < positions.length; i++) {
const positionWindow = SceneTransforms.wgs84ToWindowCoordinates(scene, positions[i], {} as any)
const positionWindow = worldToWindowCoordinates(scene, positions[i], {} as any)
if (defined(positionWindow)) {
const l = (startPositionWindow.y - positionWindow.y) / (positionWindow.x - startPositionWindow.x)
const label = labels[i - 1]
Expand Down Expand Up @@ -560,8 +571,12 @@ export default function (props, ctx, cmpName: string) {
const positions = polyline.positions
const startPosition = positions[0]
const endPosition = positions[1]
const startPositionWindow = SceneTransforms.wgs84ToWindowCoordinates(scene, startPosition, {} as any)
const endPositionWindow = SceneTransforms.wgs84ToWindowCoordinates(scene, endPosition, {} as any)
const worldToWindowCoordinates = compareCesiumVersion(Cesium.VERSION, '1.121')
? SceneTransforms.worldToWindowCoordinates
: SceneTransforms['wgs84ToWindowCoordinates']

const startPositionWindow = worldToWindowCoordinates(scene, startPosition, {} as any)
const endPositionWindow = worldToWindowCoordinates(scene, endPosition, {} as any)
if (defined(startPositionWindow) && defined(endPositionWindow)) {
const labelCollection: Array<Cesium.LabelCollection> = (primitiveCollection as any)._primitives.filter(
v => v instanceof Cesium.LabelCollection
Expand Down

0 comments on commit e6e6974

Please sign in to comment.