maxiaoxiao 11 ماه پیش
والد
کامیت
560b3c6d96
1فایلهای تغییر یافته به همراه72 افزوده شده و 107 حذف شده
  1. 72 107
      src/views/modelStretch/index.vue

+ 72 - 107
src/views/modelStretch/index.vue

@@ -210,66 +210,26 @@ export default {
       // this.pullUp(_temp, this.form.BuildingHeight);
       this.onSubmit(_temp.geojson);
     },
-    onSubmit(geojson) {
-      let that = this;
-      that.removeEntities();
-      // if (!that.loutiInfo) {
-      //   that.$message({
-      //     message: "未查询到模型数据,请重试加载模型",
-      //     type: "warning",
-      //   });
-      //   return;
-      // }
-      // const element = that.loutiInfo;
-      // //基础高度(地形高度)加入地形后可删除
-      let jcgd = 0;
+    getjcHigeht(geojson) {
       // sampleTerrainMostDetailed
+      let gcHight = 0;
       let center = getCentroid(geojson, 0);
       console.log(center, "-center");
       var polycenter = [Cesium.Cartographic.fromDegrees(center[0], center[1])];
       Cesium.sampleTerrain(viewer.terrainProvider, 11, polycenter).then(
         (updatedPositions) => {
-          jcgd = updatedPositions[0].height;
-          console.log("))", jcgd);
+          gcHight = updatedPositions[0].height;
         }
       );
-      // //地块编码
-      // let bm = element.data.find((c) => c.label == "LANDNO");
-      // if (bm && bm.value) {
-      //   //获取模型信息
-      //   let queryBySQLParameters = {
-      //     getFeatureMode: "SQL",
-      //     datasetNames: [that.info.Minfo.datasourcename + ":项目范围"],
-      //     queryParameter: {
-      //       attributeFilter: " DKBM = '" + bm.value + "'",
-      //     },
-      //     hasGeometry: true,
-      //   };
-      //   let e = await mapQuery(
-      //     that.info.Minfo.dataurl + "/featureResults.json?returnContent=true",
-      //     queryBySQLParameters
-      //   );
-
-      //   debugger;
-      //   if (e && e.totalCount > 0) {
-      //     e.features.forEach((feature) => {
-      //       feature.fieldNames.forEach((fieldName, i) => {
-      //         if (
-      //           fieldName == "BASEH" &&
-      //           Number(feature.fieldValues[i]) > jcgd
-      //         ) {
-      //           jcgd = Number(feature.fieldValues[i]);
-      //         }
-      //       });
-      //     });
-      //   }
-      // } else {
-      //   that.$message({
-      //     message: "未找到模型基础高度,默认高程为0",
-      //     type: "warning",
-      //   });
-      // }
-
+      console.log("---", gcHight);
+      return gcHight;
+    },
+    onSubmit(geojson) {
+      let that = this;
+      that.removeEntities();
+      // //基础高度(地形高度)加入地形后可删除
+      let jcgd = 0;
+      jcgd = this.getjcHigeht(geojson);
       //顶部高度,底部高度
       let maxH = jcgd,
         minH = jcgd;
@@ -294,39 +254,7 @@ export default {
           ps.push(gom[1]);
         });
         // let id = uuidv4();
-
-        // 定义多边形的顶点(经纬度)
-        var polygonHierarchy = new Cesium.PolygonHierarchy(
-          Cesium.Cartesian3.fromDegreesArray(ps)
-        );
-
-        // 创建带有高度的多边形
-        var extrudedPolygon = new Cesium.GeometryInstance({
-          geometry: new Cesium.PolygonGeometry({
-            polygonHierarchy: polygonHierarchy,
-            height: minH, // 多边形底面的高度
-            extrudedHeight: maxH, // 拉伸到的高度
-          }),
-          attributes: {
-            color: Cesium.ColorGeometryInstanceAttribute.fromColor(
-              // Cesium.Color.CHARTREUSE.withAlpha(0.1)
-              new Cesium.Color(0.8, 0.8, 0.8, 1.0).withAlpha(1)
-            ),
-          },
-        });
-
-        // 添加到场景中
-        let Primitive = new Cesium.Primitive({
-          geometryInstances: [extrudedPolygon],
-          appearance: new Cesium.PerInstanceColorAppearance({
-            flat: true,
-          }),
-          shadows: Cesium.ShadowMode.ENABLED, // 开启阴影
-        });
-        viewer.scene.primitives.add(Primitive);
-        polygonids.push(Primitive);
-
-        // 创建多边形的边界线
+        this.addPolygon(ps, minH, maxH);
 
         let pss = [];
         // for (let index = 0; index < element.geometry.points.length; index++) {
@@ -340,28 +268,8 @@ export default {
           pss.push(gom[1]);
           pss.push(maxH);
         });
