From ecf3ad202a851caa39660ddfaa16e1bf16565b2e Mon Sep 17 00:00:00 2001
From: surprise <15810472099@163.com>
Date: 星期一, 30 十月 2023 13:51:38 +0800
Subject: [PATCH] 图层管理修改

---
 src/assets/js/Map/server.js |   94 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 70 insertions(+), 24 deletions(-)

diff --git a/src/assets/js/Map/server.js b/src/assets/js/Map/server.js
index ea9caa0..93827dd 100644
--- a/src/assets/js/Map/server.js
+++ b/src/assets/js/Map/server.js
@@ -2,17 +2,21 @@
 //閰嶇疆鏂囦欢鍦板潃
 // import config from "../../../../public/config/config";
 import store from "@/store";
+import { nextTick } from "vue";
 const server = {
   layerList: [],
   graticules: null,
   alpha: null,//閫忔槑搴�
-
+  geoLayer: [],
+  geoUrl: null,
+  wmsLayerId: null,
   addTreeData(treeNode) {
-    if (!treeNode.checked) {
-      this.delLayer(treeNode.id);
-      return;
-    }
-    
+    // if (!treeNode.checked) {
+//  debugger
+      // this.delLayer(treeNode.id);
+    // return;
+    // }
+
     this.alpha = this.getResLayersAlpha(treeNode);
     //鍒ゆ柇鏄惁涓轰唬鐞�
     if (treeNode.proxy) {
@@ -286,7 +290,7 @@
       return 1;
     } else {
       var id = std[0].id;
-      var val= null;
+      var val = null;
       var layers = window.Viewer.imageryLayers._layers;
       for (var i in layers) {
         if (layers[i].id == id) {
@@ -294,9 +298,9 @@
           return layers[i].alpha;
         }
       }
-       if(!null){
+      if (!null) {
         return 1
-       }
+      }
     }
   },
   //鍔犺浇鍦板舰鏈嶅姟
@@ -315,9 +319,9 @@
   },
   //鍔犺浇WMS鏈嶅姟
   setAddWmsLayer(res) {
-    
+
     var url = this.getLayrUrl(res);
-  
+
     var img_layer = sgworld.Creator.createImageryProvider(
       "giserver",
       "wms",
@@ -387,7 +391,7 @@
 
   //娓呴櫎鍥惧眰
   delLayer(code) {
-    
+
     this.layerList.forEach((e, i) => {
       if (e.id === code) {
         switch (e.type) {
@@ -440,11 +444,11 @@
     }
   },
   //鍔犺浇GeoServer-WMS鏈嶅姟
-  setAddGeoWmsLayer(res) {
-  this.delLayer(res.id)
+  setAddGeoWmsLayer(res, alpha) {
+    // 
     var url = res.url;
     var that = this;
-    
+    this.delLayer(res.id)
     var getFeatureInfoFormat = new SmartEarth.Cesium.GetFeatureInfoFormat(
       "html",
       null,
@@ -458,11 +462,11 @@
     } else {
       url = url;
     }
-    
+
     let layer = new SmartEarth.Cesium.WebMapServiceImageryProvider({
       url: url,
       layers: res.tab,
-      id:res.id,
+      id: res.id,
       getFeatureInfoParameters: { info_format: "text/html" },
       enablePickFeatures: true,
       getFeatureInfoFormats: [getFeatureInfoFormat],
@@ -475,13 +479,16 @@
       tileWidth: 512,
       tileHeight: 512,
     });
-    layer.name = `Wms_Layer${res.id}`;
+
     let img_layer = window.Viewer.imageryLayers.addImageryProvider(layer);
+    img_layer.name = `Wms_Layer${res.id}`;
     img_layer.id = res.id
-    img_layer.alpha = this.alpha;
+    img_layer.alpha = alpha ? alpha : 1;
     this.layerList.push({ id: res.id, layerData: img_layer, type: "wmts" });
   },
   addGeoServerMmsLayers(layer, url) {
+    this.geoLayer = layer;
+    this.geoUrl = url;
     var that = this;
     var getFeatureInfoFormat = new SmartEarth.Cesium.GetFeatureInfoFormat(
       "html",
@@ -496,8 +503,13 @@
     } else {
       url = url;
     }
+
+    if (!this.wmsLayerId) {
+      this.wmsLayerId = new Date();
+    }
     let wmslayer = new SmartEarth.Cesium.WebMapServiceImageryProvider({
       url: url,
+      id: this.wmsLayerId,
       layers: layer.toString(),
       getFeatureInfoParameters: { info_format: "text/html" },
       enablePickFeatures: true,
@@ -511,13 +523,47 @@
       tileWidth: 512,
       tileHeight: 512,
     });
-    wmslayer.name = `Wms_Layer_geo`;
-    let img_layer = window.Viewer.imageryLayers.addImageryProvider(wmslayer);
-    this.layerList.push({ id: res.id, layerData: img_layer, type: "wmts" });
-  },
 
+    let img_layer = window.Viewer.imageryLayers.addImageryProvider(wmslayer);
+    img_layer.id = this.wmsLayerId;
+    this.layerList.push({ id: this.wmsLayerId, layerData: img_layer, type: "wmts" });
+  },
+  getGeoLayerChangeAlpha(res) {
+    var std = [];
+    for (var i in this.geoLayer) {
+      if (this.geoLayer[i] != res.tab) {
+        std.push(this.geoLayer[i])
+      }
+    }
+    this.geoLayer = [];
+    this.geoLayer = std;
+    var imageLayers = window.Viewer.imageryLayers._layers;
+    for (var i in imageLayers) {
+      if (imageLayers[i].id == this.wmsLayerId) {
+
+        window.Viewer.imageryLayers.remove(imageLayers[i])
+      }
+    }
+    for (var i in this.layerList) {
+      if (this.layerList[i].id == this.wmsLayerId) {
+        this.layerList.splice(i, 1)
+      }
+    }
+    if (this.geoLayer.length > 0) {
+      this.addGeoServerMmsLayers(this.geoLayer, this.geoUrl)
+    }
+    this.setAddGeoWmsLayer(res);
+    for (var i in this.layerList) {
+      if (this.layerList[i].id == res.id) {
+        return {
+          id: i,
+          layer: this.layerList[i]
+        };
+        break;
+      }
+    }
+  },
   getFeatureInfo(html) {
-    store.state.details.showDetails = false;
     var start =
       html.indexOf('<caption class="featureInfo">') +
       '<caption class="featureInfo">'.length;

--
Gitblit v1.9.3