Skip to content

Commit 34df34c

Browse files
committed
fix(vue-cesium): 🐛 viewshed DrawingAction offsetHeight not working
closed #610
1 parent 64cacc5 commit 34df34c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

packages/components/primitives/viewshed/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createCommentVNode, defineComponent, getCurrentInstance, onUnmounted, PropType, watch, WatchStopHandle } from 'vue'
1+
import { createCommentVNode, defineComponent, getCurrentInstance, onUnmounted, PropType, toRaw, watch, WatchStopHandle } from 'vue'
22
import type { VcColor, VcComponentInternalInstance } from '@vue-cesium/utils/types'
33
import { useCommon } from '@vue-cesium/composables'
44
import { scene } from '@vue-cesium/utils/cesium-props'
55
import { kebabCase } from '@vue-cesium/utils/util'
66
import { commonEmits } from '@vue-cesium/utils/emits'
77
import { Viewshed } from '@vue-cesium/shared'
8-
import { makeColor } from '@vue-cesium/utils/cesium-helpers'
8+
import { makeCartesian3, makeColor } from '@vue-cesium/utils/cesium-helpers'
99
import fragmentShader from '@vue-cesium/shared/shaders/Viewshed'
1010

1111
export const viewshedProps = {
@@ -82,7 +82,8 @@ export default defineComponent({
8282
if (!instance.mounted) {
8383
return
8484
}
85-
updateViewshed(newStartPosition, newEndPosition)
85+
86+
updateViewshed(makeCartesian3(toRaw(newStartPosition)), makeCartesian3(toRaw(newEndPosition)))
8687
},
8788
{
8889
deep: true
@@ -219,7 +220,6 @@ export default defineComponent({
219220
invisibleColor: makeColor(props.invisibleColor),
220221
showGridLine: props.showGridLine
221222
})
222-
223223
;(viewshed._viewshedShadowMap as any).cascadesEnabled = false
224224
viewshed._viewshedShadowMap.softShadows = false
225225
viewshed._viewshedShadowMap.normalOffset = false
@@ -248,7 +248,7 @@ export default defineComponent({
248248
shaderSourceText = shaderSourceText.replace(/out_FragColor/g, 'gl_FragColor')
249249
}
250250

251-
updateViewshed(props.startPosition, props.endPosition)
251+
updateViewshed(makeCartesian3(toRaw(props.startPosition)), makeCartesian3(toRaw(props.endPosition)))
252252
attachedViewshedStage = new PostProcessStage({
253253
fragmentShader: props.fragmentShader || shaderSourceText,
254254
uniforms: props.uniforms || {
@@ -333,6 +333,7 @@ export default defineComponent({
333333

334334
const updateViewshed = (startPosition, endPosition) => {
335335
const viewshed = instance.cesiumObject as Viewshed
336+
336337
const { Cartesian3 } = Cesium
337338
let diffrence = Cartesian3.subtract(endPosition, startPosition, new Cartesian3())
338339
const magnitudeSquared = Cartesian3.magnitudeSquared(diffrence)

packages/shared/analyses/Viewshed.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
* @Author: zouyaoji@https://github.com/zouyaoji
33
* @Date: 2022-04-16 18:52:39
4-
* @LastEditTime: 2022-05-14 22:42:17
5-
* @LastEditors: zouyaoji
4+
* @LastEditTime: 2024-10-09 14:57:31
5+
* @LastEditors: zouyaoji [email protected]
66
* @Description:
7-
* @FilePath: \vue-cesium@next\packages\shared\analyses\Viewshed.ts
7+
* @FilePath: \vue-cesium\packages\shared\analyses\Viewshed.ts
88
*/
99

1010
import { VcViewshedOpts } from '@vue-cesium/utils/drawing-types'
@@ -142,7 +142,7 @@ class Viewshed {
142142

143143
this._offsetHeight = Number(e)
144144
this.setView({
145-
destination: this._position,
145+
destination: this._position.clone(),
146146
orientation: {
147147
heading: this._spotLightCamera.heading,
148148
pitch: this._spotLightCamera.pitch,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
* @Author: zouyaoji@https://github.com/zouyaoji
33
* @Date: 2022-01-06 11:30:01
4-
* @LastEditTime: 2023-07-29 18:38:54
4+
* @LastEditTime: 2024-10-09 14:56:02
55
* @LastEditors: zouyaoji [email protected]
66
* @Description:
77
* @FilePath: \vue-cesium\website\docs\zh-CN\analyses\vc-analyses.md
@@ -29,6 +29,7 @@
2929
:main-fab-opts="mainFabOpts"
3030
:offset="[10, 30]"
3131
:editable="editable"
32+
:viewshedAnalysisOpts="viewshedAnalysisOpts"
3233
@draw-evt="drawEvt"
3334
@active-evt="activeEvt"
3435
@editor-evt="editorEvt"
@@ -63,6 +64,11 @@
6364
editable: false,
6465
mainFabOpts: {
6566
direction: 'right'
67+
},
68+
viewshedAnalysisOpts: {
69+
viewshedOpts: {
70+
offsetHeight: 5
71+
}
6672
}
6773
}
6874
},

0 commit comments

Comments
 (0)