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 |  272 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 217 insertions(+), 55 deletions(-)

diff --git a/src/assets/js/Map/server.js b/src/assets/js/Map/server.js
index e3ceb5a..93827dd 100644
--- a/src/assets/js/Map/server.js
+++ b/src/assets/js/Map/server.js
@@ -2,18 +2,52 @@
 //閰嶇疆鏂囦欢鍦板潃
 // 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) {
       this.addProxyAddress(treeNode); //鏈変唬鐞�
     } else {
       this.addUrlAddress(treeNode); //鏃犱唬鐞�
+    }
+
+    if (this.graticules) {
+      window.Viewer.imageryLayers.raiseToTop(this.graticules.imageryLayer);
+    }
+  },
+  showlonlatLine() {
+    if (!this.graticules) {
+      SmartEarth.Cesium.Ellipsoid.WGS84 = new SmartEarth.Cesium.Ellipsoid(
+        1737400.0,
+        1737400.0,
+        1737400.0
+      );
+
+      this.graticules = new SmartEarth.Cesium.Graticules(
+        earthCtrl.Viewer,
+        SmartEarth.Cesium.Color.PALEGREEN
+      );
+      // graticules.makeCoordAxiss();
+      var that = this;
+      earthCtrl.Viewer.scene.preUpdate.addEventListener(function () {
+        that.graticules.update();
+      });
+    } else {
+      this.graticules.enabled = !this.graticules.enabled;
     }
   },
   //浠g悊鍦板潃
@@ -129,7 +163,8 @@
         this.setAddWmtsLayer(res);
         break;
       case 3: //WMS
-        this.setAddWmsLayer(res);
+        // this.setAddWmsLayer(res);
+        this.setAddGeoWmsLayer(res)
         break;
     }
   },
@@ -149,7 +184,8 @@
       case 0: //URL
         break;
       case 3: //WMS
-        this.setAddWmsLayer(res);
+        // this.setAddWmsLayer(res);
+        this.setAddGeoWmsLayer(res)
         break;
       case 4: //WFS
         break;
