属性框位置高度计算

This commit is contained in:
zh
2025-08-22 17:51:45 +08:00
parent 1229226e8f
commit 1a1aa9f6a5

View File

@ -42,6 +42,7 @@ import { getGoodsList } from '../../../Tools/getGoodsList'
class BillboardObject extends Base {
#_postRenderEvent = null
#_destroyMouseEvent = null
#_billboardHeight = 0
/**
@ -122,6 +123,7 @@ class BillboardObject extends Base {
this.options.positions.alt = Number(
Number(options.positions.alt || 0).toFixed(2)
)
this.#_billboardHeight = this.options.positions.alt
// this.options.diffuseShow = options.diffuseShow || false
// this.options.diffuseRadius = (options.diffuseRadius || options.diffuseRadius === 0) ? options.diffuseRadius : 10
// this.options.diffuseDuration = (options.diffuseDuration || options.diffuseDuration === 0) ? options.diffuseDuration : 2000
@ -203,7 +205,8 @@ class BillboardObject extends Base {
this.#_postRenderEvent = () => {
let siteInfoPosition = Cesium.Cartesian3.fromDegrees(
this.options.positions.lng,
this.options.positions.lat
this.options.positions.lat,
this.#_billboardHeight
)
if (this.attributeElm && this.entity) {
let winpos = this.sdk.viewer.scene.cartesianToCanvasCoordinates(
@ -698,6 +701,26 @@ class BillboardObject extends Base {
if (this.entity) {
this.entity.billboard.heightReference = heightMode
this.entity.label.heightReference = heightMode
if(heightMode == Cesium.HeightReference.CLAMP_TO_GROUND) {
if (this.sdk.viewer.scene.terrainProvider.availability) {
Cesium.sampleTerrainMostDetailed(
this.sdk.viewer.scene.terrainProvider,
[
Cesium.Cartographic.fromDegrees(
this.options.positions.lng,
this.options.positions.lat
)
]
).then(position => {
this.#_billboardHeight = position[0].height
})
} else {
this.#_billboardHeight = 0
}
}
else {
this.#_billboardHeight = this.options.positions.alt
}
}
this._elms.heightMode && (this._elms.heightMode.value = heightModeName)
}
@ -752,6 +775,7 @@ class BillboardObject extends Base {
}
set alt(v) {
this.options.positions.alt = Number(Number(v).toFixed(2))
this.#_billboardHeight = this.options.positions.alt
// this.scan && (this.scan.alt = v)
// this.diffuse && (this.diffuse.alt = v)
this.renewPoint()
@ -2387,6 +2411,7 @@ class BillboardObject extends Base {
async remove() {
await remove_entity_from_cluster(this.sdk.viewer, this.entity)
this.entity = null
this.attributeBoxState = false
if (!this.sdk.viewer || !this.sdk.viewer.entities) {
return
}
@ -2592,6 +2617,7 @@ class BillboardObject extends Base {
switch (this._elms.heightMode.value) {
case '海拔高度':
heightElm.value = this.options.positions.alt
this.#_billboardHeight = this.options.positions.alt
break
case '相对地表':
if (this.sdk.viewer.scene.terrainProvider.availability) {
@ -2607,15 +2633,18 @@ class BillboardObject extends Base {
heightElm.value = Number(
(this.options.positions.alt - position[0].height).toFixed(2)
)
this.#_billboardHeight = this.options.positions.alt
})
} else {
heightElm.value = this.options.positions.alt
this.#_billboardHeight = this.options.positions.alt
}
break
case '依附地表':
break
case '依附模型':
heightElm.value = this.options.positions.alt
this.#_billboardHeight = this.options.positions.alt
break
}
}
@ -2979,11 +3008,7 @@ class BillboardObject extends Base {
}
this.sdk.viewer.scene.postRender.addEventListener(this.#_postRenderEvent)
let leftTopElm = attributeElm.getElementsByClassName('left-top')[0]
let rightTopElm = attributeElm.getElementsByClassName('right-top')[0]
let leftOnmousedown = (e) => {
console.log(1111111111)
if (this.options.attributePos.width < 200) {
this.options.attributePos.width = 200
}