Skip to content

Commit

Permalink
fix(vue-cesium): 🐛 viewshed DrawingAction offsetHeight not working
Browse files Browse the repository at this point in the history
closed #610
  • Loading branch information
zouyaoji committed Oct 9, 2024
1 parent 64cacc5 commit 34df34c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
11 changes: 6 additions & 5 deletions packages/components/primitives/viewshed/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createCommentVNode, defineComponent, getCurrentInstance, onUnmounted, PropType, watch, WatchStopHandle } from 'vue'
import { createCommentVNode, defineComponent, getCurrentInstance, onUnmounted, PropType, toRaw, watch, WatchStopHandle } from 'vue'
import type { VcColor, VcComponentInternalInstance } from '@vue-cesium/utils/types'
import { useCommon } from '@vue-cesium/composables'
import { scene } from '@vue-cesium/utils/cesium-props'
import { kebabCase } from '@vue-cesium/utils/util'
import { commonEmits } from '@vue-cesium/utils/emits'
import { Viewshed } from '@vue-cesium/shared'
import { makeColor } from '@vue-cesium/utils/cesium-helpers'
import { makeCartesian3, makeColor } from '@vue-cesium/utils/cesium-helpers'
import fragmentShader from '@vue-cesium/shared/shaders/Viewshed'

export const viewshedProps = {
Expand Down Expand Up @@ -82,7 +82,8 @@ export default defineComponent({
if (!instance.mounted) {
return
}
updateViewshed(newStartPosition, newEndPosition)

updateViewshed(makeCartesian3(toRaw(newStartPosition)), makeCartesian3(toRaw(newEndPosition)))
},
{
deep: true
Expand Down Expand Up @@ -219,7 +220,6 @@ export default defineComponent({
invisibleColor: makeColor(props.invisibleColor),
showGridLine: props.showGridLine
})

;(viewshed._viewshedShadowMap as any).cascadesEnabled = false
viewshed._viewshedShadowMap.softShadows = false
viewshed._viewshedShadowMap.normalOffset = false
Expand Down Expand Up @@ -248,7 +248,7 @@ export default defineComponent({
shaderSourceText = shaderSourceText.replace(/out_FragColor/g, 'gl_FragColor')
}

updateViewshed(props.startPosition, props.endPosition)
updateViewshed(makeCartesian3(toRaw(props.startPosition)), makeCartesian3(toRaw(props.endPosition)))
attachedViewshedStage = new PostProcessStage({
fragmentShader: props.fragmentShader || shaderSourceText,
uniforms: props.uniforms || {
Expand Down Expand Up @@ -333,6 +333,7 @@ export default defineComponent({

const updateViewshed = (startPosition, endPosition) => {
const viewshed = instance.cesiumObject as Viewshed

const { Cartesian3 } = Cesium
let diffrence = Cartesian3.subtract(endPosition, startPosition, new Cartesian3())
const magnitudeSquared = Cartesian3.magnitudeSquared(diffrence)
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/analyses/Viewshed.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* @Author: zouyaoji@https://github.com/zouyaoji
* @Date: 2022-04-16 18:52:39
* @LastEditTime: 2022-05-14 22:42:17
* @LastEditors: zouyaoji
* @LastEditTime: 2024-10-09 14:57:31
* @LastEditors: zouyaoji [email protected]
* @Description:
* @FilePath: \vue-cesium@next\packages\shared\analyses\Viewshed.ts
* @FilePath: \vue-cesium\packages\shared\analyses\Viewshed.ts
*/

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

this._offsetHeight = Number(e)
this.setView({
destination: this._position,
destination: this._position.clone(),
orientation: {
heading: this._spotLightCamera.heading,
pitch: this._spotLightCamera.pitch,
Expand Down
8 changes: 7 additions & 1 deletion website/docs/zh-CN/analyses/vc-analyses.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
* @Author: zouyaoji@https://github.com/zouyaoji
* @Date: 2022-01-06 11:30:01
* @LastEditTime: 2023-07-29 18:38:54
* @LastEditTime: 2024-10-09 14:56:02
* @LastEditors: zouyaoji [email protected]
* @Description:
* @FilePath: \vue-cesium\website\docs\zh-CN\analyses\vc-analyses.md
Expand Down Expand Up @@ -29,6 +29,7 @@
:main-fab-opts="mainFabOpts"
:offset="[10, 30]"
:editable="editable"
:viewshedAnalysisOpts="viewshedAnalysisOpts"
@draw-evt="drawEvt"
@active-evt="activeEvt"
@editor-evt="editorEvt"
Expand Down Expand Up @@ -63,6 +64,11 @@
editable: false,
mainFabOpts: {
direction: 'right'
},
viewshedAnalysisOpts: {
viewshedOpts: {
offsetHeight: 5
}
}
}
},
Expand Down

0 comments on commit 34df34c

Please sign in to comment.