548 lines
15 KiB
JavaScript
548 lines
15 KiB
JavaScript
/**
|
||
* @name: index
|
||
* @author: Administrator
|
||
* @date: 2023-12-01 12:12
|
||
* @description:index
|
||
* @update: 2023-12-01 12:12
|
||
*/
|
||
import Tools from "../../Tools";
|
||
import { getHost, getToken } from "../../on";
|
||
import { regLeftClickCallback, regRightClickCallback, regMoveCallback } from "../../Global/ClickCallback";
|
||
import { regLeftClickCallback as regLeftClickCallback2, regRightClickCallback as regRightClickCallback2, regMoveCallback as regMoveCallback2 } from "../../Global/SplitScreen/ClickCallback";
|
||
import { regLeftClickCallback as regLeftClickCallback3, regRightClickCallback as regRightClickCallback3, regMoveCallback as regMoveCallback3 } from "../../Global/MultiViewportMode/ClickCallback";
|
||
import { setSplitDirection, syncSplitData, getSdk } from "../../Global/SplitScreen";
|
||
import { syncData, getSdk as get2DSdk } from '../../Global/MultiViewportMode'
|
||
import { setActiveViewer, closeRotateAround, closeViewFollow } from '../../Global/global'
|
||
|
||
class Base extends Tools {
|
||
#_showView
|
||
#_isShowView
|
||
constructor(sdk, options = {}) {
|
||
super(sdk, options);
|
||
if (!sdk || !sdk.viewer) {
|
||
return
|
||
}
|
||
// this._splitDirection = -1
|
||
this.sdk = sdk
|
||
this.viewer = sdk.viewer
|
||
this.options = { ...options }
|
||
this.options.id = options.id || this.randomString()
|
||
this.entity = null
|
||
this.clickCallBack = null
|
||
this.rightClickCallBack = null
|
||
this.picking = true
|
||
this.options.host = this.options.host || getHost()
|
||
// this.#_showView = this.options.showView || 0
|
||
this.setDefaultValue()
|
||
|
||
// this.sdk.addIncetance(this.options.id, this)
|
||
}
|
||
|
||
// get splitDirection() {
|
||
// return this._splitDirection
|
||
// }
|
||
|
||
// set splitDirection(v) {
|
||
// switch (v) {
|
||
// case 1:
|
||
// case '1':
|
||
// this._splitDirection = 1
|
||
// break
|
||
// case -1:
|
||
// case '-1':
|
||
// this._splitDirection = -1
|
||
// break
|
||
// default:
|
||
// this._splitDirection = 0
|
||
// break
|
||
// }
|
||
// setSplitDirection(this._splitDirection, this.options.id)
|
||
// }
|
||
|
||
get showView() {
|
||
return this.#_showView
|
||
}
|
||
|
||
set showView(v) {
|
||
|
||
|
||
let sdk2D = get2DSdk().sdkD
|
||
if (!sdk2D) {
|
||
this.#_showView = v
|
||
if (this.entity) {
|
||
this.entity._showView = v
|
||
}
|
||
return
|
||
}
|
||
if (this.sdk === sdk2D) {
|
||
this.#_showView = 0
|
||
return
|
||
}
|
||
if (!this.#_showView && !this.show) {
|
||
return
|
||
}
|
||
if (this.sdk === sdk2D) {
|
||
this.#_showView = 0
|
||
return
|
||
}
|
||
if (v != 2 && v != 3) {
|
||
this.#_showView = 0
|
||
}
|
||
else {
|
||
this.#_showView = v
|
||
}
|
||
|
||
this.isShowView = true
|
||
|
||
// if(!this.show) {
|
||
// return
|
||
// }
|
||
|
||
if (!this.#_showView) {
|
||
this.show = true
|
||
}
|
||
else {
|
||
if (v == 2) {
|
||
this.show = false
|
||
}
|
||
else {
|
||
this.show = true
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
get name() {
|
||
return this.options.name
|
||
}
|
||
set name(v) {
|
||
this.options.name = v
|
||
this.label && (this.label.text = v)
|
||
this._elms.name && this._elms.name.forEach((item) => {
|
||
item.value = v
|
||
})
|
||
}
|
||
|
||
get show() {
|
||
return this.options.show
|
||
}
|
||
|
||
set show(v) {
|
||
if (typeof v === "boolean") {
|
||
let sdkD = get2DSdk().sdkD
|
||
if (!this.isShowView || !sdkD) {
|
||
this.options.show = v
|
||
if (this.originalOptions) {
|
||
this.originalOptions.show = v
|
||
}
|
||
}
|
||
this.entity._showView = this.showView
|
||
if (this.type == 'layer') {
|
||
if (this.entity) {
|
||
this.entity._objectState = this.options.show
|
||
}
|
||
}
|
||
if (!this.showView || this.showView == 3 || !sdkD) {
|
||
this.entity && (this.entity.show = this.options.show)
|
||
if (this.options.label && this.options.label.show && this.label) {
|
||
this.label.show = this.options.show
|
||
}
|
||
}
|
||
else {
|
||
this.entity && (this.entity.show = false)
|
||
if (this.options.label && this.options.label.show && this.label) {
|
||
this.label.show = false
|
||
}
|
||
}
|
||
|
||
if (this._DialogObject && this._DialogObject.showBtn) {
|
||
this._DialogObject.showBtn.checked = this.options.show
|
||
}
|
||
|
||
|
||
syncData(this.sdk, this.options.id)
|
||
syncSplitData(this.sdk, this.options.id)
|
||
this.isShowView = false
|
||
|
||
if (this.type == 'layer' && sdkD) {
|
||
let layer2d = sdkD.viewer.imageryLayers._layers[this.layerIndex]
|
||
let layer3d = this.entity
|
||
|
||
if (!layer2d) {
|
||
return
|
||
}
|
||
if (layer3d._objectState) {
|
||
if (!layer3d._showView || layer3d._showView == 2) {
|
||
layer2d.show = true
|
||
}
|
||
if (layer3d._showView == 3) {
|
||
layer2d.show = false
|
||
}
|
||
}
|
||
else {
|
||
layer2d.show = this.options.show
|
||
}
|
||
}
|
||
} else {
|
||
console.error("参数必须为boolean")
|
||
}
|
||
}
|
||
|
||
get attributeSelect() {
|
||
return [
|
||
{
|
||
name: '富文本',
|
||
value: '富文本',
|
||
key: 'richText'
|
||
},
|
||
{
|
||
name: '链接',
|
||
value: '链接',
|
||
key: 'link'
|
||
},
|
||
// {
|
||
// name: 'IP摄像头',
|
||
// value: 'IP摄像头',
|
||
// key: 'camera'
|
||
// },
|
||
// {
|
||
// name: 'ISC摄像头',
|
||
// value: 'ISC摄像头',
|
||
// key: 'isc'
|
||
// },
|
||
// {
|
||
// name: '传感器',
|
||
// value: '传感器',
|
||
// key: 'sensor'
|
||
// },
|
||
// {
|
||
// name: '全景图',
|
||
// value: '全景图',
|
||
// key: 'vr'
|
||
// },
|
||
// {
|
||
// name: '物资',
|
||
// value: '物资',
|
||
// key: 'goods'
|
||
// },
|
||
]
|
||
}
|
||
|
||
display() {
|
||
this.show = true
|
||
}
|
||
|
||
hide() {
|
||
this.show = false
|
||
}
|
||
|
||
/**
|
||
* 闪烁
|
||
* @param {number} times 闪烁一次所需时间
|
||
* @param {number} number 闪烁次数
|
||
*/
|
||
flicker(times = 500, number) {
|
||
if (this.flickerAnimate) {
|
||
TWEEN.remove(this.flickerAnimate)
|
||
}
|
||
this.flickerAnimate = new TWEEN.Tween({ degree: 1 }).to({ degree: 0 }, times / 2).easing(TWEEN.Easing.Linear.None).repeat((number || number === 0) ? (number * 2) - 1 : Infinity).yoyo(true).onUpdate(async (r, a) => {
|
||
// this.entity.billboard.color = Cesium.Color.fromCssColorString(`rgba(255,255,255,${r.degree})`)
|
||
if (!this.sdk.viewer) {
|
||
TWEEN.remove(this.flickerAnimate)
|
||
return
|
||
}
|
||
if (this.show) {
|
||
if (r.degree === 1) {
|
||
this.entity && (this.entity.show = true)
|
||
this.labelShow && this.label && (this.label.show = true)
|
||
this.text && this.text && (this.text.show = true)
|
||
}
|
||
if (r.degree === 0) {
|
||
this.entity && (this.entity.show = false)
|
||
this.labelShow && this.label && (this.label.show = false)
|
||
this.text && this.text && (this.text.show = false)
|
||
}
|
||
}
|
||
}).onComplete((d) => {
|
||
TWEEN.remove(this.flickerAnimate)
|
||
this.flickerAnimate = undefined
|
||
}).start()
|
||
}
|
||
|
||
async flyTo(options = {}) {
|
||
if (this._error) {
|
||
return
|
||
}
|
||
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 && Object.prototype.toString.call(this.options.position) === '[object Object]') {
|
||
position = { ...this.options.position }
|
||
}
|
||
else if (this.options.positions) {
|
||
position = { ...this.options.positions[0] }
|
||
}
|
||
else if (this.options.line && this.options.line.positions) {
|
||
position = { ...this.options.line.positions[0] }
|
||
}
|
||
else if (this.options.center) {
|
||
position = { ...this.options.center }
|
||
}
|
||
else if (this.options.start) {
|
||
position = { ...this.options.start }
|
||
}
|
||
else if (this.geojson) {
|
||
let range = turf.bbox(this.geojson);
|
||
position = { lng: range[0], lat: range[1] }
|
||
}
|
||
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.flyTo(this.entity, {
|
||
offset: options.orientation || {
|
||
heading: Cesium.Math.toRadians(0.0),
|
||
pitch: Cesium.Math.toRadians(-60.0),
|
||
roll: Cesium.Math.toRadians(0.0)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
async remove() {
|
||
await this.sdk.removeIncetance(this.options.id)
|
||
this.event && this.event.destroy()
|
||
this.tip && this.tip.destroy()
|
||
syncData(this.sdk, this.options.id)
|
||
syncSplitData(this.sdk, this.options.id)
|
||
}
|
||
|
||
get onClick() {
|
||
return this.clickCallBack
|
||
}
|
||
|
||
set onClick(val) {
|
||
if (val && typeof val !== 'function') {
|
||
console.error('val:', val, '不是一个function')
|
||
} else {
|
||
let sdkD = getSdk().sdkD
|
||
let sdk2D = get2DSdk().sdkD
|
||
if (sdkD && this.sdk === sdkD) {
|
||
if (this.clickCallBack == null && this.options && this.options.id) {
|
||
regLeftClickCallback2(this.options.id, this.leftClickCB, this)
|
||
}
|
||
}
|
||
else if (sdk2D && this.sdk === sdk2D) {
|
||
if (this.clickCallBack == null && this.options && this.options.id) {
|
||
regLeftClickCallback3(this.options.id, this.leftClickCB, this)
|
||
}
|
||
} else {
|
||
if (this.clickCallBack == null && this.options && this.options.id) {
|
||
regLeftClickCallback(this.options.id, this.leftClickCB, this)
|
||
}
|
||
}
|
||
this.clickCallBack = val
|
||
}
|
||
}
|
||
|
||
get onRightClick() {
|
||
return this.rightClickCallBack
|
||
}
|
||
|
||
set onRightClick(val) {
|
||
if (val && typeof val !== 'function') {
|
||
console.error('val:', val, '不是一个function')
|
||
} else {
|
||
let sdkD = getSdk().sdkD
|
||
let sdk2D = get2DSdk().sdkD
|
||
if (sdkD && this.sdk === sdkD) {
|
||
if (this.rightClickCallBack == null && this.entity && this.entity.id) {
|
||
regRightClickCallback2(this.entity.id, this.rightClickCB, this)
|
||
}
|
||
}
|
||
else if (sdk2D && this.sdk === sdk2D) {
|
||
if (this.clickCallBack == null && this.options && this.options.id) {
|
||
regRightClickCallback3(this.options.id, this.leftClickCB, this)
|
||
}
|
||
} else {
|
||
if (this.rightClickCallBack == null && this.entity && this.entity.id) {
|
||
regRightClickCallback(this.entity.id, this.rightClickCB, this)
|
||
}
|
||
}
|
||
this.rightClickCallBack = val
|
||
}
|
||
}
|
||
|
||
get onMouseMove() {
|
||
return this.mouseMoveCallBack
|
||
}
|
||
|
||
set onMouseMove(val) {
|
||
if (val && typeof val !== 'function') {
|
||
console.error('val:', val, '不是一个function')
|
||
} else {
|
||
let sdkD = getSdk().sdkD
|
||
let sdk2D = get2DSdk().sdkD
|
||
if (sdkD && this.sdk === sdkD) {
|
||
if (this.mouseMoveCallBack == null && this.entity && this.entity.id) {
|
||
regMoveCallback2(this.entity.id, this.mouseMoveCB, this)
|
||
}
|
||
}
|
||
else if (sdk2D && this.sdk === sdk2D) {
|
||
if (this.clickCallBack == null && this.options && this.options.id) {
|
||
regMoveCallback3(this.options.id, this.leftClickCB, this)
|
||
}
|
||
} else {
|
||
if (this.mouseMoveCallBack == null && this.entity && this.entity.id) {
|
||
regMoveCallback(this.entity.id, this.mouseMoveCB, this)
|
||
}
|
||
}
|
||
this.mouseMoveCallBack = val
|
||
}
|
||
}
|
||
|
||
get customView() {
|
||
return this.options.customView
|
||
}
|
||
|
||
// 设置视角
|
||
async setCustomView(val) {
|
||
if (val) {
|
||
this.options.customView = val
|
||
}
|
||
else {
|
||
let camera = this.sdk.viewer.camera
|
||
let cameraPosition84 = this.cartesian3Towgs84(camera.position, this.sdk.viewer)
|
||
|
||
let position = { lng: 0, lat: 0 }
|
||
let relativePosition = { ...cameraPosition84 }
|
||
if (this.options.position && Object.prototype.toString.call(this.options.position) === '[object Object]') {
|
||
position = { ...this.options.position }
|
||
}
|
||
else if (this.options.positions) {
|
||
position = { ...this.options.positions[0] }
|
||
}
|
||
else if (this.options.line && this.options.line.positions) {
|
||
position = { ...this.options.line.positions[0] }
|
||
}
|
||
else if (this.options.center) {
|
||
position = { ...this.options.center }
|
||
}
|
||
else if (this.options.start) {
|
||
position = { ...this.options.start }
|
||
}
|
||
else if (this.geojson) {
|
||
let range = turf.bbox(this.geojson);
|
||
position = { lng: range[0], lat: range[1] }
|
||
}
|
||
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)
|
||
}
|
||
relativePosition = {
|
||
lng: cameraPosition84.lng - position.lng,
|
||
lat: cameraPosition84.lat - position.lat,
|
||
alt: cameraPosition84.alt - position.alt
|
||
}
|
||
|
||
this.options.customView = {
|
||
orientation: { heading: Cesium.Math.toDegrees(camera.heading), pitch: Cesium.Math.toDegrees(camera.pitch), roll: Cesium.Math.toDegrees(camera.roll) },
|
||
relativePosition: relativePosition
|
||
}
|
||
this.originalOptions && (this.originalOptions.customView = this.options.customView)
|
||
}
|
||
}
|
||
|
||
// 重置视角
|
||
resetCustomView() {
|
||
this.options.customView = undefined
|
||
}
|
||
|
||
|
||
//每个节点的编辑页面
|
||
edit() {
|
||
|
||
}
|
||
|
||
leftClickCB(mo, id, p, that) {
|
||
if (that.clickCallBack && typeof that.clickCallBack === 'function') {
|
||
that.clickCallBack(mo, id, p)
|
||
}
|
||
}
|
||
|
||
rightClickCB(mo, id, p, that) {
|
||
if (that.rightClickCallBack && typeof that.rightClickCallBack === 'function') {
|
||
that.rightClickCallBack(mo, id, p)
|
||
}
|
||
}
|
||
|
||
mouseMoveCB(mo, id, p, that) {
|
||
if (that.mouseMoveCallBack && typeof that.mouseMoveCallBack === 'function') {
|
||
that.mouseMoveCallBack(mo, id, p)
|
||
}
|
||
}
|
||
|
||
getGuid() {
|
||
return Cesium.createGuid()
|
||
}
|
||
|
||
setDefaultValue() {
|
||
this.options.id = this.options.id ?? this.getGuid()
|
||
this.options.show = this.options.show ?? true
|
||
this.options.name = this.options.name ?? "未命名对象"
|
||
}
|
||
|
||
start() { }
|
||
|
||
end() { }
|
||
}
|
||
|
||
export default Base
|