const mapPlan = { planListData: null, planStart: false, planIndex: null, planStopTime: null, planTimeOut: null, startTime: null, stopTime: null, Init(res) { if (!res.children || res.children == 0) return; if (this.planStart) { this.closed(); } this.planIndex = 0; this.planListData = res.children; this.planStart = true; this.setPlanFlyStart(); this.startTime = this.formatDate(); }, closed() { this.planStart = false; if (this.planTimeOut) { clearTimeout(this.planTimeOut); this.planTimeOut = null; } this.planIndex = 0; this.planListData = null; this.stopTime = this.formatDate(); console.log("开始时间: " + this.startTime + "结束时间: " + this.stopTime); }, setPlanFlyStart() { const obj = this.planListData[this.planIndex]; this.planStopTime = obj.time; if (this.planTimeOut) { clearTimeout(this.planTimeOut); this.planTimeOut = null; } const that = this; try { earthCtrl.camera.flyTo( obj.lon, obj.lat, obj.alt, obj.height, obj.pitch, obj.roll, null, () => { this.setPlanFlyNext(); } ); } catch (e) { if (window.widget._showRenderLoopErrors) { var title = "开始时间: " + this.startTime + "结束时间: " + this.formatDate(); window.widget.showErrorPanel(title, undefined, e); } } }, setPlanFlyNext() { this.planIndex++; const time = this.planStopTime * 1000; this.planIndex = this.planIndex == this.planListData.length ? 0 : this.planIndex; if (this.planStart == true) { var that = this; this.planTimeOut = setTimeout(() => { that.setPlanFlyStart(); }, time); } }, formatDate(time) { //时间戳转日期 let date = new Date(); let y = date.getFullYear(); let MM = date.getMonth() + 1; MM = MM < 10 ? "0" + MM : MM; let d = date.getDate(); d = d < 10 ? "0" + d : d; let h = date.getHours(); h = h < 10 ? "0" + h : h; let m = date.getMinutes(); m = m < 10 ? "0" + m : m; let s = date.getSeconds(); s = s < 10 ? "0" + s : s; return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s; } }; export default mapPlan;