From b1e9c826c1ba48c3dc263039699636ed2ba3be4e Mon Sep 17 00:00:00 2001
From: surprise <15810472099@163.com>
Date: 星期一, 27 十一月 2023 11:16:06 +0800
Subject: [PATCH] 版本更新,图层管理添加矢量数据下载,视角高度增加放大限制

---
 src/assets/js/Map/temporaryTools.js |  203 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 184 insertions(+), 19 deletions(-)

diff --git a/src/assets/js/Map/temporaryTools.js b/src/assets/js/Map/temporaryTools.js
index 8362342..4873e60 100644
--- a/src/assets/js/Map/temporaryTools.js
+++ b/src/assets/js/Map/temporaryTools.js
@@ -1,11 +1,79 @@
 import store from "@/store";
+import { none } from "ol/centerconstraint";
+import * as turf from "@turf/turf";
+import WKT from "terraformer-wkt-parser";
 var temporaryTool = {
     isedit: false,
     removeTemporaryLayer(res) {
         var entities = window.Viewer.entities._entities._array;
         for (var i in entities) {
-            if (entities[i].id == res.id && entities[i].shpType == res.shpType) {
+            if (entities[i].id == res.id && entities[i]._shpType == res.shpType) {
                 window.Viewer.entities.remove(entities[i])
+            }
+        }
+    },
+    removeTemporaryLayerAll() {
+        var entities = window.Viewer.entities._entities._array;
+        for (var i = 0; i < entities.length; i++) {
+            if (entities[i]._shpType && entities[i]._shpType == "temporaryLayer") {
+                window.Viewer.entities.remove(entities[i])
+                i--;
+            }
+        }
+    },
+
+    getWKT(res) {
+        var geom = res.geometry;
+        var coord = null;
+    
+        switch (res.type) {
+            case "point":
+            case "label":
+                coord = turf.point([geom.lng, geom.lat]);
+                break;
+            case "polygon":
+                var std = [];
+                for (var i = 0; i < geom.length; i++) {
+                    if (i % 2 == 0) {
+                        std.push(geom[i], geom[i + 1])
+                    }
+                }
+                coord = turf.polygon([std]);
+                break;
+            case "polyline":
+                var std = [];
+                for (var i = 0; i < geom.length; i++) {
+                    if (i % 2 == 0) {
+                        std.push(geom[i], geom[i + 1])
+                    }
+                }
+                coord = turf.lineString([std]);
+                break;
+            case "rectangle":
+                coord = turf.polygon([[
+                    [geom[0], geom[1]],
+                    [geom[0], geom[3]],
+                    [geom[2], geom[3]],
+                    [geom[2], geom[1]],
+                    [geom[0], geom[1]],
+                ]]);
+                break;
+        }
+
+       return  WKT.convert(coord.geometry);
+     
+    },
+    locationTemporaryLayer(res) {
+        var entities = window.Viewer.entities._entities._array;
+        for (var i in entities) {
+            if (entities[i].id == res.id && entities[i]._shpType == res.shpType) {
+                window.Viewer.flyTo(entities[i], {
+                    offset: {
+                        heading: Cesium.Math.toRadians(0.0),
+                        pitch: Cesium.Math.toRadians(-90),
+                        range: 400
+                    }
+                });
             }
         }
     },
@@ -36,7 +104,7 @@
             heightReference = Number.POSITIVE_INFINITY;
         }
         var style;
-        if (res.style) {
+        if (res.outline) {
             style = Cesium.LabelStyle.FILL_AND_OUTLINE
         } else {
             style = Cesium.LabelStyle.FILL
@@ -69,7 +137,7 @@
                     res.outlineColor
                 ).withAlpha(res.outlineAlpha),
 
-                outlineWidth: res.outlineWidth,
+                outlineWidth: res.width,
                 scale: res.scale,
                 style: style,
                 horizontalOrigin: Cesium.HorizontalOrigin.CENTER,//瀵归綈鏂瑰紡
@@ -121,35 +189,48 @@
                 hierarchy: {
                     positions: Cesium.Cartesian3.fromDegreesArray(res.geometry),
                 },
-                material: Cesium.Color.fromCssColorString(res.metaColor).withAlpha(
-                    res.metaAlpha
+                material: Cesium.Color.fromCssColorString(res.material).withAlpha(
+                    res.materialAlpha
                 ),
-                outline: true,
+                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
+                    res.near,
+                    res.far
+                ),
+                outline: false,
+                outlineWidth: res.width,
+
                 outlineColor: Cesium.Color.fromCssColorString(
                     res.outlineColor
                 ).withAlpha(res.outlineAlpha),
+                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
             },
         });
     },
     addTemporaryPolylineLayer(res) {
         var outlinewidth = 0
         if (res.outline) {
-            outlinewidth = res.outlineWidth
-
+            outlinewidth = res.width
         }
+
         window.Viewer.entities.add({
             name: res.cnName,
             id: res.id,
             shpType: res.shpType,
+            outline: res.outline,
             polyline: {
+                outline: res.outline,
                 positions: Cesium.Cartesian3.fromDegreesArray(res.geometry),
                 width: res.width,
+                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
+                    res.near,
+                    res.far
+                ),
 
                 material: new Cesium.PolylineOutlineMaterialProperty({
                     color: Cesium.Color.fromCssColorString(res.material).withAlpha(
                         res.materialAlpha
+
                     ),
-                    // 璁剧疆涓棿闂撮殭鐨勯鑹�
                     outlineWidth: outlinewidth,
                     outlineColor: Cesium.Color.fromCssColorString(res.outlineColor).withAlpha(
                         res.outlineAlpha
@@ -161,8 +242,7 @@
         });
     },
     addTemporaryRectangleLayer(res) {
-
-        const rectangle = new Cesium.Entity({
+        window.Viewer.entities.add({
             name: res.cnName,
             id: res.id,
             shpType: res.shpType,
@@ -171,16 +251,20 @@
                     res.geometry[1],
                     res.geometry[2],
                     res.geometry[3]),
-                material: Cesium.Color.fromCssColorString(res.metaColor).withAlpha(
-                    res.metaAlpha
+                material: Cesium.Color.fromCssColorString(res.material).withAlpha(
+                    res.materialAlpha
+                ),
+                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
+                    res.near,
+                    res.far
                 ),
                 outlineColor: Cesium.Color.fromCssColorString(
                     res.outlineColor
                 ).withAlpha(res.outlineAlpha),
-
+                outlineWidth: res.width,
+                outline: res.outline
             }
-        });
-        window.Viewer.entities.add(rectangle)
+        })
     },
 
     getEntityObj(res) {
@@ -204,6 +288,12 @@
                 case 'polyline':
                     obj = this.getPolylineEntityObj(entity);
                     break;
+                case 'rectangle':
+                    obj = this.getRectangleEntityObj(entity);
+                    break;
+                case 'polygon':
+                    obj = this.getPolygonEntityObj(entity);
+                    break;
             }
         }
         return obj;
