Browse Source

fix:代码优化

wangsisi 4 tháng trước cách đây
mục cha
commit
e608154878
2 tập tin đã thay đổi với 13 bổ sung33 xóa
  1. 7 16
      src/views/authentic/authenticMap.js
  2. 6 17
      src/views/authentic/index.vue

+ 7 - 16
src/views/authentic/authenticMap.js

@@ -382,8 +382,13 @@ class AuthenticMap {
   }
 
   //获取地块信息
-  getAreaGeometry() {
-    const features = this.kmap.getLayerFeatures();
+  getAreaGeometry(type) {
+    let features = null
+    if(type==='add') {
+      features = [mapData.point]
+    }else{
+      features = this.kmap.getLayerFeatures();
+    }
     let geometryArr = [];
     let area = 0;
     // 获取图层上的Polygon,转成geoJson用于回显
@@ -397,20 +402,6 @@ class AuthenticMap {
     return { geometryArr, area: area.toFixed(2) };
   }
 
-  getSinglePoint(){
-    let geometryArr = [];
-    let area = 0;
-    // 获取当前勾画完的地块  mapData.point
-    [mapData.point].forEach((item) => {
-      geometryArr.push({ featureWkt: new WKT().writeFeature(item) });
-      let geom = item.getGeometry().clone();
-      geom.transform(proj.get("EPSG:4326"), proj.get("EPSG:38572"));
-      let areaItem = getArea(geom);
-      area = (areaItem + areaItem / 2) / 1000;
-    });
-    return { geometryArr, area: area.toFixed(2) };
-  }
-
   /**
    address
    farmName

+ 6 - 17
src/views/authentic/index.vue

@@ -595,22 +595,11 @@ const getDetailsData = (id) => {
 };
 
 // 添加经纬度列表
-const updatePointList = () => {
-  let geometryArrCopy, areaCopy
-  if(mapData.isEditArea){
-    //编辑修改时查所有地块点位
-    const { geometryArr, area } = authenticMap.getAreaGeometry();
-    geometryArrCopy = geometryArr
-    areaCopy = area
-  }else{
-    //新建查询当前点位的地块数据
-    const { geometryArr, area } = authenticMap.getSinglePoint();
-    geometryArrCopy = geometryArr
-    areaCopy = area
-  }
-  const lastItem = geometryArrCopy[geometryArrCopy.length - 1];
+const updatePointList = (type) => {
+  const { geometryArr, area } = authenticMap.getAreaGeometry(type);
+  const lastItem = geometryArr[geometryArr.length - 1];
   formInline.geom = lastItem.featureWkt;
-  formInline.mu = areaCopy + "亩";
+  formInline.mu = area + "亩";
   let result = parseMultiPolygon(lastItem.featureWkt);
   result.pop();
   pointList.value = result;
@@ -619,7 +608,7 @@ const updatePointList = () => {
 watchEffect(() => {
   if (mapData.isEditArea) {
     isUpdata.value = false;
-    updatePointList();
+    updatePointList('edit');
   }
 });
 
@@ -633,7 +622,7 @@ watch(
       isUpdata.value = true;
     //   isRefresh.value = false;
       formInline.createDate = dateFormat(new Date(), "YYYY-mm-dd HH:MM:SS");
-      updatePointList();
+      updatePointList('add');
       authenticMap.startModify();
     }
   }