From 2a960cd2c5b88b143cea4acfaeafb96daef0f29b Mon Sep 17 00:00:00 2001
From: surprise <15810472099@163.com>
Date: 星期三, 10 一月 2024 09:47:09 +0800
Subject: [PATCH] 代码更新

---
 src/utils/request.js                    |    2 
 static/image/管道.png                     |    0 
 src/assets/img/model/上跨.png             |    0 
 static/image/上跨.png                     |    0 
 src/api/api.js                          |    7 +
 src/components/left/layerTree/Layer.vue |    5 +
 src/assets/js/Layer/mapGeo.js           |   57 ++++++++++++-
 static/data/layerData.js                |   11 ++
 src/assets/js/Layer/drawGrid.js         |  154 +++++++++++++++++++++++---------------
 src/assets/img/model/管道.png             |    0 
 src/components/menu/menulist.vue        |    2 
 11 files changed, 166 insertions(+), 72 deletions(-)

diff --git a/src/api/api.js b/src/api/api.js
index 0dcde0c..b597367 100644
--- a/src/api/api.js
+++ b/src/api/api.js
@@ -61,8 +61,11 @@
   //璇锋眰鍦板潃
   return service.get("Grid/SelectById?id=" + params);
 }
-
-
+export function Grid_Insert(params) {
+  //璇锋眰鍦板潃
+  return service.post("Grid/Insert", params);
+}
+ 
 //浜姙鐧诲綍
 // export function loginById(params) {
 //   return request.post('/sign/loginById', params);
diff --git "a/src/assets/img/model/\344\270\212\350\267\250.png" "b/src/assets/img/model/\344\270\212\350\267\250.png"
new file mode 100644
index 0000000..98d5ed6
--- /dev/null
+++ "b/src/assets/img/model/\344\270\212\350\267\250.png"
Binary files differ
diff --git "a/src/assets/img/model/\347\256\241\351\201\223.png" "b/src/assets/img/model/\347\256\241\351\201\223.png"
new file mode 100644
index 0000000..3d72288
--- /dev/null
+++ "b/src/assets/img/model/\347\256\241\351\201\223.png"
Binary files differ
diff --git a/src/assets/js/Layer/drawGrid.js b/src/assets/js/Layer/drawGrid.js
index 079b789..eb27f5a 100644
--- a/src/assets/js/Layer/drawGrid.js
+++ b/src/assets/js/Layer/drawGrid.js
@@ -1,35 +1,49 @@
 import * as turf from '@turf/turf';
 import store from '../../../store';
+import { Grid_Insert } from '@/api/api'
+import Bus from '../../../components/tools/Bus';
 var drawGrid = {
     id: "Rectangle",
+    ids: [],
+    flag: null,
     drawRect: function () {
-        this.handler = new Cesium.ScreenSpaceEventHandler(Viewer.canvas);
+        this.handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
         var points = [];
         var shape = this.renderRect(points);
         var step = 0;
         var $this = this;
 
         this.handler.setInputAction(function (e) {
-            var cartesian = Viewer.scene.pickPosition(e.position);
+            var cartesian = viewer.scene.pickPosition(e.position);
             if (!Cesium.defined(cartesian)) {
-                var ray = Viewer.camera.getPickRay(e.position);
-                cartesian = Viewer.scene.globe.pick(ray, Viewer.scene);
+                var ray = viewer.camera.getPickRay(e.position);
+                cartesian = viewer.scene.globe.pick(ray, viewer.scene);
             }
             points[step] = cartesian;
             step++;
             if (step === 3) {
                 $this.handler.destroy();
-                store.state.isshowGrid= true
+                store.state.isshowGrid = true
             }
         }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
         this.handler.setInputAction(function (e) {
-            var cartesian = Viewer.scene.pickPosition(e.startPosition);
+            var cartesian = viewer.scene.pickPosition(e.startPosition);
             if (!Cesium.defined(cartesian)) {
-                var ray = Viewer.camera.getPickRay(e.startPosition);
-                cartesian = Viewer.scene.globe.pick(ray, Viewer.scene);
+                var ray = viewer.camera.getPickRay(e.startPosition);
+                cartesian = viewer.scene.globe.pick(ray, viewer.scene);
             }
             points[2] = cartesian;
         }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
+    },
+
+    removeRect: function () {
+        var entity = Viewer.entities._entities._array;
+        for (var i = 0; i < entity.length; i++) {
+            if (entity[i].id == 'Rectangle') {
+                Viewer.entities.remove(entity[i])
+                i--
+            }
+        }
     },
     renderRect: function (points) {
         var shape = Viewer.entities.add({
@@ -42,16 +56,16 @@
                         var r2 = Cesium.Cartographic.fromCartesian(points[2]);
 
                         var p0 = turf.point([
-                          (r0.longitude * 180) / Math.PI,
-                          (r0.latitude * 180) / Math.PI
+                            (r0.longitude * 180) / Math.PI,
+                            (r0.latitude * 180) / Math.PI
                         ]);
                         var p1 = turf.point([
-                          (r1.longitude * 180) / Math.PI,
-                          (r1.latitude * 180) / Math.PI
+                            (r1.longitude * 180) / Math.PI,
+                            (r1.latitude * 180) / Math.PI
                         ]);
                         var p2 = turf.point([
-                          (r2.longitude * 180) / Math.PI,
-                          (r2.latitude * 180) / Math.PI
+                            (r2.longitude * 180) / Math.PI,
+                            (r2.latitude * 180) / Math.PI
                         ]);
 
                         this.rectanglePoint = p1;
@@ -72,10 +86,10 @@
                         });
 
                         var coordinates = [
-                          points[0],
-                          Cesium.Cartesian3.fromDegrees(dest1.geometry.coordinates[0], dest1.geometry.coordinates[1]),
-                          points[2],
-                          Cesium.Cartesian3.fromDegrees(dest2.geometry.coordinates[0], dest2.geometry.coordinates[1])
+                            points[0],
+                            Cesium.Cartesian3.fromDegrees(dest1.geometry.coordinates[0], dest1.geometry.coordinates[1]),
+                            points[2],
+                            Cesium.Cartesian3.fromDegrees(dest2.geometry.coordinates[0], dest2.geometry.coordinates[1])
                         ];
                         return new Cesium.PolygonHierarchy(coordinates);
                     }
@@ -85,76 +99,96 @@
                 outlineColor: Cesium.Color.BLACK,
             },
         });
