From 623c70f0726e61a851a7909348e2cf7781fa5d19 Mon Sep 17 00:00:00 2001 From: wangjuncheng <1> Date: 星期四, 29 五月 2025 15:11:43 +0800 Subject: [PATCH] change --- src/components/menu/CrossSectionalAnalysis.vue | 78 +++++++++++++++++++++++++++++++-------- 1 files changed, 62 insertions(+), 16 deletions(-) diff --git a/src/components/menu/CrossSectionalAnalysis.vue b/src/components/menu/CrossSectionalAnalysis.vue index 098875f..1a27497 100644 --- a/src/components/menu/CrossSectionalAnalysis.vue +++ b/src/components/menu/CrossSectionalAnalysis.vue @@ -10,14 +10,13 @@ </div> <div @click="clearPoints"> <img src="@/assets/img/timeline/娓呴櫎.png" style="width: 26px;height: 26px;" /> - </div> </div> </template> <script setup> import { ElMessage } from 'element-plus'; -import { ref, onMounted ,defineExpose } from "vue"; +import { ref, onMounted, defineExpose } from "vue"; const viewer = window.viewer; @@ -26,9 +25,11 @@ let isWallCreated = ref(false); // 鏂板鐘舵�佸彉閲忥紝鏍囪澧欎綋鏄惁宸插垱寤� let isPicking = ref(false); // 鏄惁姝e湪鎷惧彇鐐� const isUploaded = ref(false); // 鎺у埗鏄惁宸蹭笂浼� + // 鑾峰彇鏂潰鍧愭爣 function getPickPosition(windowPosition) { if (!viewer) return null; + viewer.scene.globe.depthTestAgainstTerrain = true; const cartesian = viewer.scene.pickPosition(windowPosition); if (!cartesian) return null; const cartographic = Cesium.Cartographic.fromCartesian(cartesian); @@ -56,7 +57,6 @@ pickedPointsCross.value.push(point); drawPointOnMap(point); if (pickedPointsCross.value.length === 2) { - // ElMessage.success('褰撳墠涓ょ偣鍧愭爣宸查�夊彇瀹屾垚锛屾鍦ㄧ敓鎴愭柇闈㈡埅闈紒'); drawWall(pickedPointsCross.value[0], pickedPointsCross.value[1]); isWallCreated.value = true; // 璁剧疆涓哄凡鍒涘缓澧欎綋 } @@ -88,9 +88,65 @@ } }); pickedEntitiesIds.value.push(entity.id); // 璁板綍瀹炰綋ID + // 鍚屾椂缁樺埗妯℃嫙鐐� + drawSimulationPoint(startPoint, endPoint); } -// 淇敼鍚庣殑娓呴櫎鍑芥暟锛屽彧娓呴櫎鍒涘缓鐨勭偣鍜屽 +// 鏂板锛氱粯鍒舵ā鎷熺偣锛堝渾鏌� + label锛� +function drawSimulationPoint(start, end) { +// 璁$畻涓偣锛堢粡绾害骞冲潎鍊硷級 +const midLon = (start.longitude + end.longitude) / 2; +const midLat = (start.latitude + end.latitude) / 2; +const terrainHeight = viewer.scene.globe.getHeight( + Cesium.Cartographic.fromDegrees(midLon, midLat) +); +const cylinderBottomHeight = 0; +const cylinderTopHeight = terrainHeight + 190; +const cartesianBottom = viewer.scene.globe.ellipsoid.cartographicToCartesian( + Cesium.Cartographic.fromDegrees(midLon, midLat, cylinderBottomHeight) +); +const CrosscylinderEntity = viewer.entities.add({ + position: cartesianBottom, + cylinder: { + length: 190.0, + topRadius: 1.0, + bottomRadius: 1.0, + material: Cesium.Color.YELLOW, + outline: true, + outlineColor: Cesium.Color.YELLOW, + slices: 64, + heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, + distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000) + } +}); +const labelHeight = cylinderTopHeight + 10; +const cartesianLabel = viewer.scene.globe.ellipsoid.cartographicToCartesian( + Cesium.Cartographic.fromDegrees(midLon, midLat, labelHeight) +); + +const CrosslabelEntity = viewer.entities.add({ + position: cartesianLabel, + label: { + text: '鏂潰鎴潰妯℃嫙鐐�', + font: 'bold 14pt monospace', + style: Cesium.LabelStyle.FILL_AND_OUTLINE, + fillColor: Cesium.Color.YELLOW, + outlineColor: Cesium.Color.BLACK, + outlineWidth: 2, + verticalOrigin: Cesium.VerticalOrigin.CENTER, + horizontalOrigin: Cesium.HorizontalOrigin.CENTER, + backgroundColor: Cesium.Color.fromCssColorString('rgba(0,0,0,0.7)'), + backgroundPadding: new Cesium.Cartesian2(10, 10), + showBackground: true, + scale: 1, + distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000), + pixelOffsetScaleByDistance: new Cesium.NearFarScalar(100, 1.0, 5000, 0.3), + heightReference: Cesium.HeightReference.NONE // 浣跨敤缁濆楂樺害 + } +}); +pickedEntitiesIds.value.push(CrosscylinderEntity.id); +pickedEntitiesIds.value.push(CrosslabelEntity.id); +} function clearPoints() { for (const id of pickedEntitiesIds.value) { viewer.entities.remove(viewer.entities.getById(id)); @@ -100,10 +156,7 @@ isWallCreated.value = false; isUploaded.value = false; } - -// 鎷惧彇鐐瑰潗鏍囩劧鍚庣敾鐐癸紙绠�鍖栫増锛� function initPickHandler() { - // 鍒囨崲鐘舵�侊細濡傛灉涔嬪墠鍦ㄦ嬀鍙栵紝杩欐灏辨槸鍙栨秷鎷惧彇 if (isPicking.value) { if (pickHandlerCross) { pickHandlerCross.destroy(); @@ -114,20 +167,13 @@ ElMessage.info('宸插叧闂�--鏂潰鎴潰--鎷惧彇鐐瑰潗鏍囧姛鑳斤紒'); return; } - - // 杩涘叆鎷惧彇妯″紡 ElMessage.success(`寮�濮�--鏂潰鎴潰--鎷惧彇鍧愭爣鍔熻兘锛岃鐐瑰嚮鍦板浘閫夋嫨鐐逛綅锛侀�夊彇瀹岃鍙婃椂鍏抽棴锛岄伩鍏嶅奖鍝嶅叾浠栧姛鑳斤紒`); isPicking.value = true; - if (!viewer?.scene?.canvas) return; - - // 閿�姣佹棫鐨� handler if (pickHandlerCross) { pickHandlerCross.destroy(); pickHandlerCross = null; } - - // 鍒涘缓鏂� handler pickHandlerCross = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); const clickAction = (movement) => { @@ -139,7 +185,6 @@ pickHandlerCross.setInputAction(clickAction, Cesium.ScreenSpaceEventType.LEFT_CLICK); } -// 纭鎸夐挳鐐瑰嚮浜嬩欢,鍙戦�佽姹傝皟鐢ㄦ帴鍙� function confirmPoints() { if (pickedPointsCross.value.length < 2) { ElMessage.warning('璇峰厛閫夋嫨涓や釜鐐瑰悗鍐嶈繘琛岀‘璁わ紒'); @@ -161,9 +206,10 @@ cartesian: point2.cartesian }); - isUploaded.value = true; // 璁剧疆涓哄凡涓婁紶鐘舵�� + isUploaded.value = true; ElMessage.success('姝e湪杩涜--鏂潰鎴潰--鏁版嵁鍒嗘瀽涓婁紶锛岃绋嶇瓑...'); } + defineExpose({ clearPoints }); -- Gitblit v1.9.3