From b498685e9c29c9c4b56f24f1ee1c9db9fd109ad9 Mon Sep 17 00:00:00 2001 From: jihongshun <1151753686@qq.com> Date: 星期六, 12 七月 2025 17:23:02 +0800 Subject: [PATCH] 算法优化 --- src/views/system/project/components/addPorjectDialog.vue | 628 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 400 insertions(+), 228 deletions(-) diff --git a/src/views/system/project/components/addPorjectDialog.vue b/src/views/system/project/components/addPorjectDialog.vue index c336406..fa4de99 100644 --- a/src/views/system/project/components/addPorjectDialog.vue +++ b/src/views/system/project/components/addPorjectDialog.vue @@ -14,6 +14,8 @@ <div class="fontJust">璁惧鍒楄〃</div> <el-button @click="addDevice"> 鏂板</el-button> <el-button @click="draw"> 娓叉煋</el-button> + <el-button @click="test"> 杞崲</el-button> + <el-button @click="huixian"> 0.0</el-button> <el-table :data="tableData" max-height = '180' @@ -100,100 +102,68 @@ "belongingRoute": "绾胯矾3", "face": 30, "label": "璁惧3", - "children": [ + "children":[ { - "id": "197ee63df18b0af0", + "id": "197f211797aa9f32", "label": "鍦伴潰鐐�0", - "longitude": 125.01254682821249, - "latitude": 46.40803726847258, - "height": 5.55594577349203, + "longitude": 125.01254690233337, + "latitude": 46.408037041988585, + "height": 5.517266389025914, "children": [ { - "id": "197ee63df18539a3", - "label": "绌轰腑鐐�1", - "longitude": 125.01128753149214, - "latitude": 46.4082612208105, - "height": 6.492838981926156 + "id": "197f211797afb196", + "label": "绌轰腑鐐�0", + "longitude": 125.01240358310912, + "latitude": 46.40814584281285, + "height": 6.971525719304772 } ] }, { - "id": "197ee63df18cce29", + "id": "197f211797af91d9", "label": "鍦伴潰鐐�1", - "longitude": 125.01254709729052, - "latitude": 46.408037217374755, - "height": 6.4920524070572645, + "longitude": 125.01254808759698, + "latitude": 46.4080365594918, + "height": 7.385339183474696, "children": [ { - "id": "197ee63df18539a3", + "id": "197f211797afdb9a", "label": "绌轰腑鐐�1", - "longitude": 125.01128753149214, - "latitude": 46.4082612208105, - "height": 6.492838981926156 + "longitude": 125.0125163640242, + "latitude": 46.407960727919516, + "height": 10.451384666363694 } ] }, { - "id": "197ee63df188aa47", + "id": "197f211797afab31", "label": "鍦伴潰鐐�2", - "longitude": 125.01254783039168, - "latitude": 46.408036932133236, - "height": 7.424864167610554, + "longitude": 125.01255947706582, + "latitude": 46.408036885119245, + "height": 7.42469267651616, "children": [ { - "id": "197ee63df1845bc7", + "id": "197f211797a61300", "label": "绌轰腑鐐�2", - "longitude": 125.0112772702233, - "latitude": 46.40822893934041, - "height": 7.425650325131619 + "longitude": 125.0128655208287, + "latitude": 46.4080332165472, + "height": 14.51791089195843 } ] }, { - "id": "197ee63df199a530", + "id": "197f211797af21e7", "label": "鍦伴潰鐐�3", - "longitude": 125.01255933758492, - "latitude": 46.40803691722688, - "height": 7.424719094681872, + "longitude": 125.01256023273389, + "latitude": 46.408036999460684, + "height": 5.5171023712317435, "children": [ { - "id": "197ee63df1908bad", + "id": "197f211797a19b34", "label": "绌轰腑鐐�3", - "longitude": 125.0138300519516, - "latitude": 46.40822843553173, - "height": 7.425505375628057 - } - ] - }, - { - "id": "197ee63df198ebdf", - "label": "鍦伴潰鐐�4", - "longitude": 125.01256021566009, - "latitude": 46.408036958116895, - "height": 6.454013013927198, - "children": [ - { - "id": "197ee63df192e649", - "label": "绌轰腑鐐�4", - "longitude": 125.0138360193498, - "latitude": 46.40821153783117, - "height": 6.454799694246353 - } - ] - }, - { - "id": "197ee63df1989863", - "label": "鍦伴潰鐐�5", - "longitude": 125.01256037655455, - "latitude": 46.40803705402738, - "height": 5.5173191358810305, - "children": [ - { - "id": "197ee63df19fb1cb", - "label": "绌轰腑鐐�5", - "longitude": 125.01384789553899, - "latitude": 46.408163891976834, - "height": 6.023658449094137 + "longitude": 125.01277085845463, + "latitude": 46.40822397536244, + "height": 16.06139535507995 } ] } @@ -216,103 +186,71 @@ "face": 30, "label": "璁惧2", "children": [ - { - "id": "197ee6746f64a423", - "label": "鍦伴潰鐐�0", - "longitude": 124.98496378621228, - "latitude": 46.60913556199556, - "height": 5.517188951102072, - "children": [ { - "id": "197ee6746f74e23a", - "label": "绌轰腑鐐�0", - "longitude": 124.98623131325654, - "latitude": 46.60892064074182, - "height": 5.517975962983238 + "id": "197f2157b83d1d1e", + "label": "鍦伴潰鐐�0", + "longitude": 124.98495046473204, + "latitude": 46.60913764437918, + "height": 5.517192953851729, + "children": [ + { + "id": "197f2157b833e7e6", + "label": "绌轰腑鐐�0", + "longitude": 124.98487290823232, + "latitude": 46.609159110536, + "height": 8.492315413669576 + } + ] + }, + { + "id": "197f2157b83cb37c", + "label": "鍦伴潰鐐�1", + "longitude": 124.98495132002881, + "latitude": 46.609137518901555, + "height": 7.424720940488529, + "children": [ + { + "id": "197f2157b83dbf31", + "label": "绌轰腑鐐�1", + "longitude": 124.984847808066, + "latitude": 46.60911367086078, + "height": 8.37839897370324 + } + ] + }, + { + "id": "197f2157b831259d", + "label": "鍦伴潰鐐�2", + "longitude": 124.98496295996078, + "latitude": 46.60913752946039, + "height": 7.424330357264399, + "children": [ + { + "id": "197f2157b837245b", + "label": "绌轰腑鐐�2", + "longitude": 124.98502199892675, + "latitude": 46.60913926099941, + "height": 12.416325107963392 + } + ] + }, + { + "id": "197f2157b83112ee", + "label": "鍦伴潰鐐�3", + "longitude": 124.9849638899571, + "latitude": 46.60913769557282, + "height": 5.51721178277007, + "children": [ + { + "id": "197f2157b8349c7d", + "label": "绌轰腑鐐�3", + "longitude": 124.98502033157477, + "latitude": 46.609152323278046, + "height": 4.804689162058357 + } + ] } ] - }, - { - "id": "197ee6746f7d5cbb", - "label": "鍦伴潰鐐�1", - "longitude": 124.98496380688303, - "latitude": 46.609135777787124, - "height": 6.454174518781066, - "children": [ - { - "id": "197ee6746f76d1f7", - "label": "绌轰腑鐐�1", - "longitude": 124.98624416031694, - "latitude": 46.60896064802085, - "height": 6.454961413485681 - } - ] - }, - { - "id": "197ee6746f7f75d3", - "label": "鍦伴潰鐐�2", - "longitude": 124.9849627026509, - "latitude": 46.6091358190698, - "height": 7.4247849395402445, - "children": [ - { - "id": "197ee6746f7bd9af", - "label": "绌轰腑鐐�2", - "longitude": 124.98623564998626, - "latitude": 46.608936693647046, - "height": 7.425571052201786 - } - ] - }, - { - "id": "197ee6746f786c30", - "label": "鍦伴潰鐐�3", - "longitude": 124.98495139129277, - "latitude": 46.609136202860036, - "height": 7.385436810668997, - "children": [ - { - "id": "197ee6746f7220cc", - "label": "绌轰腑鐐�3", - "longitude": 124.98365601680429, - "latitude": 46.60902531680706, - "height": 7.386222783506121 - } - ] - }, - { - "id": "197ee6746f70eac7", - "label": "鍦伴潰鐐�4", - "longitude": 124.98495046384257, - "latitude": 46.6091358802505, - "height": 6.453950090508963, - "children": [ - { - "id": "197ee6746f74dd82", - "label": "绌轰腑鐐�4", - "longitude": 124.98366517250753, - "latitude": 46.60897886511559, - "height": 6.4547368247826675 - } - ] - }, - { - "id": "197ee6746f7ac599", - "label": "鍦伴潰鐐�5", - "longitude": 124.984950334958, - "latitude": 46.609135834916806, - "height": 5.516518597126235, - "children": [ - { - "id": "197ee6746f7220cc", - "label": "绌轰腑鐐�3", - "longitude": 124.98365601680429, - "latitude": 46.60902531680706, - "height": 7.386222783506121 - } - ] - } -] }, { "createBy": null, @@ -332,98 +270,66 @@ "label": "璁惧1", "children": [ { - "id": "197ee65dac710766", + "id": "197f21d1d1a28cf6", "label": "鍦伴潰鐐�0", - "longitude": 125.14335344347126, - "latitude": 46.55898205916312, - "height": 5.556756800574575, + "longitude": 125.14335344922452, + "latitude": 46.558982037049276, + "height": 5.556334669315725, "children": [ { - "id": "197ee65dac75edbb", + "id": "197f21d1d1adcbe6", "label": "绌轰腑鐐�0", - "longitude": 125.14209452120562, - "latitude": 46.55921686479333, - "height": 5.557543680589247 + "longitude": 125.14330233595797, + "latitude": 46.55904743869546, + "height": 6.468726016875199 } ] }, { - "id": "197ee65dac76a522", + "id": "197f21d1d1a4aa12", "label": "鍦伴潰鐐�1", - "longitude": 125.14335363213557, - "latitude": 46.55898182607255, - "height": 6.651683951645225, + "longitude": 125.14335458905991, + "latitude": 46.558981268478746, + "height": 7.384477227891685, "children": [ { - "id": "197ee65dac772525", - "label": "绌轰腑鐐�2", - "longitude": 125.14208232214659, - "latitude": 46.559179705774746, - "height": 7.425743074154034 + "id": "197f21d1d1a846ae", + "label": "绌轰腑鐐�1", + "longitude": 125.14298096389273, + "latitude": 46.558969173376134, + "height": 22.10867400719622 } ] }, { - "id": "197ee65dac712c69", + "id": "197f21d1d1a52190", "label": "鍦伴潰鐐�2", - "longitude": 125.14335446603941, - "latitude": 46.55898169199969, - "height": 7.424957062075383, + "longitude": 125.14336589537841, + "latitude": 46.558981709304724, + "height": 7.424676991507425, "children": [ { - "id": "197ee65dac772525", + "id": "197f21d1d1a6a4fe", "label": "绌轰腑鐐�2", - "longitude": 125.14208232214659, - "latitude": 46.559179705774746, - "height": 7.425743074154034 + "longitude": 125.14339720378332, + "latitude": 46.5590446327473, + "height": 16.720685909327106 } ] }, { - "id": "197ee65dac7d469a", + "id": "197f21d1d1a272b1", "label": "鍦伴潰鐐�3", - "longitude": 125.14336581328187, - "latitude": 46.55898112552418, - "height": 7.385369522508276, + "longitude": 125.14336689453488, + "latitude": 46.558981604123645, + "height": 5.516875737104807, "children": [ { - "id": "197ee65dac74b335", + "id": "197f21d1d1af7638", "label": "绌轰腑鐐�3", - "longitude": 125.14460210993491, - "latitude": 46.55869709406983, - "height": 11.416007026601994 - } - ] - }, - { - "id": "197ee65dac7817ff", - "label": "鍦伴潰鐐�4", - "longitude": 125.14336674537108, - "latitude": 46.55898211835868, - "height": 6.48472072335647, - "children": [ - { - "id": "197ee65dac7602d7", - "label": "绌轰腑鐐�4", - "longitude": 125.14461900411601, - "latitude": 46.559233306964344, - "height": 6.485507501890941 - } - ] - }, - { - "id": "197ee65dac74500d", - "label": "鍦伴潰鐐�5", - "longitude": 125.14336684823117, - "latitude": 46.55898218335435, - "height": 5.556803725040882, - "children": [ - { - "id": "197ee65dac7d10f5", - "label": "绌轰腑鐐�5", - "longitude": 125.14464805019499, - "latitude": 46.559149450894154, - "height": 7.227587215704448 + "longitude": 125.14397230855407, + "latitude": 46.55882377669704, + "height": 45.87173852318548 } ] } @@ -449,7 +355,8 @@ flyToLocal(row){ console.log(row) console.log(viewer) - const position = Cesium.Cartesian3.fromDegrees(row.longitude,row.latitude, row.altitude); + // const position = Cesium.Cartesian3.fromDegrees(row.longitude,row.latitude, row.altitude); + const position = Cesium.Cartesian3.fromDegrees(0,0,0); // 璁剧疆妯″瀷鏂瑰悜锛堝彲閫夛級 const heading = Cesium.Math.toRadians(row.face); // 鏈濅笢鍗楁柟鍚� @@ -466,7 +373,7 @@ position: position, orientation: orientation, model: { - uri: "http://192.168.1.5:9000/tower/2025/07/01/tower_20250701145739A004.glb", // 鏇挎崲鎴愪綘鐨勬ā鍨嬭矾寰� + uri: "http://192.168.1.5:9000/tower/2025/07/11/閾佸_20250711093701A001.glb", // 鏇挎崲鎴愪綘鐨勬ā鍨嬭矾寰� scale: 1, }, label: { @@ -569,7 +476,7 @@ } }); }, - drawConnectionsWithLabels(devices) { + drawConnectionsWithLabels1111(devices) { const airPoints = []; devices.forEach(device => { @@ -660,8 +567,273 @@ }); } }, + drawConnectionsWithLabels(devices) { + const airPoints = []; + + devices.forEach(device => { + if (!Array.isArray(device.children)) return; + + device.children.forEach(airPoint => { + // 绌轰腑鐐逛綅缃� + const airPos = Cesium.Cartesian3.fromDegrees( + airPoint.longitude, + airPoint.latitude, + airPoint.height + ); + + // 鉁� 娣诲姞绌轰腑鐐瑰疄浣撳拰 label + viewer.entities.add({ + position: airPos, + point: { + pixelSize: 6, + color: Cesium.Color.YELLOW + }, + label: { + text: airPoint.label || '', + font: '14px sans-serif', + fillColor: Cesium.Color.YELLOW, + style: Cesium.LabelStyle.FILL_AND_OUTLINE, + outlineColor: Cesium.Color.BLACK, + outlineWidth: 2, + verticalOrigin: Cesium.VerticalOrigin.BOTTOM, + pixelOffset: new Cesium.Cartesian2(0, -12) + } + }); + + airPoints.push(airPos); + + // 閬嶅巻鍦伴潰鐐癸紙瀛愰」锛� + if (Array.isArray(airPoint.children)) { + airPoint.children.forEach(groundPoint => { + const groundPos = Cesium.Cartesian3.fromDegrees( + groundPoint.longitude, + groundPoint.latitude, + groundPoint.height + ); + + // 鉁� 娣诲姞鍦伴潰鐐瑰疄浣撳拰 label + viewer.entities.add({ + position: groundPos, + point: { + pixelSize: 6, + color: Cesium.Color.BLUE + }, + label: { + text: groundPoint.label || '', + font: '14px sans-serif', + fillColor: Cesium.Color.WHITE, + style: Cesium.LabelStyle.FILL_AND_OUTLINE, + outlineColor: Cesium.Color.BLACK, + outlineWidth: 2, + verticalOrigin: Cesium.VerticalOrigin.BOTTOM, + pixelOffset: new Cesium.Cartesian2(0, -12) + } + }); + + // 鉁� 钃濊壊铏氱嚎杩炴帴锛氱┖涓偣 鉃� 鍦伴潰鐐� + viewer.entities.add({ + polyline: { + positions: [airPos, groundPos], + width: 2, + material: new Cesium.PolylineDashMaterialProperty({ + color: Cesium.Color.BLUE, + dashLength: 8 + }) + } + }); + }); + } + }); + }); + + // 鉁� 榛勮壊瀹炵嚎杩炴帴鎵�鏈夌┖涓偣 + if (airPoints.length > 1) { + viewer.entities.add({ + polyline: { + positions: airPoints, + width: 3, + material: Cesium.Color.YELLOW + } + }); + } + }, draw(){ this.drawConnectionsWithLabels(this.treeData) + }, + test(){ + this.treeData = this.swapGroundAir(this.treeData); + }, + swapGroundAir(data) { + + return data.map(device => { + const newChildren = []; + + device.children.forEach(ground => { + const air = ground.children && ground.children[0]; + if (air) { + newChildren.push({ + ...air, + children: [ + { + ...ground, + children: undefined + } + ] + }); + } + }); + + return { + ...device, + children: newChildren + }; + }); + }, + huixian(){ + let data=[ + { + "altitude": 35.09683139439875, + "ardGroundPoint": [ + { + "height": 35.0960134603141, + "latitude": 0.000032899894086000126, + "longitude": 3.2789183307897707e-7, + "pointNumber": 1, + "targetName": "鍦伴潰鐐�0" + } + ], + "latitude": 0.0009372188427979371, + "longitude": 0.000009340650264268872, + "pointNumber": 1, + "targetName": "绌轰腑鐐�0" + }, + { + "altitude": 40.057437157900914, + "ardGroundPoint": [ + { + "height": 40.05662385374772, + "latitude": 0.00002759265968150938, + "longitude": 7.877836487599675e-7, + "pointNumber": 1, + "targetName": "鍦伴潰鐐�1" + } + ], + "latitude": 0.0009315830781716235, + "longitude": 0.000026597143043885405, + "pointNumber": 2, + "targetName": "绌轰腑鐐�1" + }, + { + "altitude": 90.05743715790092, + "ardGroundPoint": [ + { + "height": 40.05662385374772, + "latitude": 0.00002759265968150938, + "longitude": 7.877836487599675e-7, + "pointNumber": 1, + "targetName": "鍦伴潰鐐�1-鍔犻珮" + } + ], + "latitude": 0.0009315830781716235, + "longitude": 0.000026597143043885405, + "pointNumber": 3, + "targetName": "绌轰腑鐐�1-鍔犻珮" + }, + { + "altitude": 85.4017386642163, + "ardGroundPoint": [ + { + "height": 35.09000336658791, + "latitude": -0.0000329911085806409, + "longitude": 4.656954257439534e-7, + "pointNumber": 1, + "targetName": "鍦伴潰鐐�2" + } + ], + "latitude": -0.0009372610742669285, + "longitude": 0.000013144727598247196, + "pointNumber": 4, + "targetName": "绌轰腑鐐�2-鍔犻珮" + }, + { + "altitude": 35.401738664216296, + "ardGroundPoint": [ + { + "height": 35.09000336658791, + "latitude": -0.0000329911085806409, + "longitude": 4.656954257439534e-7, + "pointNumber": 1, + "targetName": "鍦伴潰鐐�2" + } + ], + "latitude": -0.0009372610742669285, + "longitude": 0.000013144727598247196, + "pointNumber": 5, + "targetName": "绌轰腑鐐�2" + } +] + let aaa = this.convertToTree(data) + console.log(aaa) + this.drawLines(aaa) + }, + convertToTree(data) { + return data.map((item, index) => { + const parentId = 'air_' + index; + return { + id: parentId, + label: item.targetName, + longitude: item.longitude, + latitude: item.latitude, + height: item.altitude, + children: (item.ardGroundPoint || []).map((g, i) => { + return { + id: parentId + '_ground_' + i, + label: g.targetName, + longitude: g.longitude, + latitude: g.latitude, + height: g.height + } + }) + } + }); + }, + drawLines(treeData) { + console.log(treeData) + // 鏀堕泦绌轰腑鐐逛綅缃� + const airPositions = treeData.map(point => { + return Cesium.Cartesian3.fromDegrees( + point.longitude, + point.latitude, + point.height + ); + }); + + // 1. 绌轰腑鐐逛箣闂寸敤榛勮壊瀹炵嚎杩炴帴 + viewer.entities.add({ + polyline: { + positions: airPositions, + width: 2, + material: Cesium.Color.YELLOW + } + }); + + // 2. 姣忎釜绌轰腑鐐逛笌鍦伴潰鐐圭敤钃濊壊铏氱嚎杩炴帴 + treeData.forEach(point => { + const airPos = Cesium.Cartesian3.fromDegrees(point.longitude, point.latitude, point.height); + point.children.forEach(child => { + const groundPos = Cesium.Cartesian3.fromDegrees(child.longitude, child.latitude, child.height); + viewer.entities.add({ + polyline: { + positions: [airPos, groundPos], + width: 1, + material: new Cesium.PolylineDashMaterialProperty({ + color: Cesium.Color.BLUE, + dashLength: 8 + }) + } + }); + }); + }); } } } -- Gitblit v1.9.3