@@ -195,11 +231,13 @@
   },
   //鍔犺浇WMTS鏈嶅姟
   setAddWmtsLayer(res) {
+    this.delLayer(res.id);
     var url = this.getLayrUrl(res);
-    var urlTemplateImageryProvider = earthCtrl.factory.createImageryLayer({
+    let urlTemplateImageryProvider = new Cesium.WebMapTileServiceImageryProvider({
       sourceType: "wmts",
       url: url,
       layer: "",
+      id: res.id,
       format: "image/png",
       tileMatrixSetID: "GoogleCRS84Quad01",
       tileMatrixLabels: [
@@ -227,12 +265,43 @@
       tilingScheme: new Cesium.GeographicTilingScheme({
         ellipsoid: Cesium.Ellipsoid.MOON,
       }),
-    });
+    })
+    var imageLayer = window.Viewer.imageryLayers.addImageryProvider(urlTemplateImageryProvider);
+    imageLayer.id = res.id
+
+    imageLayer.alpha = this.alpha;
+    // urlTemplateImageryProvider.id = res.id
     this.layerList.push({
       id: res.id,
-      layerData: urlTemplateImageryProvider._primitive,
+      layerData: imageLayer,
       type: "wmts",
+      alpha: imageLayer,
     });
+  },
+  //鑾峰彇鍥惧眰涔嬪墠鐨勯�忔槑搴�
+  getResLayersAlpha(result) {
+    var std = this.layerList.filter(res => {
+      if (res.id == result.id) {
+        return res;
+      }
+    });
+
+    if (std.length <= 0) {
+      return 1;
+    } else {
+      var id = std[0].id;
+      var val = null;
+      var layers = window.Viewer.imageryLayers._layers;
+      for (var i in layers) {
+        if (layers[i].id == id) {
+          val = id;
+          return layers[i].alpha;
+        }
+      }
+      if (!null) {
+        return 1
+      }
+    }
   },
   //鍔犺浇鍦板舰鏈嶅姟
   setAddTearrinLayer(res) {
@@ -240,13 +309,19 @@
     var url = this.getLayrUrl(res);
     window.terrainLayer = new Cesium.CesiumTerrainProvider({
       url: url,
+      tilingScheme: new Cesium.GeographicTilingScheme({
+        ellipsoid: Cesium.Ellipsoid.MOON,
+      }),
     });
     Viewer.terrainProvider = window.terrainLayer;
+    Viewer.scene.globe.terrainExaggeration = 1.0000001;
     this.layerList.push({ id: res.id, type: "dem" });
   },
   //鍔犺浇WMS鏈嶅姟
   setAddWmsLayer(res) {
+
     var url = this.getLayrUrl(res);
+
     var img_layer = sgworld.Creator.createImageryProvider(
       "giserver",
       "wms",
@@ -316,10 +391,14 @@
 
   //娓呴櫎鍥惧眰
   delLayer(code) {
+
     this.layerList.forEach((e, i) => {
       if (e.id === code) {
         switch (e.type) {
           case "wmts":
+            window.Viewer.imageryLayers.remove(e.layerData);
+            break;
+          case "wms":
             window.Viewer.imageryLayers.remove(e.layerData);
             break;
           case "tms":
@@ -331,7 +410,7 @@
             );
             break;
           case "tileset":
-            window.Viewer.scene.primitives.remove(e.layerData)
+            window.Viewer.scene.primitives.remove(e.layerData);
             break;
         }
         this.layerList.splice(i, 1);
@@ -341,37 +420,54 @@
 
   delLayerAll() {
     this.layerList.forEach((e, i) => {
-      switch (e.type) {
-        case "wmts":
-          window.Viewer.imageryLayers.remove(e.layerData);
-          break;
-        case "tms":
-          window.Viewer.imageryLayers.remove(e.layerData);
-          break;
-        case "dem":
-          window.Viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider(
-            {}
-          );
-          break;
-        case "tileset":
-          window.Viewer.scene.primitives.remove(e.layerData)
-          break;
-      }
+      this.setRemoveLayer(e);
       this.layerList.splice(i, 1);
     });
+  },
+  setRemoveLayer(e) {
+    switch (e.type) {
+      case "wmts":
+        window.Viewer.imageryLayers.remove(e.layerData);
+        break;
+      case "tms":
+        window.Viewer.imageryLayers.remove(e.layerData);
+        break;
+      case "dem":
+        window.Viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider(
+          {}
+        );
+        break;
+      case "tileset":
+        window.Viewer.scene.primitives.remove(e.layerData);
+        break;
 
+    }
   },
   //鍔犺浇GeoServer-WMS鏈嶅姟
-  setAddGeoWmsLayer(res) {
-    var url = this.getLayrUrl(res);
-    var that = this
-    var getFeatureInfoFormat = new SmartEarth.Cesium.GetFeatureInfoFormat("html", null, function (html) {
-      that.getFeatureInfo(html)
-    });
+  setAddGeoWmsLayer(res, alpha) {
+    // 
+    var url = res.url;
+    var that = this;
+    this.delLayer(res.id)
+    var getFeatureInfoFormat = new SmartEarth.Cesium.GetFeatureInfoFormat(
+      "html",
+      null,
+      function (html) {
+        that.getFeatureInfo(html);
+      }
+    );
+    if (url.indexOf('{token}') > -1) {
+      const token = getToken();
+      url = config.proxy + url.replaceAll("{token}", token);
+    } else {
+      url = url;
+    }
+
     let layer = new SmartEarth.Cesium.WebMapServiceImageryProvider({
       url: url,
       layers: res.tab,
-      getFeatureInfoParameters: { info_format: 'text/html' },
+      id: res.id,
+      getFeatureInfoParameters: { info_format: "text/html" },
       enablePickFeatures: true,
       getFeatureInfoFormats: [getFeatureInfoFormat],
       parameters: {
@@ -383,19 +479,39 @@
       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 = alpha ? alpha : 1;
     this.layerList.push({ id: res.id, layerData: img_layer, type: "wmts" });
   },
   addGeoServerMmsLayers(layer, url) {
-    var that = this
-    var getFeatureInfoFormat = new SmartEarth.Cesium.GetFeatureInfoFormat("html", null, function (html) {
-      that.getFeatureInfo(html)
-    });
+    this.geoLayer = layer;
+    this.geoUrl = url;
+    var that = this;
+    var getFeatureInfoFormat = new SmartEarth.Cesium.GetFeatureInfoFormat(
+      "html",
+      null,
+      function (html) {
+        that.getFeatureInfo(html);
+      }
+    );
+    if (url.indexOf('{token}') > -1) {
+      const token = getToken();
+      url = config.proxy + url.replaceAll("{token}", token);
+    } 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' },
+      getFeatureInfoParameters: { info_format: "text/html" },
       enablePickFeatures: true,
       getFeatureInfoFormats: [getFeatureInfoFormat],
       parameters: {
@@ -407,39 +523,85 @@
       tileWidth: 512,
       tileHeight: 512,
     });
-    wmslayer.name = `Wms_Layer_geo`;
+
     let img_layer = window.Viewer.imageryLayers.addImageryProvider(wmslayer);
-    this.layerList.push({ id: 1001011, layerData: img_layer, type: "wmts" });
+    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;
+    var start =
+      html.indexOf('<caption class="featureInfo">') +
+      '<caption class="featureInfo">'.length;
     var end = html.indexOf("</caption>");
     var tab = html.substr(start, end - start);
-    var std = html.substr(html.indexOf('<th>'), html.lastIndexOf('</th>') - html.indexOf('<th>') + 5).replaceAll(' ', '').replaceAll('\n', '').split('</th>')
+    var std = html
+      .substr(
+        html.indexOf("<th>"),
+        html.lastIndexOf("</th>") - html.indexOf("<th>") + 5
+      )
+      .replaceAll(" ", "")
+      .replaceAll("\n", "")
+      .split("</th>");
     var gindex = null;
     for (var i = 0; i < std.length; i++) {
-      if (std[i].indexOf('gid') > -1) {
+      if (std[i].indexOf("gid") > -1) {
         gindex = i;
         break;
       }
     }
-    if (!gindex) return
-    var str = html.substr(html.indexOf('<td>'), html.lastIndexOf('</td>') - html.indexOf('<td>') + 5).replaceAll(' ', '').replaceAll('\n', '').split('</td>')
-    var gid = parseInt(str[gindex].replaceAll(
-      '<td>', ''
-    ))
-    if (gid && tab) {
 
+    if (!gindex) return;
+    var str = html
+      .substr(
+        html.indexOf("<td>"),
+        html.lastIndexOf("</td>") - html.indexOf("<td>") + 5
+      )
+      .replaceAll(" ", "")
+      .replaceAll("\n", "")
+      .split("</td>");
+    var gid = parseInt(str[gindex].replaceAll("<td>", ""));
+    if (gid && tab) {
       store.state.details = {
         gid: gid,
         tab: tab,
-        showDetails: true
-      }
+        showDetails: true,
+      };
     }
-
   },
 };
 export default server;

--
Gitblit v1.9.3