From dd7b7fbca6e6cddcd013956161fdd730c172c725 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Fri, 07 Jul 2023 15:49:48 +0800
Subject: [PATCH] 电子沙盘多边形图片更改

---
 src/utils/turfPolygon.js |  272 ++++++++++++++++++++++++++++--------------------------
 1 files changed, 140 insertions(+), 132 deletions(-)

diff --git a/src/utils/turfPolygon.js b/src/utils/turfPolygon.js
index 4952bb1..aab3663 100644
--- a/src/utils/turfPolygon.js
+++ b/src/utils/turfPolygon.js
@@ -2,158 +2,166 @@
  * @Author: shuishen 1109946754@qq.com
  * @Date: 2023-03-31 10:52:25
  * @LastEditors: shuishen 1109946754@qq.com
- * @LastEditTime: 2023-05-08 18:21:01
+ * @LastEditTime: 2023-07-07 14:34:41
  * @FilePath: \srs-police-affairs\src\utils\turfPolygon.js
- * @Description: 
- * 
- * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
+ * @Description:
+ *
+ * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
  */
-import * as turf from '@turf/turf'
+import * as turf from "@turf/turf";
 
-function getAllRegionCenter (data) {
-    let arr = []
+function getAllRegionCenter(data) {
+  let arr = [];
 
-    data.forEach(item => {
-        if (item.position && item.position.length > 0) {
-            arr.push(getRegionCenter(item.position))
-        }
-    })
-
-    arr.push(arr[0])
-
-    if (arr.length == 1) {
-        return arr[0]
-    } else if (arr.length == 2) {
-
-        return turf.centroid(turf.midpoint(turf.point(arr[0]), turf.point(arr[1]))).geometry.coordinates
-    } else {
-        arr.push(arr[0])
-
-        return turf.centroid(turf.polygon([arr])).geometry.coordinates
+  data.forEach((item) => {
+    if (item.position && item.position.length > 0) {
+      arr.push(getRegionCenter(item.position));
     }
+  });
+
+  arr.push(arr[0]);
+
+  if (arr.length == 1) {
+    return arr[0];
+  } else if (arr.length == 2) {
+    return turf.centroid(turf.midpoint(turf.point(arr[0]), turf.point(arr[1])))
+      .geometry.coordinates;
+  } else {
+    arr.push(arr[0]);
+
+    return turf.centroid(turf.polygon([arr])).geometry.coordinates;
+  }
 }
 
-function getRegionCenter (params) {
-    let arr = []
+function getRegionCenter(params) {
+  let arr = [];
 
-    params.forEach(areaArray => {
-        JSON.parse(areaArray).coordinates.forEach(item => {
-            arr.push(turf.centroid(turf.polygon([item[0]])).geometry.coordinates)
-        })
-    })
+  params.forEach((areaArray) => {
+    JSON.parse(areaArray).coordinates.forEach((item) => {
+      arr.push(turf.centroid(turf.polygon([item[0]])).geometry.coordinates);
+    });
+  });
 
-    if (arr.length == 1) {
-        return arr[0]
-    } else if (arr.length == 2) {
+  if (arr.length == 1) {
+    return arr[0];
+  } else if (arr.length == 2) {
+    return turf.centroid(turf.midpoint(turf.point(arr[0]), turf.point(arr[1])))
+      .geometry.coordinates;
+  } else {
+    arr.push(arr[0]);
 
-        return turf.centroid(turf.midpoint(turf.point(arr[0]), turf.point(arr[1]))).geometry.coordinates
-    } else {
-        arr.push(arr[0])
-
-        return turf.centroid(turf.polygon([arr])).geometry.coordinates
-    }
+    return turf.centroid(turf.polygon([arr])).geometry.coordinates;
+  }
 }
 
-export const computerCapacity = (data, type = '') => {
+export const computerCapacity = (data, type = "") => {
+  if (type != "") {
+    const center = getAllRegionCenter(data);
 
-    if (type != '') {
-
-        const center = getAllRegionCenter(data)
-
-        if (type == 'all') {
-
-            global.viewer.flyToPosition(
-                new global.DC.Position(
-                    Number(center[0] + 0.03),
-                    Number(center[1] - 0.30),
-                    Number(36000),
-                    Number(-3),
-                    Number(-45),
-                    Number(0)
-                ),
-                function () { },
-                3
-            )
-
-        } else {
-
-            global.viewer.flyToPosition(
-                new global.DC.Position(
-                    Number(center[0] + 0.0046),
-                    Number(center[1] - 0.04),
-                    Number(4000),
-                    Number(-3),
-                    Number(-45),
-                    Number(0)
-                ),
-                function () { },
-                3
-            )
-
-        }
+    if (type == "all") {
+      global.viewer.flyToPosition(
+        new global.DC.Position(
+          Number(center[0] + 0.03),
+          Number(center[1] - 0.3),
+          Number(36000),
+          Number(-3),
+          Number(-45),
+          Number(0)
+        ),
+        function () {},
+        3
+      );
     } else {
-        console.log(data, 564)
-        let pointArr = []
-        data.forEach(item => {
-            if (item.longitude && item.latitude) {
-                pointArr.push(turf.point([item.longitude, item.latitude]))
-                return
-            }
-
-            if (item.lng && item.lat) {
-                pointArr.push(turf.point([item.lng, item.lat]))
-                return
-            }
-        })
-
-        const features = turf.featureCollection(pointArr)
-
-        const scope = turf.envelope(features).bbox
-
-        // const poly = turf.polygon([[[0, 29], [3.5, 29], [2.5, 32], [0, 29]]])
-
-        console.log([[scope[0], scope[1]], [scope[2], scope[1]], [scope[2], scope[3]], [scope[0], scope[3]]])
-
-        var poly = turf.polygon([[[scope[0], scope[1]], [scope[2], scope[1]], [scope[2], scope[3]], [scope[0], scope[3]], [scope[0], scope[1]]]])
-        var scaledPoly = turf.transformScale(poly, 4)
-
-        let boxPoint = []
-        scaledPoly.geometry.coordinates[0].forEach(item => {
-            boxPoint.push(turf.point(item))
-        })
-
-        const boxFeatures = turf.featureCollection(boxPoint)
-
-        const boxScope = turf.envelope(boxFeatures).bbox
-
-        global.viewer.flyToBounds(boxScope,
-            { heading: 0, pitch: -90, roll: 0 },
-            (e) => { },
-            3
-        )
+      global.viewer.flyToPosition(
+        new global.DC.Position(
+          Number(center[0] + 0.0046),
+          Number(center[1] - 0.04),
+          Number(4000),
+          Number(-3),
+          Number(-45),
+          Number(0)
+        ),
+        function () {},
+        3
+      );
     }
-}
+  } else {
+    console.log(data, 564);
+    let pointArr = [];
+    data.forEach((item) => {
+      if (item.longitude && item.latitude) {
+        pointArr.push(turf.point([item.longitude, item.latitude]));
+        return;
+      }
 
-export const getMapBounds = (data, type = '') => {
-    let pointArr = []
+      if (item.lng && item.lat) {
+        pointArr.push(turf.point([item.lng, item.lat]));
+        return;
+      }
+    });
 
-    data.forEach(item => {
-        pointArr.push(turf.point([item.x, item.y]))
-        return
-    })
+    const features = turf.featureCollection(pointArr);
 
-    const features = turf.featureCollection(pointArr)
-
-    const scope = turf.envelope(features).bbox
+    const scope = turf.envelope(features).bbox;
 
     // const poly = turf.polygon([[[0, 29], [3.5, 29], [2.5, 32], [0, 29]]])
 
-    return scope
-}
+    console.log([
+      [scope[0], scope[1]],
+      [scope[2], scope[1]],
+      [scope[2], scope[3]],
+      [scope[0], scope[3]],
+    ]);
 
-export const getLineSpeed = (data) => {
-    var line = turf.lineString(data)
-    var length = turf.length(line, { units: 'miles' })
+    var poly = turf.polygon([
+      [
+        [scope[0], scope[1]],
+        [scope[2], scope[1]],
+        [scope[2], scope[3]],
+        [scope[0], scope[3]],
+        [scope[0], scope[1]],
+      ],
+    ]);
+    var scaledPoly = turf.transformScale(poly, 4);
 
-    return length * 1000 / 50
-}
\ No newline at end of file
+    let boxPoint = [];
+    scaledPoly.geometry.coordinates[0].forEach((item) => {
+      boxPoint.push(turf.point(item));
+    });
+
+    const boxFeatures = turf.featureCollection(boxPoint);
+
+    const boxScope = turf.envelope(boxFeatures).bbox;
+
+    global.viewer.flyToBounds(
+      boxScope,
+      { heading: 0, pitch: -90, roll: 0 },
+      (e) => {},
+      3
+    );
+  }
+};
+
+export const getMapBounds = (data, type = "") => {
+  let pointArr = [];
+
+  data.forEach((item) => {
+    pointArr.push(turf.point([item.x, item.y]));
+    return;
+  });
+
+  const features = turf.featureCollection(pointArr);
+
+  const scope = turf.envelope(features).bbox;
+
+  // const poly = turf.polygon([[[0, 29], [3.5, 29], [2.5, 32], [0, 29]]])
+
+  return scope;
+};
+
+export const getLineSpeed = (data, multiple) => {
+  var line = turf.lineString(data);
+  var length = turf.length(line, { units: "miles" });
+
+  return (length * 1000) / multiple;
+};

--
Gitblit v1.9.3