From 6db44719b442b88a3cd1bb71ae74a778b3c4dabc Mon Sep 17 00:00:00 2001
From: 584911253@qq.com <584911253@qq.com>
Date: 星期三, 15 三月 2023 16:18:00 +0800
Subject: [PATCH] 三维截取功能修改

---
 src/views/Synthesis/LeftMenu.vue |  296 ++++++++++++++++++++++++++++++++++++++----------
 src/components/mapsdk.vue        |   49 ++++++++
 2 files changed, 282 insertions(+), 63 deletions(-)

diff --git a/src/components/mapsdk.vue b/src/components/mapsdk.vue
index f4dc56b..81fb2b9 100644
--- a/src/components/mapsdk.vue
+++ b/src/components/mapsdk.vue
@@ -448,6 +448,24 @@
 
         </el-card>
       </div>
+      <!--涓夌淮鎴潰鍒嗘瀽寮圭獥-->
+      <div
+          class="modelClipPop"
+          v-if="$store.state.propertiesFlag == '3'"
+      >
+        <div class="slide-bg">
+          <el-slider class="slide" @change="valveChange()" :min="-300" :max="300" v-model="valueX"></el-slider>
+          <span>宸﹀彸鎴潰</span>
+        </div>
+        <div class="slide-bg">
+          <el-slider class="slide" @change="valveChange()" :min="-300" :max="300" v-model="valueY"></el-slider>
+          <span>鍓嶅悗鎴潰</span>
+        </div>
+        <div class="slide-bg">
+          <el-slider class="slide" @change="valveChange()" :min="-300" :max="300" v-model="valueZ"></el-slider>
+          <span>涓婁笅鎴潰</span>
+        </div>
+      </div>
 
       <!--闄勪欢鍒楄〃寮圭獥-->
       <el-dialog
@@ -659,6 +677,9 @@
       },
       showAttribute: false,
       attributeList: [],
+      valueZ:0,
+      valueX:0,
+      valueY:0
     };
   },
   mounted() {
@@ -685,6 +706,10 @@
     });
     //妯″瀷鎹曟崏
     this.catchmodel()
+
+    window.localStorage.setItem('slider_x',this.valueX);
+    window.localStorage.setItem('slider_y',this.valueY);
+    window.localStorage.setItem('slider_z',this.valueZ);
   },
   methods: {
 
@@ -1495,6 +1520,11 @@
         this.attributeList = list;
       }
     },
+    valveChange(){
+      window.localStorage.setItem('slider_x',this.valueX);
+      window.localStorage.setItem('slider_y',this.valueY);
+      window.localStorage.setItem('slider_z',this.valueZ);
+    }
   },
   destroyed() {
     this.showAttribute = false
@@ -1551,6 +1581,25 @@
         padding: 10px 20px;
       }
     }
+    .modelClipPop{
+      width: 350px;
+      z-index: 40;
+      position: absolute;
+      left: 2%;
+      top: 3%;
+      background: rgba(255,255,255,0.85);
+      border: 1px solid rgba(32, 160, 255, 0.6);
+      .slide-bg{
+        padding:10px;
+        display: flex;
+        align-items: center;
+        .slide{
+          width: 250px;
+          margin-left: 5px;
+          margin-right: 15px;
+        }
+      }
+    }
     .pathAnalysisBox{
       width: 412px;
       height: 370px;
diff --git a/src/views/Synthesis/LeftMenu.vue b/src/views/Synthesis/LeftMenu.vue
index e5707d9..ca3e32f 100644
--- a/src/views/Synthesis/LeftMenu.vue
+++ b/src/views/Synthesis/LeftMenu.vue
@@ -678,7 +678,6 @@
           label: '鍏朵粬妯″瀷'
         }],
       modelClip: false,
-      clippingPlanes: null,
       showPickUp: false,
     };
   },
@@ -691,9 +690,13 @@
         // window.model = null;
       }
       sgworld.Analysis.clearCurtainContrast();
+      this.showPickUp = false;
       if (this.isMenuFlag == "d") {
         this.clearAllAnalsy();
       }
