From e6e69740d07cc1ee3566ed393bbb24e537223727 Mon Sep 17 00:00:00 2001 From: zouyaoji <370681295@qq.com> Date: Wed, 9 Oct 2024 15:16:45 +0800 Subject: [PATCH] fix(vue-cesium): :bug: cesiumJS 1.121 Breaking Changes closed #598 --- .../use-selection-indicatior.ts | 6 +++- .../controls/vc-overview-map/index.ts | 24 +++++++++++---- .../components/viewer/src/defaultProps.ts | 4 +++ packages/components/viewer/src/useViewer.ts | 6 +++- .../use-drawing/use-drawing-polyline.ts | 19 +++++++++--- .../use-drawing/use-drawing-segment.ts | 29 ++++++++++++++----- 6 files changed, 70 insertions(+), 18 deletions(-) diff --git a/packages/components/controls/selection-indicator/use-selection-indicatior.ts b/packages/components/controls/selection-indicator/use-selection-indicatior.ts index 3ff77c09..dd0c0f78 100644 --- a/packages/components/controls/selection-indicator/use-selection-indicatior.ts +++ b/packages/components/controls/selection-indicator/use-selection-indicatior.ts @@ -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 @@ -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 = () => { diff --git a/packages/components/controls/vc-overview-map/index.ts b/packages/components/controls/vc-overview-map/index.ts index b6997ea2..94fb3431 100644 --- a/packages/components/controls/vc-overview-map/index.ts +++ b/packages/components/controls/vc-overview-map/index.ts @@ -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: { @@ -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 diff --git a/packages/components/viewer/src/defaultProps.ts b/packages/components/viewer/src/defaultProps.ts index 754608b9..e160641c 100644 --- a/packages/components/viewer/src/defaultProps.ts +++ b/packages/components/viewer/src/defaultProps.ts @@ -121,6 +121,10 @@ export default { type: Number, default: 1.0 }, + verticalExaggeration: { + type: Number, + default: 1.0 + }, shadows: { type: Boolean, default: false diff --git a/packages/components/viewer/src/useViewer.ts b/packages/components/viewer/src/useViewer.ts index f591a01d..963e1153 100644 --- a/packages/components/viewer/src/useViewer.ts +++ b/packages/components/viewer/src/useViewer.ts @@ -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 扩展补充 diff --git a/packages/composables/use-drawing/use-drawing-polyline.ts b/packages/composables/use-drawing/use-drawing-polyline.ts index e9727d07..b4398506 100644 --- a/packages/composables/use-drawing/use-drawing-polyline.ts +++ b/packages/composables/use-drawing/use-drawing-polyline.ts @@ -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 370681295@qq.com * @Description: * @FilePath: \vue-cesium\packages\composables\use-drawing\use-drawing-polyline.ts @@ -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' @@ -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) @@ -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) { diff --git a/packages/composables/use-drawing/use-drawing-segment.ts b/packages/composables/use-drawing/use-drawing-segment.ts index 6039129b..563adf2f 100644 --- a/packages/composables/use-drawing/use-drawing-segment.ts +++ b/packages/composables/use-drawing/use-drawing-segment.ts @@ -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 370681295@qq.com * @Description: * @FilePath: \vue-cesium\packages\composables\use-drawing\use-drawing-segment.ts @@ -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' @@ -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) @@ -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) @@ -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] @@ -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 = (primitiveCollection as any)._primitives.filter( v => v instanceof Cesium.LabelCollection