maxiaoxiao 11 miesięcy temu
rodzic
commit
45143de3fb
1 zmienionych plików z 23 dodań i 23 usunięć
  1. 23 23
      src/views/siteselection/components/xzjg.vue

+ 23 - 23
src/views/siteselection/components/xzjg.vue

@@ -333,9 +333,9 @@ export default {
         .then((data) => {
           viewer.dataSources.add(data);
           let entities = data.entities.values;
-          let addlabel = false;
+          // let addlabel = false;
           if (!geojson.type.includes("Polygon") || height) {
-            entities.forEach((entity) => {
+            entities.forEach((entity, ei) => {
               if (entity.billboard) {
                 entity.billboard = undefined;
                 entity.point = {
@@ -348,25 +348,25 @@ export default {
                 entity.polygon.material = Cesium.Color.WHITE;
                 entity.polygon.outlineColor = Cesium.Color.BLACK;
                 entity.polygon.outlineWidth = 1.0;
-                if (!addlabel) {
-                  let center = this.getCentroid(geojson).geometry.coordinates;
-                  console.log(center, "geojson");
-                  var polycenter = Cesium.Cartesian3.fromDegrees(
-                    center[0],
-                    center[1],
-                    height
-                  );
-                  entity.position = polycenter;
-                  entity.label = {
-                    font: "bolder 18px sans-serif",
-                    style: Cesium.LabelStyle.FILL_AND_OUTLINE,
-                    text: name, //图标名称
-                    fillColor: Cesium.Color.fromCssColorString("#fff000"),
-                    pixelOffset: new Cesium.Cartesian2(0, -20),
-                    zIndex: 3,
-                  };
-                  addlabel = true;
-                }
+                // if (!addlabel) {
+                let center = this.getCentroid(geojson, ei).geometry.coordinates;
+                console.log(center, "geojson");
+                var polycenter = Cesium.Cartesian3.fromDegrees(
+                  center[0],
+                  center[1],
+                  height
+                );
+                entity.position = polycenter;
+                entity.label = {
+                  font: "bolder 18px sans-serif",
+                  style: Cesium.LabelStyle.FILL_AND_OUTLINE,
+                  text: name, //图标名称
+                  fillColor: Cesium.Color.fromCssColorString("#fff000"),
+                  pixelOffset: new Cesium.Cartesian2(0, -20),
+                  zIndex: 3,
+                };
+                // addlabel = true;
+                // }
               }
             });
           }
@@ -382,7 +382,7 @@ export default {
           if (id == "all") _this.isshowAll = true;
         });
     },
-    getCentroid(geojson) {
+    getCentroid(geojson, eindex) {
       console.log(geojson, "jj");
       if (turf.getType(geojson) === "Feature") {
         geojson = geojson.geometry;
@@ -390,7 +390,7 @@ export default {
       if (turf.getType(geojson) === "Polygon") {
         return turf.centroid(geojson);
       } else if (turf.getType(geojson) === "MultiPolygon") {
-        let polygon = turf.polygon(geojson.coordinates[0]);
+        let polygon = turf.polygon(geojson.coordinates[eindex]);
         return turf.centroid(polygon);
       } else {
         throw new Error("Unsupported geometry type");