- 
+
         return shape;
     },
-    drawPoint: function ( res) {
-        var rect = Viewer.entities.getById(this.id);
+    drawPoint: function (res) {
+        var rect = viewer.entities.getById(this.id);
         if (!rect) return;
 
         var points = rect.polygon.hierarchy.getValue().positions;
         //var r0 = Cesium.Cartographic.fromCartesian(points[0]);
         //var r1 = Cesium.Cartographic.fromCartesian(points[1]);
         //var r2 = Cesium.Cartographic.fromCartesian(points[2]);
-        
+
         var r0 = Cesium.Cartographic.fromCartesian(points[0]);
         var r1 = Cesium.Cartographic.fromCartesian(points[1]);
         var r2 = Cesium.Cartographic.fromCartesian(points[2]);
-
         var p0 = turf.point([(r0.longitude * 180) / Math.PI, (r0.latitude * 180) / Math.PI]);
         var p1 = turf.point([(r1.longitude * 180) / Math.PI, (r1.latitude * 180) / Math.PI]);
         var p2 = turf.point([(r2.longitude * 180) / Math.PI, (r2.latitude * 180) / Math.PI]);
-
         // 鍋氭垚 3 * 4 鐨勭綉鏍�
-        var wCount =res.col, hCount = res.row;
-   
+        var wCount = res.col + 1, hCount = res.row + 1;
+        this.flag = parseInt(res.col) * parseInt(res.col);
         var wStep = turf.distance(p0, p1, { units: "meters" }) / (wCount - 1);
         var hStep = turf.distance(p1, p2, { units: "meters" }) / (hCount - 1);
 
         var wAngle = turf.bearing(p0, p1);
         var hAngle = turf.bearing(p1, p2);
         var op = { units: "meters", };
-
         var arr = [p0.geometry.coordinates];
-
-        for (var i = 1; i < wCount; i++) {
-            var dest = turf.destination(p0, wStep * i, wAngle, op);
-            arr.push(dest.geometry.coordinates);
-        }
- 
-        for (var i = 0; i < wCount; i++) {
-            var p = arr[i];
-            for (var j = 1; j < hCount; j++) {
-                var dest = turf.destination(p, hStep * j, hAngle, op);
-                arr.push(dest.geometry.coordinates);
+        this.removeRect();
+        for (var i = 1; i < hCount; i++) {
+            for (var j = 1; j < wCount; j++) {
+                var start_west, start_hest;
+                if (j == 1) {
+                    start_west = p0.geometry.coordinates;
+                } else {
+                    start_west = turf.destination(p0, wStep * (j - 1), wAngle, op).geometry.coordinates;
+                }
+                var end_west = turf.destination(p0, wStep * j, wAngle, op).geometry.coordinates;
+                var start_hest = turf.destination(start_west, hStep * i, hAngle, op).geometry.coordinates;
+                var end_hest = turf.destination(end_west, hStep * i, hAngle, op).geometry.coordinates;
+                var val = [
+                    [start_west[0], start_west[1],18],
+                    [end_west[0], end_west[1],18],
+                    [end_hest[0], end_hest[1],18],
+                    [start_hest[0], start_hest[1],18],
+                    [start_west[0], start_west[1],18]
+                ]
+                this.setInsertGridData(val, (i * j))
             }
         }
- 
-        console.log(arr);
-        // 鏄剧ず鐐�
-        // for (var i = 0; i < arr.length; i++) {
-        //     var p = arr[i];
-        //     console.log(arr[i])
-        //     Viewer.entities.add({
-        //         name: "鐐�",
-        //         show: true,
-        //         position: Cesium.Cartesian3.fromDegrees(p[0], p[1], 0),
-        //         point: {
-        //             color: Cesium.Color.RED,
-        //             pixelSize: 5,
-        //             heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
-        //             // 鏃犺濡備綍缂╂斁锛屾爣璁扮偣涓嶈鍦板舰閬尅
-        //             disableDepthTestDistance: Number.POSITIVE_INFINITY
-        //         }
-        //     });
-        // }
     },
-    setGridRowCol:function(res){
-     
-        store.state.isshowGrid= false;  
+    setGridRowCol: function (res) {
+
+        store.state.isshowGrid = false;
 
         this.drawPoint(res);
 
     },
+    async setInsertGridData(res, num) {
+        var obj =
+        {
+            "type": "Feature",
+            "properties":
+                { "ID": num, "NAME": "Area8", "REMARK": "" },
+            "geometry":
+            {
+                "type": "Polygon",
+                "coordinates": [
+                    res
+                ]
+            }
+        }
+
+        const data = await Grid_Insert({ json: JSON.stringify(obj) })
+        if (data.status == 200) {
+            this.ids.push(data.data)
+        }
+
+        if (this.flag == num) {
+            var obj = {
+                id: new Date().getTime(),
+                sourceType: 'DrawGrid',
+                name: "鏂板缓鏍肩綉",
+                style: {
+                    ids: this.ids,
+                    sourceType: 'DrawGrid',
+                }
+            }
+            Bus.$emit("addOtherData", "瀵硅薄", obj);
+        }
+    }
 };
 export default drawGrid
diff --git a/src/assets/js/Layer/mapGeo.js b/src/assets/js/Layer/mapGeo.js
index 4bc8b4c..4bc616e 100644
--- a/src/assets/js/Layer/mapGeo.js
+++ b/src/assets/js/Layer/mapGeo.js
@@ -1,7 +1,9 @@
 var source = []
+import { Grid_SelectById } from '@/api/api'
 const mapGeo = {
     source1: null,
     type: null,
+    feature: [],
     init(res) {
         if (this.type && this.type === res) {
             return this.type = null
@@ -28,7 +30,48 @@
                 break;
         }
     },
+    addGridLayer(res) {
+        var ids = res.style.ids;
+        var length = ids.length ;
 
+        this.feature = [];
+        for (var i = 0; i < length; i++) {
+            this.getGridids(ids[i], length-1, i);
+        }
+    },
+    async getGridids(id, length, index) {
+        const data = await Grid_SelectById(id)
+        if (data.status == 200) {
+            this.feature.push(data.data.features[0])
+        }
+        console.log(index,length)
+        if (index == length) {
+            var feature = {
+                "type": "FeatureCollection",
+                "name": "wangge",
+                "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
+                "features": this.feature,
+            }
+            console.log(feature);
+            this.addGridMenuGeoJson(feature)
+        }
+    },
+    addGridMenuGeoJson(res){
+        console.log(res);
+        var data = Cesium.GeoJsonDataSource.load(res, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆�
+            {
+                stroke: Cesium.Color.ORANGE, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ら鑹层��
+                fill: Cesium.Color.WHITE.withAlpha(0.2), //澶氳竟褰㈠唴閮ㄧ殑榛樿棰滆壊銆�
+                strokeWidth: 3, //鎶樼嚎鍜屽杈瑰舰杞粨鐨勯粯璁ゅ搴︺��
+            }
+        )
+        data.then((dataSource) => {
+            dataSource.name = "鏍肩綉"
+            Viewer.dataSources.add(
+                dataSource
+            );
+        })
+    },
     addZhongPoGeoJson(res) {
         var url = layerData.config.Model_URL + res.urls;
         var data = Cesium.GeoJsonDataSource.load(url, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆�
@@ -49,16 +92,16 @@
         if (this.type && this.type == res) {
             this.type = null
         }
-      
-            if (!res.type) return;
-            Viewer.dataSources.remove(Viewer.dataSources.getByName(res.type)[0])
-      
+
+        if (!res.type) return;
+        Viewer.dataSources.remove(Viewer.dataSources.getByName(res.type)[0])
+
 
     },
 
     addzhaiHaiGeoJson(res) {
-        var url1 = layerData.config.Model_URL + res.urls ;
-     
+        var url1 = layerData.config.Model_URL + res.urls;
+
         var color = Cesium.Color.fromCssColorString("rgb(255,0,255)")
         var data1 = Cesium.GeoJsonDataSource.load(url1, //瑕佸姞杞界殑 url銆丟eoJSON 瀵硅薄鎴� TopoJSON 瀵硅薄銆�
             {
@@ -74,7 +117,7 @@
             );
         })
 
-       
+
     },
 
     addZhongQuXianGeoJson(res) {
diff --git a/src/components/left/layerTree/Layer.vue b/src/components/left/layerTree/Layer.vue
index 544d5f7..1d3ee7f 100644
--- a/src/components/left/layerTree/Layer.vue
+++ b/src/components/left/layerTree/Layer.vue
@@ -100,6 +100,7 @@
 import { Op_SelectByPage, Op_Insert, Op_UpdateById, Img_SelectByPage, Img_DeleteByIds } from '../../../api/api.js'
 import model from "../../../assets/js/Layer/model";
 import mapOL from "../../../assets/js/Layer/mapOL";
+import mapGeo from "../../../assets/js/Layer/mapGeo";
 // 宸ョ▼鏍戝伐鍏�
 let _treeTool;
 function arrGroup(arr, fn) {
@@ -855,7 +856,9 @@
         mapOL.addLayerData(res);
       } else if (res.sourceType == "imgUp" && res.checked) {
         model.addImgUpLayer(res);
-      }
+      }else if(res.sourceType == "DrawGrid" && res.checked) {
+聽 聽 聽 聽 mapGeo.addGridLayer(res);
+聽 聽 聽 }
     },
     // 娣诲姞婕旂ず鍔ㄧ敾
     editDemoAnimation() {
diff --git a/src/components/menu/menulist.vue b/src/components/menu/menulist.vue
index db9dd57..ad7f48d 100644
--- a/src/components/menu/menulist.vue
+++ b/src/components/menu/menulist.vue
@@ -186,7 +186,7 @@
   background-size: 100% 100%;
   background-repeat: no-repeat;
   width: 360px;
-  height: 180px;
+  height: 230px;
   /* border-radius: 5px 5px 5px 30px; */
 }
 </style>
diff --git a/src/utils/request.js b/src/utils/request.js
index eac667c..ccfda0b 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -2,7 +2,7 @@
 import axios from "axios";
 
 const service = axios.create({
-    baseURL: layerData.config.BASE_URL, // api鐨刡ase_url
+    baseURL: layerData.config.api_url, // api鐨刡ase_url
     timeout: -1, // 璇锋眰瓒呮椂鏃堕棿
 
 });
diff --git a/static/data/layerData.js b/static/data/layerData.js
index d03623d..3908cce 100644
--- a/static/data/layerData.js
+++ b/static/data/layerData.js
@@ -14,6 +14,7 @@
         olTdtSl: 'http://t0.tianditu.com/DataServer?T=cta_w&x={x}&y={y}&l={z}&tk=',
         olTdtBZ: 'http://t0.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=',
         vidoe_URL:"http://192.168.20.83/JiangSu/Data/video/m1.mp4",
+        api_url: "http://localhost:8080/JiangSu"
     },
     modelData: [
         {
@@ -47,6 +48,16 @@
             name: '閿ユ《',
             url: '/Data/glb/閿ユ《.glb',
             imgUrl: '閿ユ《.png'
+        },{
+            id: 'md7',
+            name: '涓婅法',
+            url: '/Data/glb/涓婅法.glb',
+            imgUrl: '涓婅法.png'
+        },{
+            id: 'md8',
+            name: '绠¢亾',
+            url: '/Data/glb/绠¢亾.glb',
+            imgUrl: '绠¢亾.png'
         }
     ]
 }
\ No newline at end of file
diff --git "a/static/image/\344\270\212\350\267\250.png" "b/static/image/\344\270\212\350\267\250.png"
new file mode 100644
index 0000000..98d5ed6
--- /dev/null
+++ "b/static/image/\344\270\212\350\267\250.png"
Binary files differ
diff --git "a/static/image/\347\256\241\351\201\223.png" "b/static/image/\347\256\241\351\201\223.png"
new file mode 100644
index 0000000..3d72288
--- /dev/null
+++ "b/static/image/\347\256\241\351\201\223.png"
Binary files differ

--
Gitblit v1.9.3