@@ -222,11 +312,86 @@
             case 'polyline':
                 obj = this.getPolylineEntityObj(res);
                 break;
+            case 'rectangle':
+                obj = this.getRectangleEntityObj(res);
+                break;
+            case 'polygon':
+                obj = this.getPolygonEntityObj(res);
+                break;
         }
 
         store.state.temporaryLayer = obj;
         sgworld.Creator.SimpleGraphic.clear();
     },
+    getPolygonEntityObj(res) {
+        var mataColor = res.polygon.material.color._value;
+        var outlineColor = res.polygon.outlineColor._value;
+        var val = res.polygon.hierarchy.getValue().positions;
+        var geom = [];
+        for (var i in val) {
+            var coord = this.setCartesianToEightFour(val[i])
+            geom.push(coord.lng, coord.lat)
+        }
+
+        return {
+            id: this.isedit ? res.id : (new Date()).getTime(),
+            cnName: res.name,
+            materialAlpha: mataColor.alpha,
+            outlineAlpha: outlineColor.alpha,
+            material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
+            outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
+            near: res.polygon._distanceDisplayCondition._value.near,
+            far: res.polygon._distanceDisplayCondition._value.far,
+            geometry: geom,
+            type: 'polygon',
+            shpType: 'temporaryLayer',
+            layerType: '澶氳竟褰�',
+            outline: res.polygon.outline != null ? res.polygon.outline._value : false,
+            width: res.polygon.outlineWidth ? res.polygon.outlineWidth._value : 1,
+        }
+    },
+
+
+
+
+    getRectangleEntityObj(res) {
+        var mataColor = res.rectangle.material.color._value;
+        var outlineColor = res.rectangle.outlineColor._value;
+        var west = Cesium.Math.toDegrees(
+            res.rectangle._coordinates.getValue().west
+        ); // 鏍规嵁寮у害鑾峰彇鍒扮粡搴�
+        var east = Cesium.Math.toDegrees(
+            res.rectangle._coordinates.getValue().east
+        ); // 鏍规嵁寮у害鑾峰彇鍒扮含搴�
+        var north = Cesium.Math.toDegrees(
+            res.rectangle._coordinates.getValue().north
+        ); // 鏍规嵁寮у害鑾峰彇鍒扮粡搴�
+        var south = Cesium.Math.toDegrees(
+            res.rectangle._coordinates.getValue().south
+        ); // 鏍规嵁寮у害鑾峰彇鍒扮含搴�
+        var geom = [west, south, east, north];
+        return {
+            id: this.isedit ? res.id : (new Date()).getTime(),
+            cnName: res.name,
+            material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
+            outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
+            near: res.rectangle._distanceDisplayCondition._value.near,
+            far: res.rectangle._distanceDisplayCondition._value.far,
+            materialAlpha: mataColor.alpha,
+            outlineAlpha: outlineColor.alpha,
+            outline: res.outline != null ? res.outline : false,
+            width: res.rectangle.outlineWidth._value,
+            geometry: geom,
+            rotation: res.rectangle.rotation ? res.rectangle.rotation : 0,
+            type: 'rectangle',
+            shpType: 'temporaryLayer',
+            layerType: '鐭╁舰',
+
+        }
+
+    },
+
+
     getPolylineEntityObj(res) {
         var mataColor = res.polyline.material.color._value;
         var outlineColor = res.polyline.material.outlineColor._value;
@@ -236,7 +401,6 @@
             var coord = this.setCartesianToEightFour(val[i])
             geom.push(coord.lng, coord.lat)
         }
-
         return {
             id: this.isedit ? res.id : (new Date()).getTime(),
             cnName: res.name,
@@ -251,6 +415,8 @@
             outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
             materialAlpha: mataColor.alpha,
             outlineAlpha: outlineColor.alpha,
+            near: res.polyline._distanceDisplayCondition._value.near,
+            far: res.polyline._distanceDisplayCondition._value.far,
         }
     },
     getLabelEntityObj(res) {
@@ -265,7 +431,6 @@
         if (res.label.outlineWidth && res.label.outlineWidth._value) {
             width = res.label.outlineWidth._value
         }
-
         return {
             id: this.isedit ? res.id : (new Date()).getTime(),
             cnName: res.name,
@@ -290,7 +455,6 @@
             layerType: '鏂囨湰鐐�',
         }
     },
-
     getPointEntityObj(res) {
         var mataColor = res.point.color._value;
         var outlineColor = res.point.outlineColor._value;
@@ -312,6 +476,7 @@
             layerType: '鍩烘湰鐐�',
             heightReference: res.point.disableDepthTestDistance != null ? false : true,
             size: res.point.pixelSize._value,
+
         }
     },
 

--
Gitblit v1.9.3