From 4f57ac3d9e7183a0a8bfbbf28610562d91976509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Thu, 21 Aug 2025 16:03:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E8=B6=85=E5=87=BA=E6=9C=80=E5=A4=A7=E5=80=BC=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=92=8C=E8=BF=9B=E5=BA=A6=E6=9D=A1=E4=BF=AE=E6=94=B9=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=E4=BC=9A=E8=B7=B3=E8=B7=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Global/efflect/Sunshine/index.js | 4 +++ src/Global/efflect/Sunshine/timeLIne.js | 39 ++++++++++++------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Global/efflect/Sunshine/index.js b/src/Global/efflect/Sunshine/index.js index f1b1a59..12119d5 100644 --- a/src/Global/efflect/Sunshine/index.js +++ b/src/Global/efflect/Sunshine/index.js @@ -80,6 +80,10 @@ export default class Sunshine { } 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) } diff --git a/src/Global/efflect/Sunshine/timeLIne.js b/src/Global/efflect/Sunshine/timeLIne.js index f6155e9..d7deb47 100644 --- a/src/Global/efflect/Sunshine/timeLIne.js +++ b/src/Global/efflect/Sunshine/timeLIne.js @@ -9,7 +9,7 @@ export default class TimeLine { this.timelineCon = document.getElementsByClassName('timeline-container')[0]; this.speed = speed; this.animationId; - this.startTime = Date.now(); + this.startTime = performance.now(); this.manualPosition = null; this.isDragging = false; this.pauseed = false; @@ -28,9 +28,7 @@ export default class TimeLine { document.getElementsByClassName('time-marks')[0].appendChild(label) } } - - - that.startTime = Date.now() - ((that.manualPosition || 0) * 86400 * 1000 / that.speed); + that.startTime = performance.now() - ((that.manualPosition || 0) * 86400 * 1000 / that.speed); that.timeline.addEventListener('mousedown', (e) => { if (e.srcElement.className === 'handle') { @@ -57,21 +55,22 @@ export default class TimeLine { document.getElementById('timePause').addEventListener('click', function () { that.pauseed = !that.pauseed; if (that.pauseed) {//暂停 + that.pausedTime = performance.now(); // 记录暂停时刻 document.getElementById('timePause').textContent = '播放'; that.animationId && cancelAnimationFrame(that.animationId); - that.pausedTime = Date.now(); // 记录暂停时刻 that.sdk.viewer.clock.shouldAnimate = false } else {//播放 + let now = performance.now() + const pausedDuration = now - that.pausedTime; document.getElementById('timePause').textContent = '暂停'; that.manualPosition = null - const pausedDuration = Date.now() - that.pausedTime; that.startTime += pausedDuration; // 补偿暂停期间的时间差 if (that.changeDate) {//切换日期后让时间从0开始 if (that.changeDateGrag) { that.changeDateGrag = undefined } else { - that.startTime = Date.now() + that.startTime = now } that.changeDate = undefined } @@ -88,14 +87,14 @@ export default class TimeLine { that.isDragging = false; if (that.manualPosition !== null) { // that.sdk.viewer.clock.shouldAnimate = true - that.startTime = Date.now() - (that.manualPosition * 86400 * 1000 / that.speed); + that.startTime = performance.now() - (that.manualPosition * 86400 * 1000 / that.speed); that.manualPosition = null; that.changeDate && (that.changeDateGrag = true) if (!that.pauseed) { that.update() func(that.time) } else { - that.pausedTime = Date.now(); // 记录暂停时刻 + that.pausedTime = performance.now(); // 记录暂停时刻 func(that.currentTime.textContent) } @@ -113,9 +112,9 @@ export default class TimeLine { update() { if (this.manualPosition !== null) return; if (this.changeDate) {//切换日期后让时间从0开始 - this.startTime = Date.now() + this.startTime = performance.now() } - let elapsed = (Date.now() - this.startTime) * this.speed; + let elapsed = (performance.now() - this.startTime) * this.speed; // if (this.elapsed) { // elapsed = elapsed + this.elapsed // this.elapsed = undefined @@ -133,23 +132,23 @@ export default class TimeLine { } } setSpeed(v) { + let now = performance.now() if (!this.pauseed) { const currentProgress = this.manualPosition ?? - (Date.now() - this.startTime) * this.speed / (86400 * 1000); + (performance.now() - this.startTime) * this.speed / (86400 * 1000); this.speed = v; - this.startTime = Date.now() - (currentProgress * 86400 * 1000 / this.speed); + this.startTime = performance.now() - (currentProgress * 86400 * 1000 / this.speed); } else { - let pausedDuration = Date.now() - this.pausedTime; + let pausedDuration = now - this.pausedTime; this.startTime += pausedDuration; // 补偿暂停期间的时间差 - const currentProgress = this.manualPosition ?? - (Date.now() - this.startTime) * this.speed / (86400 * 1000); + (now - this.startTime) * this.speed / (86400 * 1000); this.speed = v; - this.startTime = Date.now() - (currentProgress * 86400 * 1000 / this.speed); + this.startTime = now - (currentProgress * 86400 * 1000 / this.speed); - this.pausedTime = Date.now(); // 记录切换speed暂停时刻 - this.speed = v; + this.pausedTime = now; // 记录切换speed暂停时刻 + // this.speed = v; } this.manualPosition = null; @@ -158,7 +157,7 @@ export default class TimeLine { } updateTime() { this.manualPosition = null; - this.startTime = Date.now() - ((this.manualPosition || 0) * 86400 * 1000 / this.speed); + this.startTime = performance.now() - ((this.manualPosition || 0) * 86400 * 1000 / this.speed); this.pauseed && (this.changeDate = true) this.changeDateGrag = undefined this.update();