+
+      this.$store.state.propertiesFlag = '';
+      Viewer.entities.removeAll();
 
       if (this.isMenuFlag != val) {
         if (res.id != "b9") {
@@ -1395,14 +1398,14 @@
     setIquery(res) {
       switch (res) {
         case "e2":
-          Viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
+          this.showPickUp = false;
           this.$store.state.mapMenuBoolean = !this.$store.state.mapMenuBoolean;
           this.$store.state.mapMenuBoxFlag = "1";
           break;
         case "e1":
-          Viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
           this.$store.state.mapMenuBoolean = !this.$store.state.mapMenuBoolean;
           this.$store.state.mapMenuBoxFlag = "2";
+          this.showPickUp = false;
           break;
         //鎷惧彇鍔熻兘
         case "e3":
@@ -1413,7 +1416,9 @@
             Viewer.screenSpaceEventHandler.setInputAction(function (event) {
               let p = sgworld.Navigate.getMouseDegrees(event);
               console.log(p);
-              that.getPickUpData(p);
+              if (that.showPickUp){
+                that.getPickUpData(p);
+              }
             }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
           } else {
             this.$refs.queryinfo.closeAll();
@@ -1551,6 +1556,7 @@
           var that = this;
           that.modelClip = !that.modelClip;
           if (that.modelClip) {
+            that.$store.state.propertiesFlag = '3';
             if (window.model) {
               that.modelClipping();
             }
@@ -1575,6 +1581,7 @@
             }
           }
           else {
+            that.$store.state.propertiesFlag = '';
             Viewer.entities.removeAll();
           }
           // window.model = sgworld.Creator.create3DTilesets(
@@ -1755,89 +1762,247 @@
       let targetY = 0.0;
       let planeEntities = [];
       let selectedPlane;
+      // let clippingPlanes = new Cesium.ClippingPlaneCollection({
+      //   planes: [ // ClippingPlane瀵硅薄鏁扮粍闆嗗悎
+      //     new Cesium.ClippingPlane( // 瑁佸垏闈�
+      //       new Cesium.Cartesian3(0.0, 0.0, -1.0), // 娉曠嚎鏂瑰悜
+      //       0// 鍘熺偣鍒板钩闈㈢殑鏈�鐭窛绂伙紝璁剧疆0灏卞ソ
+      //     ),
+      //   ],
+      //   enabled: true,
+      //   edgeWidth: 1.0, // 妯″瀷琚鍒囬儴鍒嗙殑鎴潰绾垮
+      // });
       let clippingPlanes = new Cesium.ClippingPlaneCollection({
         planes: [ // ClippingPlane瀵硅薄鏁扮粍闆嗗悎
-          new Cesium.ClippingPlane( // 瑁佸垏闈�
-            new Cesium.Cartesian3(0.0, 0.0, -1.0), // 娉曠嚎鏂瑰悜
-            0// 鍘熺偣鍒板钩闈㈢殑鏈�鐭窛绂伙紝璁剧疆0灏卞ソ
-          ),
+          //鍓嶅悗鍒囧壊
+          new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 1, 0), 0), //鍚�
+          new Cesium.ClippingPlane(new Cesium.Cartesian3(0, -1, 0), 0),  //鍓�
+          // 宸﹀彸鍒囧壊
+          new Cesium.ClippingPlane(new Cesium.Cartesian3(1.0, 0.0, 0), 0), //宸�
+          new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0), 0),  //鍙�
+          // 涓婁笅鍒囧壊
+          new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, -1), 0),  //涓娾啋涓�
+          // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, 1), 0),  //涓嬧啋涓娿��
         ],
         enabled: true,
         edgeWidth: 1.0, // 妯″瀷琚鍒囬儴鍒嗙殑鎴潰绾垮
+        unionClippingRegions: true, //true 鎵嶈兘澶氫釜鍒囧壊
       });
       let boundingSphere = window.model.boundingSphere;
