From 2d90fa3dc99fced159d0bc76939fd9b88e6aafe1 Mon Sep 17 00:00:00 2001 From: wangyawei <1796609990@qq.com> Date: 星期五, 18 四月 2025 14:23:28 +0800 Subject: [PATCH] 接入视频流 --- src/utils/tools.js | 182 +++++++++++++++++++++++++++++++-------------- 1 files changed, 124 insertions(+), 58 deletions(-) diff --git a/src/utils/tools.js b/src/utils/tools.js index 9b23612..a56a9c7 100644 --- a/src/utils/tools.js +++ b/src/utils/tools.js @@ -2,6 +2,8 @@ // import cameraIcon from "../assets/images/base/瑙嗛娴嬬偣.png" // import cameraIconSel from "../assets/images/base/瑙嗛娴嬬偣sel.png" import { ElLoading, ElMessage } from "element-plus"; +import RainEffect from './rain' +import SnowEffect from './snow' let layerIsOpen = false; const Cesium = SmartEarth.Cesium; const colorAll = { @@ -19,88 +21,152 @@ analysisDXPMRes: [], slopeArrow: null, elevationTool: null, + rainEffect: null, + snowEffect: null, // 鏂板闆晥鏋滃疄渚� + regionTerrain: null, + polygonPosition: [], + PolygonArr: [], init(earthCtrl) { this.earthCtrl = earthCtrl; return this; }, - // 鍧″害鍒嗘瀽 - pdfx(option) { - this.elevationTool = new SmartEarth.ElevationTool(earthCtrl) - if (option.terrainRender == '1') { - this.elevationTool.type = 'slope' - } else { - this.elevationTool.type = 'none' - } - this.elevationTool.tf = option.contourLines - this.elevationTool.setSpacing(option.spacing) - this.elevationTool.setWidth(option.lineWidth) - this.elevationTool.setContourColor(option.color); - this.elevationTool.render(); - console.log(this.elevationTool, 'eleelelelelelelel') + hexToColor(hexColor) { + const hex = hexColor.replace('#', ''); + const r = parseInt(hex.substring(0, 2), 16) / 255; + const g = parseInt(hex.substring(2, 4), 16) / 255; + const b = parseInt(hex.substring(4, 6), 16) / 255; + return new Cesium.Color(r, g, b, 1.0); }, - // 鍧″悜绠ご - pxjt(colors, angles) { - this.slopeArrow = earthCtrl.factory.createSlopeArrow({}); - this.slopeArrow.setColorsAndAngles(colors, angles); + // 娓呴櫎澶╂皵鐗规晥 + delRain() { + if (this.rainEffect) { + this.rainEffect.destroy() + this.rainEffect = null + } + }, + delSnow() { + if (this.snowEffect) { + this.snowEffect.destroy(); + this.snowEffect = null; + } + }, + // 闆ㄥぉ妯℃嫙 + toggleRain(option, show) { + console.log(option, 'option') + // 鍏堥攢姣佹棫瀹炰緥 + if (this.rainEffect) { + this.rainEffect.destroy() + this.rainEffect = null + } + this.rainEffect = new RainEffect(earthCtrl.viewer, { + tiltAngle: -0.2, //鍊炬枩瑙掑害 + rainSize: option.rainSize, // 闆ㄧ殑澶у皬 + rainSpeed: option.rainSpeed, // 闆ㄧ殑閫熷害 + color: this.hexToColor(option.rainColor) // 闆ㄧ殑棰滆壊 + }) + }, + // 闆ぉ妯℃嫙 + toggleSnow(option = {}, show = true) { + console.log(option, 'option'); + const defaultOption = { + snowSize: 0.02, // 榛樿闆殑澶у皬 + snowSpeed: 100.0, // 榛樿闆殑閫熷害 + snowColor: "#ffffff", // 榛樿棰滆壊锛氱櫧鑹� + }; + option = { ...defaultOption, ...option }; + if (this.snowEffect) { + this.snowEffect.destroy(); + this.snowEffect = null; + } + this.snowEffect = new SnowEffect(earthCtrl.viewer, { + snowSize: option.snowSize, // 闆殑澶у皬 + snowSpeed: option.snowSpeed, // 闆殑閫熷害 + snowColor: this.hexToColor(option.snowColor), // 闆殑棰滆壊 + }); - // 鍒涘缓缁樺埗宸ュ叿 - const drawTool = earthCtrl.shapeTool.createDrawShapeTool((e) => { + // 鎺у埗鏄剧ず/闅愯棌 + if (this.snowEffect) { + this.snowEffect.show(show); + } + }, + // 鍖哄煙鍒掑垎宸ュ叿 + hfqy() { + this.regionTerrain = earthCtrl.factory.createRegionTerrain({}); + this.polygonPosition = []; + + const draw = earthCtrl.shapeTool.createDrawShapeTool((e) => { const polygonI = []; - const polygonPosition = []; for (const i of e.result) { const ellipsoid = earthCtrl.coreMap.scene.globe.ellipsoid; const cartographic = ellipsoid.cartesianToCartographic(i); - - const lon = Cesium.Math.toDegrees(cartographic.longitude); - const lat = Cesium.Math.toDegrees(cartographic.latitude); // 绾害 + const lon = SmartEarth.Cesium.Math.toDegrees( + cartographic.longitude + ); // 缁忓害 + const lat = SmartEarth.Cesium.Math.toDegrees(cartographic.latitude); // 绾害 polygonI.push(lon, lat, 0); - polygonPosition.push(lon, lat); + this.polygonPosition.push(lon, lat); } - const PolygonArr = []; - PolygonArr.push({ + this.PolygonArr.push({ id: earthCtrl.factory.createUUID(), polygon: polygonI, }); - - // 娓呴櫎缁樺埗宸ュ叿 - drawTool.removeFromMap(); - // 璁剧疆鍧″害绠ご鐨勪綅缃拰绫诲瀷 - this.slopeArrow.setPositions(polygonPosition); - this.slopeArrow.setSlopeType(1); - this.slopeArrow.setRegionEnabled(true); - console.log(this.slopeArrow,'slope') + draw.removeFromMap(); + this.regionTerrain.setPositions(this.polygonPosition); + this.regionTerrain.setRegionEnabled(true); }); }, - // 鍏抽棴鍧″悜绠ご - gbpxjt() { + // 鍧″害鍒嗘瀽 + pdfx() { + if (this.regionTerrain) { + console.log('鍧″害鍒嗘瀽'); + this.clearPreviousAnalysis(); // 鍏堟竻闄や箣鍓嶇殑鍒嗘瀽 + this.regionTerrain.setType("slope"); + this.regionTerrain.update(); + } + }, + + // 鍧″悜绠ご + pxjt(colors, angles) { + if (this.regionTerrain) { + this.clearPreviousAnalysis(); // 鍏堟竻闄や箣鍓嶇殑鍒嗘瀽 + this.regionTerrain.setType("aspect"); + this.regionTerrain.update(); + } + + this.slopeArrow = earthCtrl.factory.createSlopeArrow({}); + this.slopeArrow.setColorsAndAngles(colors, angles); + this.slopeArrow.setSlopeType(1); + }, + + // 绛夐珮绾垮垎鏋� + dgxfx(option) { + this.clearPreviousAnalysis(); // 鍏堟竻闄や箣鍓嶇殑鍒嗘瀽 + this.hfqy(); + this.elevationTool = new SmartEarth.ElevationTool(earthCtrl); + this.elevationTool.tf = option.contourLines; + this.elevationTool.setSpacing(option.spacing); + this.elevationTool.setWidth(option.lineWidth); + this.elevationTool.setContourColor(option.color); + this.elevationTool.render(); + }, + + // 娓呴櫎涔嬪墠鐨勫垎鏋愶紙鍧″害銆佸潯鍚戙�佺瓑楂樼嚎锛� + clearPreviousAnalysis() { + if (this.regionTerrain) { + this.regionTerrain.setType(""); + this.regionTerrain.update(); + } + if (this.slopeArrow) { this.slopeArrow.setSlopeType(0); + // this.slopeArrow = null; } - }, - // 澶╂皵 - toggleRain(weather = "rain", show) { - if (show) { - earthCtrl.environment.showEffect(weather); - } else { - earthCtrl.environment.disableEffect(weather); + if (this.elevationTool) { + this.elevationTool = null; } }, - toggleSnow(weather = "snow", show) { - if (show) { - earthCtrl.environment.showEffect(weather); - } else { - let snowValue = { - test1: 2, - test2: 1.0, - test3: 0.5, - test4: 0.5, - }; - earthCtrl.environment.disableEffect(weather); - } - }, - // 鏍囩粯 CreateLabel(pic, show) { if (show) { -- Gitblit v1.9.3