Explorar el Código

整治总览上图的图斑添加名称显示

maxiaoxiao hace 5 meses
padre
commit
fc9544261e
Se han modificado 2 ficheros con 45 adiciones y 16 borrados
  1. 28 8
      src/utils/MapHelper/help.js
  2. 17 8
      src/views/LandConsolidation/components/sdgk.vue

+ 28 - 8
src/utils/MapHelper/help.js

@@ -59,8 +59,9 @@ export function loadGeoJSON(geom, yanse, adata, fun) {
         offset: new Cesium.HeadingPitchRange(0, -45),
       });
     fun(data)
-    if (!geojson.type.includes("Polygon")) {
-      data.entities.values.forEach((entity, ei) => {
+    console.log(adata.name, '---')
+    data.entities.values.forEach((entity, ei) => {
+      if (!geojson.type.includes("Polygon")) {
         if (entity.billboard) {
           entity.billboard = new Cesium.BillboardGraphics({
             image: "@/.././static/images/flypng/hos_point.png",
@@ -69,13 +70,32 @@ export function loadGeoJSON(geom, yanse, adata, fun) {
             scale: 1.0,
             pixelOffset: new Cesium.Cartesian2(0, -16),
           });
-          // entity.point = {
-          //   pixelsize: 20,
-          //   color: Cesium.Color.fromCssColorString(colors),
-          // };
         }
-      });
-    }
+        // entity.point = {
+        //   pixelsize: 20,
+        //   color: Cesium.Color.fromCssColorString(colors),
+        // };
+      }
+      if (adata.name && entity.polygon) {
+        let center = getCentroid(geojson, ei);
+        entity.position = Cesium.Cartesian3.fromDegrees(
+          center[0],
+          center[1],
+          adata.lab_height || 0
+        );
+        entity.label = {
+          font: "bolder 18px sans-serif",
+          style: Cesium.LabelStyle.FILL_AND_OUTLINE,
+          text: adata.name, //图标名称
+          fillColor: Cesium.Color.fromCssColorString(yanse),
+          pixelOffset: new Cesium.Cartesian2(0, -20),
+          zIndex: 3,
+        };
+        console.log(entity, adata.name, '---')
+      }
+
+    });
+
 
   });
   // let polygon = Cesium.GeoJsonDataSource.load(geojson, {

+ 17 - 8
src/views/LandConsolidation/components/sdgk.vue

@@ -213,14 +213,23 @@ export default {
       newVal.forEach((res, ri) => {
         let color = legends[res.type].color;
         if (res.geom)
-          loadGeoJSON(res.geom, color, { isfly: false }, (data) => {
-            geoSources[ri] = data;
-            data.name = res.type = 0 ? "sdqy" : "zzqy";
-            // data.show = false;
-            // data.entities.values.forEach((entity) => {
-            //   entity.properties = { type: "图斑上图", id: res.id };
-            // });
-          });
+          loadGeoJSON(
+            res.geom,
+            color,
+            {
+              isfly: false,
+              name: res.name,
+              lab_height: res.type * 5,
+            },
+            (data) => {
+              geoSources[ri] = data;
+              data.name = res.type = 0 ? "sdqy" : "zzqy";
+              // data.show = false;
+              // data.entities.values.forEach((entity) => {
+              //   entity.properties = { type: "图斑上图", id: res.id };
+              // });
+            }
+          );
       });
     },
     sourcesshow(isshow) {