import { getPublickey, getSecurityLogin, getListCanview } from "../../../api/modelBase.js"; import JSEncrypt from "jsencrypt"; import store from "../../../store/index.js"; import { getToken, setToken } from "../../../utils/auth.js"; import mapConfig from "./mapConfig.js"; import axios from "axios"; import mapServer from "./mapServer.js"; const modelLayer = { modelBase: null, dbid: null, geom: null, // 获取Publickey 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); }); }, // 获取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() { const token = getToken(); getListCanview({ token: token }).then((response) => { const data = response.data; const obj = data.filter((item) => { if (item.name == this.modelBase.modelLayer) { return item; } }); if (obj.length > 0) { this.dbid = obj[0].dbid; } }); this.setLayerQuery(); }, setLayerQuery() { const token = getToken(); this.geom = mapConfig.setPointToCrical(120.27, 14.79, null); const obj = { type: "FeatureCollection", totalFeatures: 1086, features: [this.geom] }; // earthCtrl.factory.createFeatureLayer({ // sourceType: "geojson", // url: obj, // style: { // layerType: "polygon", // material: new SmartEarth.Cesium.ColorMaterialProperty( // new SmartEarth.Cesium.Color.fromCssColorString("#00f") // ), // outlineColor: new SmartEarth.Cesium.Color.fromCssColorString("#fff"), // outline: true // } // }); this.configTooles = { url: config.modelBase.url + config.modelBase.geo + "/entitydbdata/query/entity", layerid: "432a7d4f-b136-4649-91a3-52709db9c3ef", dbid: "a02c1f922bd64a0ea5979dbebc60d337", geometry: this.geom.geometry, start: 1, token: token, outfields: "*", containCount: true, contentType: "application/x-www-form-urlencoded" }; this.getLayerModelCount(this.configTooles); }, getLayerModelCount(res) { axios .post( res.url, { dbid: res.dbid, geometry: res.geometry, layerid: res.layerid, returnCountOnly: res.containCount, token: res.token }, { headers: { Authorization: res.token, "Content-Type": res.contentType } } ) .then((response) => { if (response.status === 200) { this.getLayerModelList(res, response.data.data); } else { this.getLayerModelList(res, 200); } }); }, getLayerModelList(res, count) { const that = this; axios .post( res.url, { dbid: res.dbid, geometry: res.geometry, layerid: res.layerid, containCount: res.containCount, token: res.token, count: count, start: 1, outfields: res.outfields }, { headers: { Authorization: res.token, "Content-Type": res.contentType } } ) .then((response) => { console.log("List", response); that.setLayerFilter(response.data.data.items); }); }, setLayerFilter(rs) { const obj = mapServer.listData.filter((item) => { if (item.type == "Tileset") { return item; } }); if (!obj) return; const tileset = obj[0].layer; 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)' ]); 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: { conditions: [ [ // "${id} == '1_b092c0c26de646b984801e29fba37f82'", '${targettype} == "军事目标"', '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); // }) // }) } }; export default modelLayer;