月球大数据地理空间分析展示平台-【前端】-月球2期前端
Surpriseplus
2023-09-15 92291bdc16443dca885956d74644f2abe04eaf6f
src/assets/js/Map/server.js
@@ -1,9 +1,10 @@
import { getToken } from "@/utils/auth";
//配置文件地址
import config from "./config";
// import config from "../../../../public/config/config";
import store from "@/store";
const server = {
  layerList: [],
  graticules: null,
  addTreeData(treeNode) {
    if (!treeNode.checked) {
      this.delLayer(treeNode.id);
@@ -15,6 +16,29 @@
    } 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
    }
  },
  //代理地址
  addProxyAddress(res) {
@@ -240,8 +264,13 @@
    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服务
@@ -338,6 +367,29 @@
      }
    });
  },
  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.layerList.splice(i, 1);
    });
  },
  //加载GeoServer-WMS服务
  setAddGeoWmsLayer(res) {
    var url = this.getLayrUrl(res);
@@ -362,8 +414,35 @@
    });
    layer.name = `Wms_Layer${res.id}`;
    let img_layer = window.Viewer.imageryLayers.addImageryProvider(layer);
    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)
    });
    let wmslayer = new SmartEarth.Cesium.WebMapServiceImageryProvider({
      url: url,
      layers: layer.toString(),
      getFeatureInfoParameters: { info_format: 'text/html' },
      enablePickFeatures: true,
      getFeatureInfoFormats: [getFeatureInfoFormat],
      parameters: {
        transparent: true,
        format: "image/png",
        srs: "EPSG:104903",
        styles: "",
      },
      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" });
  },
  getFeatureInfo(html) {
    store.state.details.showDetails = false;
    var start = html.indexOf("<caption class=\"featureInfo\">") + "<caption class=\"featureInfo\">".length;
@@ -377,6 +456,7 @@
        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(