Merge branch 'develop' of http://xny.yj-3d.com:3000/zh/sdk4.0
This commit is contained in:
56
src/Global/efflect/Sunshine/_element.js
Normal file
56
src/Global/efflect/Sunshine/_element.js
Normal file
@ -0,0 +1,56 @@
|
||||
function html() {
|
||||
return `
|
||||
<span class="custom-divider"></span>
|
||||
<div class="div-item">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<span class="label">播放倍数</span>
|
||||
<div class="input-number input-number-unit-1">
|
||||
<input class="input" type="number" title="" min="0.01" max="999999" step="10" @model="speed">
|
||||
<span class="arrow"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<span class="label">阴影柔和度</span>
|
||||
<div class="input-number input-number-unit-1">
|
||||
<input class="input" type="number" title="" min="0" max="1" step="0.1" @model="darkness">
|
||||
<span class="arrow"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="div-item">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<span class="label">阴影优化</span>
|
||||
<input class="btn-switch" type="checkbox" @model="softShadow">
|
||||
</div>
|
||||
<div class="col">
|
||||
<span class="label" style="flex: 0 0 56px;">日期选择</span>
|
||||
<input class="sunshine-date" type="text" placeholder="YYYY-MM-DD" @model="time">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="custom-divider"></span>
|
||||
<div class="div-item">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="timeline-container">
|
||||
<div class="timeline" id="timeline">
|
||||
<div class="progress" id="progress">
|
||||
<div class="handle" id="handle"></div>
|
||||
<div class="current-time" id="currentTime">00:00:00</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="time-marks">
|
||||
</div>
|
||||
<button id="timePause">暂停</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="custom-divider"></span>
|
||||
`
|
||||
}
|
||||
|
||||
export { html }
|
92
src/Global/efflect/Sunshine/eventBinding.js
Normal file
92
src/Global/efflect/Sunshine/eventBinding.js
Normal file
@ -0,0 +1,92 @@
|
||||
class eventBinding {
|
||||
constructor() {
|
||||
this.element = {}
|
||||
}
|
||||
static event = {}
|
||||
|
||||
getEvent(name) {
|
||||
return eventBinding.event[name]
|
||||
}
|
||||
|
||||
getEventAll() {
|
||||
return eventBinding.event
|
||||
}
|
||||
|
||||
setEvent(name, event) {
|
||||
eventBinding.event[name] = event
|
||||
}
|
||||
|
||||
on(that, elements) {
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
let Event = []
|
||||
let isEvent = false
|
||||
let removeName = []
|
||||
if (!elements[i] || !elements[i].attributes) {
|
||||
continue;
|
||||
}
|
||||
for (let m of elements[i].attributes) {
|
||||
switch (m.name) {
|
||||
case '@model': {
|
||||
isEvent = true
|
||||
if (elements[i].type == 'checkbox') {
|
||||
Event.push((e) => { that[m.value] = e.target.checked })
|
||||
elements[i].checked = that[m.value]
|
||||
}
|
||||
else {
|
||||
Event.push((e) => {
|
||||
let value = e.target.value
|
||||
if (e.target.type == 'number') {
|
||||
value = Number(value)
|
||||
}
|
||||
that[m.value] = value
|
||||
})
|
||||
if (elements[i].nodeName == 'IMG') {
|
||||
elements[i].src = that[m.value]
|
||||
}
|
||||
else {
|
||||
elements[i].value = that[m.value]
|
||||
}
|
||||
}
|
||||
if (this.element[m.value]) {
|
||||
this.element[m.value].push(elements[i])
|
||||
}
|
||||
else {
|
||||
this.element[m.value] = [elements[i]]
|
||||
}
|
||||
removeName.push(m.name)
|
||||
break;
|
||||
}
|
||||
case '@click': {
|
||||
elements[i].addEventListener('click', (e) => {
|
||||
if (typeof (that.Dialog[m.value]) === 'function') {
|
||||
that.Dialog[m.value](e)
|
||||
}
|
||||
});
|
||||
removeName.push(m.name)
|
||||
// elements[i].attributes.removeNamedItem(m.name)
|
||||
break;
|
||||
}
|
||||
}
|
||||
// elements[i].attributes[m] = undefined
|
||||
}
|
||||
for (let n = 0; n < removeName.length; n++) {
|
||||
elements[i].attributes.removeNamedItem(removeName[n])
|
||||
}
|
||||
|
||||
if (isEvent) {
|
||||
let ventType = 'input'
|
||||
if (elements[i].tagName != 'INPUT' || elements[i].type == 'checkbox') {
|
||||
ventType = 'change'
|
||||
}
|
||||
elements[i].addEventListener(ventType, (e) => {
|
||||
for (let t = 0; t < Event.length; t++) {
|
||||
Event[t](e)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const EventBinding = new eventBinding();
|
||||
export default EventBinding;
|
224
src/Global/efflect/Sunshine/index.js
Normal file
224
src/Global/efflect/Sunshine/index.js
Normal file
@ -0,0 +1,224 @@
|
||||
/**
|
||||
* @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() { }
|
||||
}
|
||||
|
133
src/Global/efflect/Sunshine/timeLIne.js
Normal file
133
src/Global/efflect/Sunshine/timeLIne.js
Normal file
@ -0,0 +1,133 @@
|
||||
export default class TimeLine {
|
||||
constructor(sdk, speed) {
|
||||
this.sdk = { ...sdk };
|
||||
this.progress = document.getElementById('progress');
|
||||
this.handle = document.getElementById('handle');
|
||||
this.timeline = document.getElementById('timeline');
|
||||
this.currentTime = document.getElementById('currentTime');
|
||||
this.timelineCon = document.getElementsByClassName('timeline-container')[0];
|
||||
this.speed = speed;
|
||||
this.animationId;
|
||||
this.startTime = Date.now();
|
||||
this.manualPosition = null;
|
||||
this.isDragging = false;
|
||||
this.pauseed = false;
|
||||
this.time = '';
|
||||
this.update = this.update.bind(this);
|
||||
|
||||
TimeLine.init(this)
|
||||
}
|
||||
static init(that) {
|
||||
for (let i = 0; i <= 24; i++) {
|
||||
if (i % 6 === 0) {
|
||||
const label = document.createElement('div');
|
||||
label.className = 'time-mark';
|
||||
label.textContent = `${i}:00`;
|
||||
label.style.left = `${(i / 24) * 100}%`;
|
||||
document.getElementsByClassName('time-marks')[0].appendChild(label)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
that.startTime = Date.now() - ((that.manualPosition || 0) * 86400 * 1000 / that.speed);
|
||||
|
||||
that.timeline.addEventListener('mousedown', (e) => {
|
||||
that.isDragging = true;
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
that.timeline.addEventListener('mousemove', (e) => {
|
||||
if (!that.isDragging) return;
|
||||
|
||||
const rect = that.timeline.getBoundingClientRect();
|
||||
let pos = (e.clientX - rect.left) / rect.width;
|
||||
pos = Math.max(0, Math.min(1, pos));
|
||||
|
||||
that.manualPosition = pos;
|
||||
that.progress.style.width = `${pos * 100}%`;
|
||||
|
||||
const seconds = pos * 86400;
|
||||
that.currentTime.textContent = that.formatTime(seconds);
|
||||
});
|
||||
that.update();
|
||||
|
||||
document.getElementById('timePause').addEventListener('click', function () {
|
||||
that.pauseed = !that.pauseed;
|
||||
if (that.pauseed) {
|
||||
document.getElementById('timePause').textContent = '播放';
|
||||
that.animationId && cancelAnimationFrame(that.animationId);
|
||||
that.pausedTime = Date.now(); // 记录暂停时刻
|
||||
that.sdk.viewer.clock.shouldAnimate = false
|
||||
} else {
|
||||
document.getElementById('timePause').textContent = '暂停';
|
||||
that.manualPosition = null
|
||||
|
||||
const pausedDuration = Date.now() - that.pausedTime;
|
||||
that.startTime += pausedDuration; // 补偿暂停期间的时间差
|
||||
that.sdk.viewer.clock.shouldAnimate = true
|
||||
that.update(); // 重启动画循环
|
||||
}
|
||||
});
|
||||
}
|
||||
moveComplay(func) {
|
||||
let that = this
|
||||
that.timeline.addEventListener('mouseup', () => {
|
||||
that.isDragging = false;
|
||||
if (that.manualPosition !== null) {
|
||||
// that.sdk.viewer.clock.shouldAnimate = true
|
||||
that.startTime = Date.now() - (that.manualPosition * 86400 * 1000 / that.speed);
|
||||
that.manualPosition = null;
|
||||
|
||||
if (!that.pauseed) {
|
||||
that.update()
|
||||
func(that.time)
|
||||
} else {
|
||||
that.pausedTime = Date.now(); // 记录暂停时刻
|
||||
func(that.currentTime.textContent)
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
formatTime(seconds) {
|
||||
const hrs = Math.floor(seconds / 3600).toString().padStart(2, '0');
|
||||
const mins = Math.floor((seconds % 3600) / 60).toString().padStart(2, '0');
|
||||
const secs = Math.floor(seconds % 60).toString().padStart(2, '0');
|
||||
return `${hrs}:${mins}:${secs}`;
|
||||
}
|
||||
|
||||
update() {
|
||||
if (this.manualPosition !== null) return;
|
||||
|
||||
const elapsed = (Date.now() - this.startTime) * this.speed;
|
||||
const totalSeconds = elapsed / 1000;
|
||||
const daySeconds = totalSeconds % 86400;
|
||||
const percentage = daySeconds / 86400;
|
||||
|
||||
this.progress.style.width = `${percentage * 100}%`;
|
||||
this.time = this.formatTime(daySeconds)
|
||||
this.currentTime.textContent = this.time;
|
||||
this.animationId = requestAnimationFrame(this.update);
|
||||
}
|
||||
setSpeed(v) {
|
||||
const currentProgress = this.manualPosition ??
|
||||
(Date.now() - this.startTime) * this.speed / (86400 * 1000);
|
||||
|
||||
this.speed = v;
|
||||
this.startTime = Date.now() - (currentProgress * 86400 * 1000 / this.speed);
|
||||
this.manualPosition = null;
|
||||
this.update();
|
||||
|
||||
}
|
||||
updateTime() {
|
||||
this.startTime = Date.now() - (this.manualPosition * 86400 * 1000 / this.speed);
|
||||
this.manualPosition = null;
|
||||
this.update();
|
||||
}
|
||||
clear() {
|
||||
this.animationId && cancelAnimationFrame(this.animationId);
|
||||
this.progress.style.width = '0%';
|
||||
this.currentTime.textContent = '00:00:00';
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user