Files
sdk4.0/src/Obj/Base/Explosion/index.js

383 lines
12 KiB
JavaScript
Raw Normal View History

2025-07-03 13:54:01 +08:00
import Base from "../index";
import Dialog from '../../Element/Dialog';
import EventBinding from '../../Element/Dialog/eventBinding';
import { html } from "./_element";
import MouseEvent from '../../../Event/index'
import { syncData } from '../../../Global/MultiViewportMode'
import MouseTip from '../../../MouseTip'
import { setSplitDirection, syncSplitData, setActiveId } from '../../../Global/SplitScreen'
import { setActiveViewer, closeRotateAround, closeViewFollow, getGroundCover} from '../../../Global/global'
class Explosion extends Base {
/**
* @constructor
* @description 爆炸
* @param sdk
* @param options {object} 爆炸属性
* */
constructor(sdk, options = {}, _Dialog = {}) {
super(sdk, options);
this.viewer = sdk.viewer
this.options.show = (options.show || options.show === false) ? options.show : true
this.options.name = this.options.name || '未命名对象'
this.options.size = (this.options.size || this.options.size === 0) ? this.options.size : 80
this.options.scaleByDistance = (options.scaleByDistance || options.scaleByDistance === false) ? options.scaleByDistance : true
this.event = new MouseEvent(this.sdk)
this.Dialog = _Dialog
this.operate = {}
this._elms = {};
this._EventBinding = new EventBinding()
this.sdk.addIncetance(this.options.id, this)
Explosion.create(this)
}
get type() {
return 'Explosion'
}
// 创建
static create(that) {
let img_bz = []
for (let i = 10001; i <= 10120; i++) {
let src = that.getSourceRootPath() + `/img/frameAnimation/explosion/b${i}.png`
img_bz.push(src)
}
let i = 0
let flyEntity = new Cesium.Entity({
id: that.options.id,
show: that.options.show,
position: new Cesium.CallbackProperty(() => {
return Cesium.Cartesian3.fromDegrees(that.options.position.lng, that.options.position.lat, that.options.position.alt)
}, false),
billboard: {
image: new Cesium.CallbackProperty(() => {
let img = img_bz[flyEntity.imgIndex]
flyEntity.imgIndex++
if (flyEntity.imgIndex >= img_bz.length) {
flyEntity.imgIndex = 0
}
return img
}, false),
// scale: that.options.size,
disableDepthTestDistance: new Cesium.CallbackProperty(function () {
return getGroundCover() ? undefined : Number.POSITIVE_INFINITY
}, false),
width: that.options.size,
height: that.options.size,
sizeInMeters: that.options.scaleByDistance,
pixelOffset: { x: 0, y: -20 }
},
});
flyEntity.imgIndex = 0
that.entity = that.viewer.entities.add(flyEntity)
syncData(that.sdk, that.options.id)
if(that.options.show) {
setSplitDirection(0, that.options.id)
}
}
// 编辑框
async edit(state) {
let _this = this
this.originalOptions = this.deepCopyObj(this.options)
if (this._DialogObject && this._DialogObject.close) {
this._DialogObject.close()
this._DialogObject = null
}
if (state) {
this._DialogObject = await new Dialog(this.sdk, this.options, {
title: '爆炸属性', left: '180px', top: '100px',
confirmCallBack: (options) => {
this.name = this.name.trim()
if(!this.name) {
this.name = '未命名对象'
}
this.originalOptions = this.deepCopyObj(this.options)
this._DialogObject.close()
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(this.originalOptions)
syncData(this.sdk, this.options.id)
syncSplitData(this.sdk, this.options.id)
},
resetCallBack: () => {
this.reset()
this.Dialog.resetCallBack && this.Dialog.resetCallBack()
},
removeCallBack: () => {
this.Dialog.removeCallBack && this.Dialog.removeCallBack()
},
closeCallBack: () => {
this.reset()
this.positionEditing = false
this.Dialog.closeCallBack && this.Dialog.closeCallBack()
},
showCallBack: (show) => {
this.options.show = show
this.originalOptions.show = show
this.show = show
this.Dialog.showCallBack && this.Dialog.showCallBack()
},
translationalCallBack: () => {
this.positionEditing = !this.positionEditing
},
})
this._DialogObject._element.body.className = this._DialogObject._element.body.className + ' explosion'
let contentElm = document.createElement('div');
contentElm.innerHTML = html()
this._DialogObject.contentAppChild(contentElm)
let all_elm = contentElm.getElementsByTagName("*")
this._EventBinding.on(this, all_elm)
this._elms = this._EventBinding.element
this.scaleByDistance = this.options.scaleByDistance
}
}
async flyTo(options = {}) {
setActiveViewer(0)
closeRotateAround(this.sdk)
closeViewFollow(this.sdk)
if (this.options.customView && this.options.customView.relativePosition && this.options.customView.orientation) {
let orientation = {
heading: Cesium.Math.toRadians(this.options.customView.orientation.heading || 0.0),
pitch: Cesium.Math.toRadians(this.options.customView.orientation.pitch || -60.0),
roll: Cesium.Math.toRadians(this.options.customView.orientation.roll || 0.0)
}
let lng = this.options.customView.relativePosition.lng
let lat = this.options.customView.relativePosition.lat
let alt = this.options.customView.relativePosition.alt
let destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
let position = { lng: 0, lat: 0 }
if (this.options.position) {
position = { ...this.options.position }
}
else if (this.options.positions) {
position = { ...this.options.positions[0] }
}
else if (this.options.center) {
position = { ...this.options.center }
}
else if (this.options.start) {
position = { ...this.options.start }
}
else {
if (this.options.hasOwnProperty('lng')) {
position.lng = this.options.lng
}
if (this.options.hasOwnProperty('lat')) {
position.lat = this.options.lat
}
if (this.options.hasOwnProperty('alt')) {
position.alt = this.options.alt
}
}
// 如果没有高度值,则获取紧贴高度计算
if (!position.hasOwnProperty('alt')) {
position.alt = await this.getClampToHeight(position)
}
lng = this.options.customView.relativePosition.lng + position.lng
lat = this.options.customView.relativePosition.lat + position.lat
alt = this.options.customView.relativePosition.alt + position.alt
destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
this.sdk.viewer.camera.flyTo({
destination: destination,
orientation: orientation
})
}
else {
this.sdk.viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(this.options.position.lng, this.options.position.lat, this.options.position.alt + (this.options.size * 8)),
orientation: options.orientation || {
heading: Cesium.Math.toRadians(0.0),
pitch: Cesium.Math.toRadians(-85.0),
roll: Cesium.Math.toRadians(0.0)
},
})
}
}
reset() {
if (!this.entity) {
return
}
this.previous = null
this.options = this.deepCopyObj(this.originalOptions)
this.name = this.originalOptions.name
this.size = this.originalOptions.size
this.scaleByDistance = this.originalOptions.scaleByDistance
this.lng = this.options.position.lng
this.lat = this.options.position.lat
}
get scaleByDistance() {
return this.options.scaleByDistance
}
set scaleByDistance(v) {
this.options.scaleByDistance = v
this.entity.billboard.sizeInMeters = v
this._elms.scaleByDistance && this._elms.scaleByDistance.forEach((item) => {
item.checked = v
})
}
get lng() {
return this.options.position.lng
}
set lng(v) {
this.options.position.lng = v
this._elms.lng && this._elms.lng.forEach((item) => {
item.value = v
})
}
get lat() {
return this.options.position.lat
}
set lat(v) {
this.options.position.lat = v
this._elms.lat && this._elms.lat.forEach((item) => {
item.value = v
})
}
get alt() {
return this.options.position.alt
}
set alt(v) {
this.options.position.alt = v
this._elms.alt && this._elms.alt.forEach((item) => {
item.value = v
})
}
get size() {
return this.options.size
}
set size(v) {
this.options.size = v
this.entity.billboard.width = this.options.size
this.entity.billboard.height = this.options.size
this._elms.size && this._elms.size.forEach((item) => {
item.value = v
})
}
/**@desc
*
* @memberOf Source
* @param status {boolean}
*
* */
set positionEditing(status) {
if (YJ.Measure.GetMeasureStatus() || !this.sdk || !this.sdk.viewer || !this.entity) {
return
}
this.operate.positionEditing = status
if (status === true) {
this.tip && this.tip.destroy()
this.tip = new MouseTip('点击鼠标左键确认,右键取消', this.sdk)
this.previous = {
position: { ...this.options.position }
}
this.event.mouse_move((movement, cartesian) => {
let positions = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
this.lng = positions.lng
this.lat = positions.lat
this.alt = positions.alt
this.tip.setPosition(
cartesian,
movement.endPosition.x,
movement.endPosition.y
)
})
this.event.mouse_left((movement, cartesian) => {
let positions = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
this.lng = positions.lng
this.lat = positions.lat
this.alt = positions.alt
this.previous = {
position: { ...this.options.position }
}
this.event.mouse_move(() => { })
this.event.mouse_left(() => { })
this.event.mouse_right(() => { })
this.event.gesture_pinck_start(() => { })
this.event.gesture_pinck_end(() => { })
this.positionEditing = false
})
this.event.mouse_right((movement, cartesian) => {
this.positionEditing = false
})
this.event.gesture_pinck_start((movement, cartesian) => {
let startTime = new Date()
this.event.gesture_pinck_end(() => {
let endTime = new Date()
if (endTime - startTime >= 500) {
this.positionEditing = false
}
else {
let positions = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
this.lng = positions.lng
this.lat = positions.lat
this.alt = positions.alt
this.previous = {
position: { ...this.options.position }
}
this.event.mouse_move(() => { })
this.event.mouse_left(() => { })
this.event.mouse_right(() => { })
this.event.gesture_pinck_start(() => { })
this.event.gesture_pinck_end(() => { })
this.positionEditing = false
}
})
})
}
else {
if (this.event) {
this.event.mouse_move(() => { })
this.event.mouse_left(() => { })
this.event.mouse_right(() => { })
this.event.gesture_pinck_start(() => { })
this.event.gesture_pinck_end(() => { })
}
this.tip && this.tip.destroy()
if (this.previous) {
this.lng = this.previous.position.lng
this.lat = this.previous.position.lat
this.alt = this.previous.position.alt
}
}
}
get positionEditing() {
return this.operate.positionEditing
}
/**
* 删除
*/
async remove() {
this.viewer.entities.remove(this.entity)
this.entity = null
if (this._DialogObject && !this._DialogObject.isDestroy) {
this._DialogObject.close()
this._DialogObject = null
}
this.tip && this.tip.destroy()
this.event && this.event.destroy()
await this.sdk.removeIncetance(this.options.id)
await syncData(this.sdk, this.options.id)
}
flicker() {}
}
export default Explosion