+      // 鍒涘缓涓�涓潗鏍囪酱锛屼究浜庢祴璇�
+      var transform = Cesium.Transforms.eastNorthUpToFixedFrame(boundingSphere.center);
+      var modelMatrixPrimitive = Viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
+        // modelMatrix: transform,
+        length: 140.0
+      }));
+
+      // // 鍒涘缓娣诲姞瑁佸壀骞抽潰
+      // for (let i = 0; i < clippingPlanes.length; ++i) {
+      //   const plane = clippingPlanes.get(i);
+      //   const planeEntity = Viewer.entities.add({
+      //     position: boundingSphere.center,
+      //     plane: {
+      //       dimensions: new Cesium.Cartesian2(
+      //         boundingSphere.radius * 1.5,
+      //         boundingSphere.radius * 1.5
+      //       ),//鍒囬潰鐨勯暱鍜屽
+      //       material: Cesium.Color.WHITE.withAlpha(0.1),
+      //       plane: new Cesium.CallbackProperty(
+      //         // 娣诲姞缁戝畾浜嬩欢锛屼笉鏂皟鐢�
+      //         createPlaneUpdateFunction(plane),
+      //         false
+      //       ),
+      //       outline: true,
+      //       outlineColor: Cesium.Color.WHITE,
+      //     },
+      //   });
+      //   planeEntities.push(planeEntity);
+      // }
       // 鍒涘缓娣诲姞瑁佸壀骞抽潰
+      let m_box;
       for (let i = 0; i < clippingPlanes.length; ++i) {
-        const plane = clippingPlanes.get(i);
-        const planeEntity = Viewer.entities.add({
-          position: boundingSphere.center,
+        let plane = clippingPlanes.get(i);
+        let getPlaneType = getType4Plane(plane);
+        let planeEntity = Viewer.entities.add({ //娣诲姞骞抽潰瀹炰綋 鐩磋瑁佸垏闈�
+          id: 'ClipPlane' + i,
+          position: boundingSphere.center,// 鏍规嵁3dtiles鍚屾璋冩暣瑁佸垏闈㈤珮搴�
           plane: {
-            dimensions: new Cesium.Cartesian2(
-              boundingSphere.radius * 1.5,
-              boundingSphere.radius * 1.5
-            ),
-            material: Cesium.Color.WHITE.withAlpha(0.1),
-            plane: new Cesium.CallbackProperty(
-              // 娣诲姞缁戝畾浜嬩欢锛屼笉鏂皟鐢�
-              createPlaneUpdateFunction(plane),
-              false
-            ),
-            outline: true,
+            dimensions: new Cesium.Cartesian2(80, 80),//鍒囬潰鐨勯暱鍜屽
+            plane: new Cesium.CallbackProperty(createPlaneUpdateFunction_box(plane, getPlaneType, boundingSphere.center), false),
+            material: Cesium.Color.WHITE.withAlpha(0.01),
+            outline: false,
             outlineColor: Cesium.Color.WHITE,
-          },
+          }
         });
-        planeEntities.push(planeEntity);
+        if (!m_box) {
+          m_box = Viewer.entities.add({
+            id: 'ClopBox',
+            modelMatrixPrimitive:modelMatrixPrimitive,
+            position: boundingSphere.center,
+            box: {
+              dimensions: new Cesium.Cartesian3(boundingSphere.radius * 1.2, boundingSphere.radius * 1.2, 40),
+              material: Cesium.Color.WHITE.withAlpha(0.3),
+            }
+          })
+        }
       }
-      this.clippingPlanes = clippingPlanes;
       window.model.clippingPlanes = clippingPlanes;
 
-      // Select plane when mouse down
       // 缁戝畾涓婄Щ鍔ㄤ簨浠�
-      const downHandler = new Cesium.ScreenSpaceEventHandler(
-        Viewer.scene.canvas
-      );
-      downHandler.setInputAction(function (movement) {
-        const pickedObject = scene.pick(movement.position);
-        if (
-          Cesium.defined(pickedObject) &&
-          Cesium.defined(pickedObject.id.plane)
-        ) {
-          selectedPlane = pickedObject.id.plane;
-          selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05);
-          selectedPlane.outlineColor = Cesium.Color.WHITE;
-          scene.screenSpaceCameraController.enableInputs = false;
-        }
-      }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
+      // const downHandler = new Cesium.ScreenSpaceEventHandler(
+      //   Viewer.scene.canvas
+      // );
+      // downHandler.setInputAction(function (movement) {
+      //   const pickedObject = scene.pick(movement.position);
+      //   if (
+      //     Cesium.defined(pickedObject) &&
+      //     Cesium.defined(pickedObject.id.plane)
+      //   ) {
+      //     selectedPlane = pickedObject.id.plane;
+      //     selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05);
+      //     selectedPlane.outlineColor = Cesium.Color.WHITE;
+      //     scene.screenSpaceCameraController.enableInputs = false;
+      //   }
+      // }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
 
-      // Release plane on mouse up
       // 缁戝畾涓嬬Щ鍔ㄤ簨浠�
-      const upHandler = new Cesium.ScreenSpaceEventHandler(
-        Viewer.scene.canvas
-      );
-      upHandler.setInputAction(function () {
-        if (Cesium.defined(selectedPlane)) {
-          selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1);
-          selectedPlane.outlineColor = Cesium.Color.WHITE;
-          selectedPlane = undefined;
-        }
-        scene.screenSpaceCameraController.enableInputs = true;
-      }, Cesium.ScreenSpaceEventType.LEFT_UP);
+      // const upHandler = new Cesium.ScreenSpaceEventHandler(
+      //   Viewer.scene.canvas
+      // );
+      // upHandler.setInputAction(function () {
+      //   if (Cesium.defined(selectedPlane)) {
+      //     selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1);
+      //     selectedPlane.outlineColor = Cesium.Color.WHITE;
+      //     selectedPlane = undefined;
+      //   }
+      //   scene.screenSpaceCameraController.enableInputs = true;
+      // }, Cesium.ScreenSpaceEventType.LEFT_UP);
       // Update plane on mouse move
