suerprisePlus
2024-06-27 6ae4841b48665145aa469d574fbadb988a9c498c
src/assets/js/map/modelLayer.js
@@ -1,7 +1,10 @@
import {
  getPublickey,
  getSecurityLogin,
  getListCanview
  getListCanview,
  getmapConfig,
  getQueryEentity,
  getSettingPublickey
} from "../../../api/modelBase.js";
import JSEncrypt from "jsencrypt";
import store from "../../../store/index.js";
@@ -14,35 +17,42 @@
  modelBase: null,
  dbid: null,
  geom: null,
  // 获取Publickey
  layers: null,
  publickey: null,
  init() {
    this.modelBase = config.modelBase;
    getPublickey().then((response) => {
      const password = this.modelBase.password;
      const userId = this.modelBase.userId;
      const publickey = response.data;
      const encrypt = new JSEncrypt();
      encrypt.setPublicKey(publickey);
      let encrypted = encrypt.encrypt(password.substring(0, 50)) + "";
      let submit = {
        userid: userId,
        password: encrypted
      };
      this.setLoginsubmit(submit);
    this.getSettingPublicKey();
    const token = getToken();
    if (token) {
      this.getModelLayerList();
    } else {
      getPublickey().then((response) => {
        const password = this.modelBase.password;
        const userId = this.modelBase.userId;
        this.publickey = response.data;
        const encrypt = new JSEncrypt();
        encrypt.setPublicKey(this.publickey);
        let encrypted = encrypt.encrypt(password.substring(0, 50)) + "";
        let submit = {
          userid: userId,
          password: encrypted
        };
        this.setLoginsubmit(submit);
      });
    }
  },
  getSettingPublicKey() {
    getSettingPublickey().then((response) => {
      this.publickey = response.data;
    });
  },
  // 获取Token
  setLoginsubmit(res) {
    // const token = getToken();
    // if (token) {
    getSecurityLogin(res).then((response) => {
      const val = response.data.token;
      setToken(val);
      this.getModelLayerList();
    });
    // } else {
    //   this.getModelLayerList( );
    // }
  },
  // 获取列表
  getModelLayerList() {
@@ -56,19 +66,87 @@
      });
      if (obj.length > 0) {
        this.dbid = obj[0].dbid;
        this.getmapConfig();
      }
    });
    this.setLayerQuery();
  },
  getmapConfig() {
    getmapConfig({
      dbid: this.dbid,
      token: getToken()
    }).then((response) => {
      if (response.code != 200) return;
      const layers = response.data.layers;
      this.layers = layers;
      for (var i in layers) {
        if (layers[i].name == "建筑") {
          const url = layers[i].lod_url["3d"][""];
          mapServer.addServer({
            sourceType: "Tileset",
            url: url,
            id: layers[i].id
          });
        }
      }
    });
  },
  getQueryGroupBy(layer, filed, ction) {
    const layerId = this.layers.filter((item) => {
      if (item.name == layer) {
        return item;
      }
    });
    if (layerId.length <= 0) {
      return;
    }
    const url =
      config.modelBase.url +
      config.modelBase.geo +
      "/entitydbdata/query/entity";
    const obj = [
      {
        type: "count",
        field: filed,
        outfield: "count_" + filed
      }
    ];
    axios
      .post(
        url,
        {
          layerid: layerId[0].id,
          dbid: this.dbid,
          token: getToken(),
          statistics: JSON.stringify(obj),
          containCount: true,
          groupby: filed
        },
        {
          headers: {
            Authorization: getToken(),
            "Content-Type": "application/x-www-form-urlencoded"
          }
        }
      )
      .then((response) => {
        ction(response);
      })
      .catch((error) => {
        error;
      });
  },
  setLayerQuery() {
    const token = getToken();
    this.geom = mapConfig.setPointToCrical(120.27, 14.79, null);
    const obj = {
      type: "FeatureCollection",
      totalFeatures: 1086,
      features: [this.geom]
    };
    // const obj = {
    //   type: "FeatureCollection",
    //   totalFeatures: 1086,
    //   features: [this.geom]
    // };
    // earthCtrl.factory.createFeatureLayer({
    //   sourceType: "geojson",
    //   url: obj,
@@ -146,7 +224,6 @@
        }
      )
      .then((response) => {
        console.log("List", response);
        that.setLayerFilter(response.data.data.items);
      });
  },
@@ -161,18 +238,16 @@
    const a = [];
    // rs.filter((item) => {
    //   if (item.targettype == "军事目标") {
    //     console.log(item);
    //     // a.push(["${id} === '" + item.sid + "'",  "color('#FF0000', 0.5)"]);
    //   }
    // });
    //
    a.push([
      // "${id} == '1_b092c0c26de646b984801e29fba37f82'",
      '${id} == 1_b092c0c26de646b984801e29fba37f82',
       'color("purple", 0.5)'
      "${id} == 1_b092c0c26de646b984801e29fba37f82",
      'color("purple", 0.5)'
    ]);
    a.push(["true", "color('#E8F1F2', 0.5)"]);
    console.log(   tileset);
    tileset.style = new Cesium.Cesium3DTileStyle({
      // color: "vec4(1.0,1.0,1.0, 1.0)", // 红色
      color: {
@@ -180,18 +255,16 @@
          [
            // "${id} == '1_b092c0c26de646b984801e29fba37f82'",
            '${targettype} == "军事目标"',
             'color("purple", 0.5)'
            'color("purple", 0.5)'
          ]
        ]
      }
    });
    //   window.Cesium.when(tileset.readyPromise, function(tileset) {
    //     var tilesetId = tileset.id;
    //     console.log('Tileset ID: ' + tilesetId);
    // });
    //   tileset.readyPromise.then( (item)=> {
    //     tileset.tileVisible.addEventListener( (tile)=> {
    //       console.log(tile);
    //     })
    //   })
  }