Explorar o código

上图公共提取

maxiaoxiao hai 9 meses
pai
achega
b6c3a48b79

+ 3 - 1
src/utils/MapHelper/help.js

@@ -35,7 +35,9 @@ export function loadGeoJSON(geom, yanse, adata, fun) {
     stroke: yanse
       ? Cesium.Color.fromCssColorString(yanse)
       : Cesium.Color.RED.withAlpha(0),
-    fill: Cesium.Color.fromCssColorString(yanse).withAlpha(adata.fill_a || 0.4), //Cesium.Color.fromCssColorString("rgba(10, 95, 152, 0.4)"), //注意:颜色必须大写,即不能为blue
+    fill: yanse
+      ? Cesium.Color.fromCssColorString(yanse).withAlpha(adata.fill_a || 0.4)
+      : Cesium.Color.WHITE.withAlpha(0), //Cesium.Color.fromCssColorString("rgba(10, 95, 152, 0.4)"), //注意:颜色必须大写,即不能为blue
     strokeWidth: adata.sw || 2,
   })
   polygon.then((data) => {

+ 45 - 25
src/views/cockpit/common/VectorSpace/BoxCommonVector.vue

@@ -133,7 +133,7 @@ import * as tdsy from "@/views/cockpit/js/tdsy";
 
 import * as wellknown from "wellknown";
 import * as turf from "@turf/turf";
-
+import { loadGeoJSON } from "@/utils/MapHelper/help.js";
 import CockpitVector from "@/components/Query/clickQuery/CockpitVector.vue";
 let BoxCommonVector_entity = null;
 let layerSources = {};
@@ -224,29 +224,30 @@ export default {
         })
       );
       tdsy.layersObj[lid] = layer;
-      this.loadGeoJSON(geom, lid);
-    },
-    loadGeoJSON(geojson, id, yanse, isfly = true) {
-      let polygon = Cesium.GeoJsonDataSource.load(geojson, {
-        clampToGround: true,
-        stroke: yanse
-          ? Cesium.Color.fromCssColorString(yanse)
-          : Cesium.Color.RED.withAlpha(0),
-        fill: yanse
-          ? Cesium.Color.fromCssColorString(yanse).withAlpha(0.3)
-          : Cesium.Color.WHITE.withAlpha(0),
-        strokeWidth: isfly ? 5 : 2,
-        zIndex: isfly ? 10 : 5,
-      });
-      polygon.then(function (dataSource) {
-        viewer.dataSources.add(dataSource);
-        layerSources[id] = dataSource;
-        if (isfly)
-          viewer.flyTo(dataSource, {
-            offset: new Cesium.HeadingPitchRange(0, -45),
-          });
+      loadGeoJSON(geom, null, { isfly: true }, (data) => {
+        layerSources[lid] = data;
       });
     },
+    // loadGeoJSON(geojson, id, yanse, isfly = true) {
+    //   let polygon = Cesium.GeoJsonDataSource.load(geojson, {
+    //     clampToGround: true,
+    //     stroke: yanse
+    //       ? Cesium.Color.fromCssColorString(yanse)
+    //       : Cesium.Color.RED.withAlpha(0),
+    //     fill: yanse
+    //       ? Cesium.Color.fromCssColorString(yanse).withAlpha(0.3)
+    //       : Cesium.Color.WHITE.withAlpha(0),
+    //     strokeWidth: isfly ? 5 : 2,
+    //   });
+    //   polygon.then(function (dataSource) {
+    //     viewer.dataSources.add(dataSource);
+    //     layerSources[id] = dataSource;
+    //     if (isfly)
+    //       viewer.flyTo(dataSource, {
+    //         offset: new Cesium.HeadingPitchRange(0, -45),
+    //       });
+    //   });
+    // },
     multiPolygonToPolygons(multiPolygon) {
       const polygons = [];
       multiPolygon.coordinates.forEach((polygonCoordinates) => {
@@ -408,7 +409,14 @@ export default {
               offset: new Cesium.HeadingPitchRange(0, -45),
             });
           } else {
-            this.loadGeoJSON(item.geom, "h_" + item.index, "#ff0000");
+            loadGeoJSON(
+              item.geom,
+              "#ff0000",
+              { isfly: true, sw: 5 },
+              (data) => {
+                layerSources["h_" + item.index] = data;
+              }
+            );
           }
         }
       }
@@ -631,8 +639,15 @@ export default {
       // else this.draw_vector_tdgy_gy_jd(newVal);
       else {
         newVal.forEach((res, index) => {
+          res.type = "图斑上图";
           res.index = index;
-          if (res.geom) this.loadGeoJSON(res.geom, index, "#55A1E3", false);
+          if (res.geom)
+            loadGeoJSON(res.geom, "#55A1E3", {}, (data) => {
+              layerSources[index] = data;
+              data.entities.values.forEach((entity) => {
+                entity.properties = res;
+              });
+            });
         });
       }
     },
@@ -643,7 +658,12 @@ export default {
         // tdsy.layersObj[newVal].show = true;
       }
       if (oldVal && layerSources[oldVal]) {
-        viewer.dataSources.remove(layerSources[oldVal]);
+        try {
+          viewer.dataSources.remove(layerSources[oldVal]);
+        } catch (error) {
+          console.log(error);
+        }
+
         layerSources[oldVal] = null;
       }
       console.log(newVal, oldVal, "----");

+ 0 - 1
src/views/farmlandProtection/components/interDetails.vue

@@ -176,7 +176,6 @@ export default {
       let id = "h_" + item.id;
       this.tempdataLayerId = id;
       loadGeoJSON(item.geom, "#ff0000", { isfly: true }, (data) => {
-        console.log("--sx;,ksc");
         layerSources[id] = data;
       });
     },