月球大数据地理空间分析展示平台-【前端】-月球2期前端
Surpriseplus
2023-10-10 616b8ab8998bfbec69929152612dc94d3112c2a9
src/assets/js/Map/server.js
@@ -4,6 +4,7 @@
import store from "@/store";
const server = {
  layerList: [],
  graticules: null,
  addTreeData(treeNode) {
    if (!treeNode.checked) {
      this.delLayer(treeNode.id);
@@ -14,6 +15,31 @@
      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;
    }
  },
  //代理地址
@@ -243,7 +269,6 @@
      tilingScheme: new Cesium.GeographicTilingScheme({
        ellipsoid: Cesium.Ellipsoid.MOON,
      }),
    });
    Viewer.terrainProvider = window.terrainLayer;
    Viewer.scene.globe.terrainExaggeration = 1.0000001;
@@ -336,7 +361,7 @@
            );
            break;
          case "tileset":
            window.Viewer.scene.primitives.remove(e.layerData)
            window.Viewer.scene.primitives.remove(e.layerData);
            break;
        }
        this.layerList.splice(i, 1);
@@ -359,24 +384,28 @@
          );
          break;
        case "tileset":
          window.Viewer.scene.primitives.remove(e.layerData)
          window.Viewer.scene.primitives.remove(e.layerData);
          break;
      }
      this.layerList.splice(i, 1);
    });
  },
  //加载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)
    });
    var that = this;
    var getFeatureInfoFormat = new SmartEarth.Cesium.GetFeatureInfoFormat(
      "html",
      null,
      function (html) {
        that.getFeatureInfo(html);
      }
    );
    let layer = new SmartEarth.Cesium.WebMapServiceImageryProvider({
      url: url,
      layers: res.tab,
      getFeatureInfoParameters: { info_format: 'text/html' },
      getFeatureInfoParameters: { info_format: "text/html" },
      enablePickFeatures: true,
      getFeatureInfoFormats: [getFeatureInfoFormat],
      parameters: {
@@ -390,17 +419,28 @@
    });
    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)
    });
    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;
    }
    let wmslayer = new SmartEarth.Cesium.WebMapServiceImageryProvider({
      url: url,
      layers: layer.toString(),
      getFeatureInfoParameters: { info_format: 'text/html' },
      getFeatureInfoParameters: { info_format: "text/html" },
      enablePickFeatures: true,
      getFeatureInfoFormats: [getFeatureInfoFormat],
      parameters: {
@@ -417,35 +457,46 @@
    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;
    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 (!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;