Procházet zdrojové kódy

修复场景页面元素提交拦截BUG

DESKTOP-6LTVLN7\Liumouren před 3 týdny
rodič
revize
ce9fa3e0cb
2 změnil soubory, kde provedl 28 přidání a 24 odebrání
  1. 23 23
      src/components/wgn/controlPanel.vue
  2. 5 1
      src/views/wgn/Example.vue

+ 23 - 23
src/components/wgn/controlPanel.vue

@@ -607,8 +607,9 @@ export default {
       return null;
     },
     /**
-     * 发送前校验:元素个数(numberOf)与入参 FeatureCollection.features;
-     * 点线面参数按 elementTypes 声明顺序与要素几何类型一一对应(忽略 unit/file 等非几何项)。
+     * 发送前校验:以「元素个数」numberOf 为主,与入参 FeatureCollection.features 数量对齐;
+     * 「参数类型」elementTypes 中的 point/polyline/polygon 仅表示允许的几何类型(可多选),
+     * 不要求每种类型各来一个,也不要求与声明顺序一一对应(忽略 unit/file 等非几何项)。
      */
     validateSendGeometryParams() {
       if (!this.dmsServerItem || !Array.isArray(this.dmsServerItem.elementTypes)) {
@@ -626,17 +627,13 @@ export default {
         return { ok: true };
       }
 
+      const allowedCanonSet = new Set(geoSlots.map((s) => s.canon));
+
       const rawN = this.dmsServerItem.numberOf;
-      let expectedGeomCount = geoSlots.length;
+      let expectedGeomCount = null;
       if (rawN !== undefined && rawN !== null && rawN !== "") {
         const parsedN = typeof rawN === "number" ? rawN : Number(rawN);
         if (Number.isFinite(parsedN) && parsedN >= 0) {
-          if (parsedN !== geoSlots.length) {
-            return {
-              ok: false,
-              message: `场景元数据不一致:元素个数为 ${parsedN},点/线/面参数为 ${geoSlots.length} 个,请检查 DMS「元素个数」与「参数类型」配置`,
-            };
-          }
           expectedGeomCount = parsedN;
         }
       }
@@ -644,20 +641,22 @@ export default {
       const fc = this.jsonData;
       const features = fc && Array.isArray(fc.features) ? fc.features : [];
 
-      if (features.length > expectedGeomCount) {
-        return {
-          ok: false,
-          message: `入参几何要素过多:当前 ${features.length} 个,场景要求 ${expectedGeomCount} 个(元素个数)`,
-        };
-      }
-      if (features.length < expectedGeomCount) {
-        return {
-          ok: false,
-          message: `入参几何要素不足:当前 ${features.length} 个,场景要求 ${expectedGeomCount} 个(元素个数),请绘制或渲染足够要素`,
-        };
+      if (expectedGeomCount !== null) {
+        if (features.length > expectedGeomCount) {
+          return {
+            ok: false,
+            message: `入参几何要素过多:当前 ${features.length} 个,场景要求 ${expectedGeomCount} 个(元素个数)`,
+          };
+        }
+        if (features.length < expectedGeomCount) {
+          return {
+            ok: false,
+            message: `入参几何要素不足:当前 ${features.length} 个,场景要求 ${expectedGeomCount} 个(元素个数),请绘制或渲染足够要素`,
+          };
+        }
       }
 
-      for (let i = 0; i < geoSlots.length; i++) {
+      for (let i = 0; i < features.length; i++) {
         const f = features[i];
         const g = f && f.geometry;
         if (!g || !g.type) {
@@ -673,10 +672,11 @@ export default {
             message: `第 ${i + 1} 个几何要素类型「${g.type}」不符合场景要求,请使用点、线或面`,
           };
         }
-        if (fk !== geoSlots[i].canon) {
+        if (!allowedCanonSet.has(fk)) {
+          const allowedLabel = [...allowedCanonSet].join("、");
           return {
             ok: false,
-            message: `第 ${i + 1} 个几何要素类型错误:场景参数要求「${geoSlots[i].declared}」,当前为「${g.type}」`,
+            message: `第 ${i + 1} 个几何要素类型「${g.type}」不在场景允许的类型内,允许:${allowedLabel}`,
           };
         }
       }

+ 5 - 1
src/views/wgn/Example.vue

@@ -71,7 +71,11 @@ export default {
 
       // 定位
       viewer.camera.setView({
-        destination: SkyScenery.Cartesian3.fromDegrees(121.1, 31, 30000.0), // 设置位置
+        destination: SkyScenery.Cartesian3.fromDegrees(
+          121.10708551540051,
+          31.14836073612525,
+          30000.0
+        ), // 默认场景中心
         orientation: {
           heading: SkyScenery.Math.toRadians(0.0), // 方向
           pitch: SkyScenery.Math.toRadians(-90.0), // 倾斜角度