-        var boundaryPolyline = new Cesium.GeometryInstance({
-          geometry: new Cesium.PolylineGeometry({
-            positions: Cesium.Cartesian3.fromDegreesArrayHeights(pss), // 注意这里需要处理高度为0的情况,因为边界线通常在地表
-            width: 2, // 边界线的宽度
-          }),
-          attributes: {
-            color: Cesium.ColorGeometryInstanceAttribute.fromColor(
-              // Cesium.Color.CHARTREUSE.withAlpha(0.8)
-              new Cesium.Color(0.4, 0.4, 0.4, 1.0).withAlpha(1)
-            ),
-          },
-        });
-        let boundaryPolylinePrimitive = new Cesium.Primitive({
-          geometryInstances: [boundaryPolyline],
-          appearance: new Cesium.PolylineColorAppearance({
-            edgeWidth: 1,
-            // vertexFormat: Cesium.PolylineVertexFormat.POSITION_AND_COLOR,
-            vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,
-          }),
-        });
-        viewer.scene.primitives.add(boundaryPolylinePrimitive);
-        polygonids.push(boundaryPolylinePrimitive);
+        this.addPolyline(pss);
+
         // viewer.entities.add({
         //   id: id,
         //   polygon: {
@@ -377,6 +285,63 @@ export default {
         // });
       }
     },
+    addPolygon(ps, minH, maxH) {
+      // 定义多边形的顶点(经纬度)
+      var polygonHierarchy = new Cesium.PolygonHierarchy(
+        Cesium.Cartesian3.fromDegreesArray(ps)
+      );
+
+      // 创建带有高度的多边形
+      var extrudedPolygon = new Cesium.GeometryInstance({
+        geometry: new Cesium.PolygonGeometry({
+          polygonHierarchy: polygonHierarchy,
+          height: minH, // 多边形底面的高度
+          extrudedHeight: maxH, // 拉伸到的高度
+        }),
+        attributes: {
+          color: Cesium.ColorGeometryInstanceAttribute.fromColor(
+            // Cesium.Color.CHARTREUSE.withAlpha(0.1)
+            new Cesium.Color(0.8, 0.8, 0.8, 1.0).withAlpha(1)
+          ),
+        },
+      });
+
+      // 添加到场景中
+      let Primitive = new Cesium.Primitive({
+        geometryInstances: [extrudedPolygon],
+        appearance: new Cesium.PerInstanceColorAppearance({
+          flat: true,
+        }),
+        shadows: Cesium.ShadowMode.ENABLED, // 开启阴影
+      });
+      viewer.scene.primitives.add(Primitive);
+      polygonids.push(Primitive);
+    },
+    addPolyline(pss) {
+      // 创建多边形的边界线
+      var boundaryPolyline = new Cesium.GeometryInstance({
+        geometry: new Cesium.PolylineGeometry({
+          positions: Cesium.Cartesian3.fromDegreesArrayHeights(pss), // 注意这里需要处理高度为0的情况,因为边界线通常在地表
+          width: 2, // 边界线的宽度
+        }),
+        attributes: {
+          color: Cesium.ColorGeometryInstanceAttribute.fromColor(
+            // Cesium.Color.CHARTREUSE.withAlpha(0.8)
+            new Cesium.Color(0.4, 0.4, 0.4, 1.0).withAlpha(1)
+          ),
+        },
+      });
+      let boundaryPolylinePrimitive = new Cesium.Primitive({
+        geometryInstances: [boundaryPolyline],
+        appearance: new Cesium.PolylineColorAppearance({
+          edgeWidth: 1,
+          // vertexFormat: Cesium.PolylineVertexFormat.POSITION_AND_COLOR,
+          vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT,
+        }),
+      });
+      viewer.scene.primitives.add(boundaryPolylinePrimitive);
+      polygonids.push(boundaryPolylinePrimitive);
+    },
     removeEntities() {
       for (let index = 0; index < polygonids.length; index++) {
         const element = polygonids[index];