-      const moveHandler = new Cesium.ScreenSpaceEventHandler(
-        Viewer.scene.canvas
-      );
-      moveHandler.setInputAction(function (movement) {
-        if (Cesium.defined(selectedPlane)) {
-          const deltaY = movement.startPosition.y - movement.endPosition.y;
-          targetY += deltaY;
-        }
-      }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
+      // const moveHandler = new Cesium.ScreenSpaceEventHandler(
+      //   Viewer.scene.canvas
+      // );
+      // moveHandler.setInputAction(function (movement) {
+      //   if (Cesium.defined(selectedPlane)) {
+      //     const deltaY = movement.startPosition.y - movement.endPosition.y;
+      //     targetY += deltaY;
+      //     console.log("targetY----",targetY)
+      //   }
+      // }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
       function createPlaneUpdateFunction(plane) {
         return function () {
           plane.distance = targetY;
           return plane;
         };
       }
+      //鑾峰彇鍒囬潰鐨則ype // 涓娿�佷笅銆佸乏銆佸彸銆佸墠銆佸悗
+      function getType4Plane(plane) {
+        var m_type;
+        var normal = plane._normal;
+        var x = normal.x;
+        var y = normal.y;
+        var z = normal.z;
+        if (x == 1 && y == 0 && z == 0) {
+          m_type = 'left';
+        }
+        else if (x == -1 && y == 0 && z == 0) {
+          m_type = 'right';
+        }
+        else if (x == 0 && y == 1 && z == 0) {
+          m_type = 'behind';
+        }
+        else if (x == 0 && y == -1 && z == 0) {
+          m_type = 'front';
+        }
+        else if (x == 0 && y == 0 && z == -1) {
+          m_type = 'top';
+        }
+        return m_type;
+      }
+      function createPlaneUpdateFunction_box(plane, type, origin) {
+        return function () {
+          var num_x = window.localStorage.getItem('slider_x') / 100000;
+          var num_y = window.localStorage.getItem('slider_y') / 100000;
+          var num_z = window.localStorage.getItem('slider_z')/1.5;//璇诲彇婊戝姩鏉″��
+          var origin_degree = cartesian3ToDegrees(origin);
+          var target_degree_x = [origin_degree[0] + num_x, origin_degree[1], +origin_degree[2]];
+          var target_degree_y = [origin_degree[0], origin_degree[1] + num_y, +origin_degree[2]];
+          var target_degree_z = [origin_degree[0], origin_degree[1], +origin_degree[2] + num_z];
+          var m_dis_x = Cesium.Cartesian3.distance(origin, Cesium.Cartesian3.fromDegrees(target_degree_x[0], target_degree_x[1], target_degree_x[2]));
+          var m_dis_y = Cesium.Cartesian3.distance(origin, Cesium.Cartesian3.fromDegrees(target_degree_y[0], target_degree_y[1], target_degree_y[2]));
+          var m_dis_z = Cesium.Cartesian3.distance(origin, Cesium.Cartesian3.fromDegrees(target_degree_z[0], target_degree_z[1], target_degree_z[2]));
+          createPlanePos(origin_degree, num_x, num_y, num_z);
+          let distance = 140;
+          if (type == 'left') {
+            if (num_x < 0) {
+              plane.distance = distance - (-m_dis_x);
+              return plane;
+            } else {
+              plane.distance = distance - m_dis_x
+              return plane;
+            }
+          }
+          else if (type == 'behind') {
+            if (num_y < 0) {
+              plane.distance = distance - (-m_dis_y);
+              return plane;
+            } else {
+              plane.distance = distance - m_dis_y;
+              return plane;
+            }
+          }
+          else if (type == 'right') {
+            if (num_x < 0) {
+              plane.distance = distance - m_dis_x;
+              return plane;
+            } else {
+              plane.distance = distance - (-m_dis_x);
+              return plane;
+            }
+          }
+          else if (type == 'front') {
+            if (num_y < 0) {
+              plane.distance = distance - m_dis_y;
+              return plane;
+            } else {
+              plane.distance = distance - (-m_dis_y);
+              return plane;
+            }
+          }
+          else if (type == 'top') {
+            if (num_z < 0) {
+              plane.distance =  m_dis_z;
+              // console.log('num_z=========',num_z)
+              // console.log('m_dis_z=========',m_dis_z)
+              // plane.distance = distance - m_dis_z;
+              return plane;
+            } else {
+              // plane.distance = 100;
+              plane.distance = distance - (-m_dis_z);
+              return plane;
+            }
+          }
+          return plane;
+        };
+      }
+
+      function createPlanePos(origin, x, y, z) {
+        var clipbox=Viewer.entities.getById('ClopBox');
+        if (clipbox) {
+          clipbox.position=new Cesium.CallbackProperty(function () {
+            return Cesium.Cartesian3.fromDegrees(origin[0] + x, origin[1] + y, +origin[2] + z);//瀹炴椂杩斿洖褰撳墠鐩掑瓙鐨勪綅缃�
+          }, false);
+        }
+      }
+      function cartesian3ToDegrees(cartesian3) {
+        var ellipsoid = Viewer.scene.globe.ellipsoid;
+        var cartographic = ellipsoid.cartesianToCartographic(cartesian3);
+        var lat = Cesium.Math.toDegrees(cartographic.latitude);
+        var lng = Cesium.Math.toDegrees(cartographic.longitude);
+        var alt = cartographic.height;
+        var pos = [lng, lat, alt];
+        return pos;
+      }
+
     },
 
     //鍏抽棴绠¢亾淇℃伅寮圭獥
@@ -2070,6 +2235,7 @@
       var std = data.result;
       var that = this;
       var checkKey = [];
+      let checkedLayers = [];
       var val = std.filter((str) => {
         if (str.type == 1) {
           return str;
@@ -2078,11 +2244,15 @@
           if (str.isShow == 1) {
             checkKey.push(str.id);
             that.setAddLayers(str);
+            if (str.serveType == "WMS" && str.url){
+              checkedLayers.push(str);
+            }
           }
           return str;
         }
       });
-
+      //瀛樺偍閫変腑鍥惧眰
+      sessionStorage.setItem("checkedLayers",JSON.stringify(checkedLayers));
       var res = this.setTreeData(val);
 
       for (var i in res) {

--
Gitblit v1.9.3