suerprisePlus
2024-06-21 fde8e3bedaf5f883f38c3a0ec33d3c6a8748d1c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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;