/** * @description 水面 */ import Dialog from '../../../Obj/Element/Dialog'; import { html } from "./_element"; import EventBinding from '../../../Obj/Element/Dialog/eventBinding'; import { syncData } from '../../MultiViewportMode' import Tools from '../../../Tools' import TimeLine from './TimeLine' import { setSplitDirection, syncSplitData, setActiveId } from '../../SplitScreen' export default class Sunshine { /** * @constructor * @param sdk * @description 光照 * @param options {object} 光照属性 * @param options.time=当前时间 {string} 当前时间 * @param options.speed=1000 {number} 速度倍速 * @param options.darkness=0.3 {number} 阴影不透明度--越大越不透明 * @param options.softShadow=false {boolean} 阴影优化--true/false} * @param Dialog {object} 弹框对象 * @param Dialog.confirmCallBack {function} 弹框确认时的回调 * */ constructor(sdk, options = {}, _Dialog = {}) { this.viewer = sdk.viewer this.options = { ...options } this.sdk = { ...sdk } this.options.time = options.time || new Date() this.options.speed = options.speed || 1000 this.options.darkness = options.darkness || 0.4 this.options.softShadow = options.softShadow || true this.options.show = options.show === true ? true : false this.Dialog = _Dialog this.timeLine this._EventBinding = new EventBinding() this._elms = {}; Sunshine.start(this) } static start(that) { that.viewer.scene.globe.enableLighting = true that.viewer.shadows = true that.viewer.scene.globe.enableLighting = true; that.viewer.terrainShadows = Cesium.ShadowMode.RECEIVE_ONLY that.viewer.shadowMap.darkness = 1.0 - that.options.darkness //阴影透明度--越大越透明 const now = new Date(); now.setHours(0, 0, 0, 0); // 设置为当天0点 that.viewer.clock.currentTime = Cesium.JulianDate.fromDate(now); that.viewer.clock.multiplier = that.options.speed; that.viewer.shadowMap.softShadows = that.options.softShadow; that.edit(true) } get darkness() { return this.options.darkness } set darkness(v) { this.options.darkness = v this.viewer.shadowMap.darkness = 1.0 - this.options.darkness } get speed() { return this.options.speed } set speed(v) { this.options.speed = v this.viewer.clock.multiplier = this.options.speed; this.timeLine.setSpeed(v) } get softShadow() { return this.options.softShadow } set softShadow(v) { this.options.softShadow = v this.viewer.shadowMap.softShadows = this.options.softShadow; } /** * @description 编辑框 * @param state=false {boolean} 状态: true打开, false关闭 */ async edit(state = false) { let tools = new Tools() this.originalOptions = tools.deepCopyObj(this.options) // let elms = this.sdk.viewer._container.getElementsByClassName('YJ-custom-base-dialog') // for (let i = elms.length - 1; i >= 0; i--) { // this.sdk.viewer._container.removeChild(elms[i]) // } if (this._DialogObject && this._DialogObject.close) { this._DialogObject.close() this._DialogObject = null } if (state) { this._DialogObject = await new Dialog(this.sdk, this.originalOptions, { title: '光照属性', left: '180px', top: '100px', confirmCallBack: (options) => { this.originalOptions = tools.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.entity.style = new Cesium.Cesium3DTileStyle({ // color: "color('rgba(255,255,255," + this.newData.transparency + ")')", // show: true, // }); this.Dialog.closeCallBack && this.Dialog.closeCallBack() }, showCallBack: (show) => { this.show = show this.Dialog.showCallBack && this.Dialog.showCallBack() } }, true) this._DialogObject._element.body.className = this._DialogObject._element.body.className + ' sun-shine-surface' let contentElm = document.createElement('div'); contentElm.innerHTML = html() this._DialogObject.contentAppChild(contentElm) //时间轴 let _that = this this.timeLine = new TimeLine(this.sdk, this.options.speed) // this.timeLine.setSpeed(1000) this.timeLine.moveComplay(item => { let timeData = _that.time + " " + item _that.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date(timeData)); _that.viewer.scene.requestRender(); }) let jeDateObject let printDateElm = contentElm.getElementsByClassName('sunshine-date')[0] let text jeDateObject = jeDate(printDateElm, { format: "YYYY-MM-DD", isinitVal: true, isClear: false, donefun: function (obj) { this.time = obj.val const now = new Date(); let timeData = now.setHours(0, 0, 0, 0); // 设置为当天0点 _that.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date(timeData)); _that.timeLine.updateTime(timeData) } }); if (this.time) { jeDateObject.setValue(this.time) } else { jeDateObject.nowBtn && jeDateObject.nowBtn() this.time = jeDateObject.getValue() } let all_elm = contentElm.getElementsByTagName("*") this._EventBinding.on(this, all_elm) this._elms = this._EventBinding.element this._elms.color = [jeDateObject] } else { // if (this._element_style) { // document.getElementsByTagName('head')[0].removeChild(this._element_style) // this._element_style = null // } // if (this._DialogObject && this._DialogObject.remove) { // this._DialogObject.remove() // this._DialogObject = null // } } } reset() { if (!this.viewer.entities.getById(this.options.id)) { return } this.time = this.originalOptions.time this.speed = this.originalOptions.speed this.darkness = this.originalOptions.darkness } /** * 飞到对应实体 */ async flyTo(options = {}) { } /** * 删除 */ async remove() { this.viewer.scene.globe.enableLighting = false this.viewer.shadows = false this.viewer.clock.multiplier = 1.0 this.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date()); this.entity = null this.timeLine.clear() if (this._DialogObject && !this._DialogObject.isDestroy) { this._DialogObject.close() this._DialogObject = null } // await this.sdk.removeIncetance(this.options.id) await syncData(this.sdk, this.options.id) } flicker() { } }