From f521ebc2551d468c4c478783a18d4b0714394d61 Mon Sep 17 00:00:00 2001
From: suerprisePlus <15810472099@163.com>
Date: 星期一, 14 十月 2024 15:00:13 +0800
Subject: [PATCH] 配网大屏功能优化

---
 src/components/mapOl/index.vue |   97 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 87 insertions(+), 10 deletions(-)

diff --git a/src/components/mapOl/index.vue b/src/components/mapOl/index.vue
index 6537e15..ae520c5 100644
--- a/src/components/mapOl/index.vue
+++ b/src/components/mapOl/index.vue
@@ -8,7 +8,7 @@
                 <el-form-item label="绾害:">
                     {{ formInline.lat }}
                 </el-form-item>
-                <el-form-item>
+                <el-form-item v-show="isShow">
                     <el-button type="success" icon="el-icon-plus" @click="drowPoint"></el-button>
                     <el-button type="danger" icon="el-icon-delete" @click="clearDrawPoint"></el-button>
                 </el-form-item>
@@ -34,6 +34,7 @@
 import mapData from '@/assets/js/mapSdk/mapData.js';
 import mapConfig from '../../assets/js/mapSdk/mapConfig';
 import * as turf from '@turf/turf'
+import LineString from 'ol/geom/LineString';
 export default {
     props: {
         parentData: {
@@ -44,6 +45,7 @@
     },
     data() {
         return {
+            isShow: true,
             mapol: null,
             drawLayer: null,
             formInline: {
@@ -59,6 +61,7 @@
         initOlMap() {
             const baseLayer = mapData.baseLayer;
             const vecUrl = baseLayer.sUrl + baseLayer.vecLayer + baseLayer.lUrl
+            const geo= config.geoServer;
             var vectorLayer = new TileLayer({
                 source: new XYZ({
                     url: vecUrl + config.tdToken,
@@ -70,6 +73,19 @@
                     url: cvaUrl + config.tdToken,
                 }),
             });
+            // var layer2 = new Image({
+            //     name: "Wms_Layer",
+            //     source: new ImageWMS({
+            //         crossOrigin: "anonymous",
+            //         url: geo.url + geo.wms,
+            //         params: {
+            //             FORMAT: "image/png",
+            //             VERSION: "1.1.1",
+            //             LAYERS: geo.layers[0],
+            //         },
+            //     }),
+            // });
+            // this.mapol.addLayer(layer2);
             this.mapol = new Map({
                 target: 'mapView',
                 layers: [vectorLayer, vectorLayer1],
@@ -80,28 +96,89 @@
                 }),
             });
 
-
+console.log(geo.url + geo.wms)
             var layer2 = new Image({
                 name: "Wms_Layer",
                 source: new ImageWMS({
                     crossOrigin: "anonymous",
-                    url: config.geoServer.url + config.geoServer.wms,
+                    url: geo.url + geo.wms,
                     params: {
                         FORMAT: "image/png",
                         VERSION: "1.1.1",
-                        LAYERS: 'sxpw:sxdwx',
+                        LAYERS: geo.layers[1],
                     },
                 }),
             });
             this.mapol.addLayer(layer2);
             if (this.parentData) {
-                const obj = mapConfig.getWKTParse(this.parentData)
-                this.formInline = {
-                    lon: obj.coordinates[0],
-                    lat: obj.coordinates[1],
+                if (this.parentData.indexOf('type') > -1) {
+                    const data = JSON.parse(this.parentData)[0];
+                    this.isShow = data.isShow
+                    if (data.type == 'point') {
+                        const obj = mapConfig.getWKTParse(data.val.point)
+                        this.formInline = {
+                            lon: obj.coordinates[0],
+                            lat: obj.coordinates[1],
+                        }
+                        this.addPointData(obj);
+                    } else if (data.type == 'line') {
+                        const obj = mapConfig.getWKTParse(data.val.f_location)
+                        this.formInline = {
+                            lon: obj.coordinates[0],
+                            lat: obj.coordinates[1],
+                        }
+                        this.addPointData(obj);
+                        const line = mapConfig.getWKTParse(data.val.re_position)
+                        this.addLineData(line)
+                    }
+
+                } else {
+                    const obj = mapConfig.getWKTParse(this.parentData)
+                    this.formInline = {
+                        lon: obj.coordinates[0],
+                        lat: obj.coordinates[1],
+                    }
+                    this.addPointData(obj);
                 }
-                this.addPointData(obj);
+
+
             }
+        },
+        addLineData(res) {
+            var coord = res.coordinates;
+            var geom = [];
+            coord.filter(i => {
+                geom.push(transform(
+                    i,
+                    'EPSG:4326',
+                    'EPSG:3857'
+                ))
+            })
+            var feature = new Feature({
+                type: 'LineString',
+                geometry: new LineString(geom),
+            });
+            feature.setStyle(
+                new Style({
+                    stroke: new Stroke({
+                        color: 'blue',
+                        width: 3,
+                    }),
+
+                })
+            );
+            const extent = feature.getGeometry().getExtent()
+            var source = new VectorSource();
+            source.addFeature(feature);
+            // 鍒涘缓绾跨殑鐭㈤噺鍥惧眰
+            var vectorLayer = new VectorLayer();
+            vectorLayer.setSource(source);
+            this.mapol.addLayer(vectorLayer);
+            this.mapol.getView().fit(extent, {
+                size: this.mapol.getSize(),
+                padding: [100, 100,200,100], // 鍥涗釜鏂瑰悜鐨勮竟璺濓紝鍙��
+                constrainResolution: false, // 鏄惁闄愬埗鍒嗚鲸鐜囷紝鍙��
+            });
         },
         addPointData(res) {
             const coord = res.coordinates;
@@ -162,7 +239,7 @@
                 this.formInline.lon = parseFloat(a1[0]).toFixed(6);
                 this.formInline.lat = parseFloat(a1[1]).toFixed(6);
                 var point = turf.point([this.formInline.lon, this.formInline.lat]);
-                const gPoint= mapConfig.getWKTConvert(point.geometry)
+                const gPoint = mapConfig.getWKTConvert(point.geometry)
                 this.$emit('childData', gPoint);
                 this.mapol.removeInteraction(this.draw);
             });

--
Gitblit v1.9.3