/** * @description 水面 */ import Dialog from '../../../Obj/Element/Dialog'; import { html } from "./_element"; import EventBinding from './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 } const now = new Date(); now.setHours(0, 0, 0, 0); // 设置为当天0点 this.options.time = options.time this.options.hour = options.hour 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点 let date if (that.options.time && that.options.hour) { date = new Date(that.options.time + " " + that.options.hour) } else { date = new Date(); date.setHours(0, 0, 0, 0); // 设置为当天0点 } that.viewer.clock.currentTime = Cesium.JulianDate.fromDate(date); that.viewer.clock.multiplier = that.options.speed; that.viewer.shadowMap.softShadows = that.options.softShadow; that.viewer.shadowMap.cascadesEnabled = true that.viewer.shadowMap.size = 2048; that.viewer.shadowMap.numberOfCascades = 4; // 增加级联层数(默认3层) that.viewer.shadowMap.maximumDistance = 5000; // 扩大阴影渲染距离 const lightCamera = that.viewer.shadowMap._lightCamera; lightCamera.frustum.near = 0.1; // 缩小近平面距离 lightCamera.frustum.far = 10000; // 扩大远平面距离 that.viewer.shadowMap.normalOffset = true; // 避免深度冲突导致的阴影闪烁 // 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 this._elms.darkness && this._elms.darkness.forEach(item => { item.value = v }) } get time() { return this.options.time } set time(v) { this.options.time = v const now = new Date(); let timeData = now.setHours(0, 0, 0, 0); // 设置为当天0点 this.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date(timeData)); // _that.timeLine.updateTime(timeData) } set timeBar(v) { let timeData = this.time + " " + v this.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date(timeData)); this.viewer.scene.requestRender(); } set realTime(v) { const now = new Date(); this.viewer.clock.currentTime = Cesium.JulianDate.fromDate(now); } get speed() { return this.options.speed } set speed(v) { this.options.speed = v this._elms.speed && this._elms.speed.forEach(item => { item.value = 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) { let _this = this // 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) // // this.remove() // // }, // resetCallBack: () => { // this.reset() // this.Dialog.resetCallBack && this.Dialog.resetCallBack() // }, // // removeCallBack: () => { // // this.Dialog.removeCallBack && this.Dialog.removeCallBack() // // }, // closeCallBack: () => { // this.reset() // _this.remove() // // 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 && this.timeLine.clear() this.viewer.shadowMap.cascadesEnabled = false this.viewer.shadowMap.size = 1024; this.viewer.shadowMap.numberOfCascades = 3; // 增加级联层数(默认3层) const lightCamera = this.viewer.shadowMap._lightCamera; this.viewer.shadowMap.normalOffset = false; // 避免深度冲突导致的阴影闪烁 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() { } }