suerprisePlus
2024-12-17 5dfcbd19cd041e1f8a5fb7ed9ab694bf4de00352
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
import axios from "axios";
import mapConfig from "./mapConfig";
import * as turf from "@turf/turf";
import mapServer from "./mapServer";
import { getToken } from "../../../utils/auth";
import modelLayer from "./modelLayer";
import {
  getPublickey,
  getQueryEentity,
  getSettingPublickey,
  getQueryEentity2
} from "../../../api/modelBase.js";
import { nextTick } from "vue";
import JSEncrypt from "jsencrypt";
const layerJson = {
  layerData: null,
  url: null,
  coord: null,
  rectangularSensor: null,
  targetList: [],
  linePath: null,
  richTextPoint1: null,
  wfsLayer: null,
  dataSource: null,
  init(url) {
    this.url = url;
    this.getJsonLayer();
  },
  getJsonLayer() {
    const that = this;
    Cesium.GeoJsonDataSource.load(this.url, {
      stroke: Cesium.Color.fromCssColorString("#FFFFFF"), //多边形或线的颜色
      fill: Cesium.Color.fromCssColorString("#FFFFFF"), //多边形或线的颜色
      strokeWidth: 1, //多边形或线 宽度
      clampToGround: true //多边形或线 固定在地面上true/false
    }).then((dataSource) => {
      const entities = dataSource.entities.values;
      that.layerData = dataSource;
      entities.map((item) => {
        item.polygon.heightReference =
          Cesium.HeightReference.RELATIVE_TO_GROUND; // 贴地
        item.polygon.height = 0; // 距地高度0米
        item.polygon.extrudedHeightReference =
          Cesium.HeightReference.RELATIVE_TO_GROUND; //拉伸
        item.polygon.extrudedHeight = item.properties["ELEVATION"]; // 拉伸高度
        var polyPositions = item.polygon.hierarchy.getValue().positions;
        var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center; //中心点
        polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
        item.position = polyCenter;
        if (item.id == "965") {
          that.coord = {
            lon: item.properties["lon"]._value,
            lat: item.properties["lat"]._value
          };
        }
        item.label = {
          text: "",
          font: "500 20px Helvetica",
          scale: 1,
          style: Cesium.LabelStyle.FILL,
          fillColor: Cesium.Color.WHITE,
 
          eyeOffset: new Cesium.Cartesian3(
            0.0,
            item.polygon.extrudedHeight + 1,
            -(item.polygon.extrudedHeight + 1)
          ),
          verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
          showBackground: true,
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
            50.0,
            500.0
          ),
          backgroundColor: new Cesium.Color(26 / 255, 196 / 255, 228 / 255, 1.0) //背景顔色
        };
      });
      Viewer.dataSources.add(dataSource);
    });
  },
  setQyeryData(res) {
    // this.setTitleSetRest();
    if (res.indexOf("海军陆战队") > -1) {
      this.setQueryExtent2();
    } else if (res.indexOf("军事目标") > -1) {
      this.setQueryByFiled("军事目标", "#409EFF", false);
    } else if (res.indexOf("民宅") > -1) {
      this.setQueryByFiled("民宅", "#808080", false);
    } else if (res.indexOf("经济目标") > -1) {
      this.setQueryByFiled("经济目标", "#FFFF00", true);
    } else if (res.indexOf("堤丰") > -1) {
      // this.setQueryTF("SubicBayWeapon_wfs", "weapons", "堤丰系统");
      this.setQueryTF2("堤丰系统");
    }
  },
 
  getPublickey(res) {
    const encrypt = new JSEncrypt();
    encrypt.setPublicKey(modelLayer.publickey + "");
    return encrypt.encrypt(res);
  },
  async setQueryFlywire() {
    const obj = "ejfl = '美空军指挥中心'" + "";
    const filed = this.getPublickey(obj);
    const layer = modelLayer.layers.filter((item) => {
      if (item.name == "建筑") {
        return item;
      }
    });
    if (layer.length <= 0) return;
    const data = getQueryEentity({
      token: getToken(),
      start: 1,
      count: 0,
      containCount: true,
      layerid: layer[0].id,
      dbid: modelLayer.dbid,
      where: filed
    });
  },
  setQueryTF2(name) {
    //  const obj = "weaponname like '%堤丰系统%'" + "";
    const filed = this.getPublickey(name);
    const layer = modelLayer.layers.filter((item) => {
      if (item.name == "武器点") {
        return item;
      }
    });
    if (layer.length <= 0) return;
    getQueryEentity({
      token: getToken(),
      start: 1,
      count: 0,
      containCount: true,
      layerid: layer[0].id,
      dbid: modelLayer.dbid,
      where: filed
    }).then((response) => {
      if (response.code != 200) return;
      const geom = response.data.items[0];
      const position = [geom._x, geom._y, 0];
      const cylinder = {
        radius: 400000, //半径
        angle: 30, //扫描角度(可选)
        speed: 5, //倍速(可选)
        stackPartitions: 80, //横向网格数(可选)
        slicePartitions: 80, //纵向网格数(可选)
        wallColor: "rgba(255,255,255,0)" //扫描墙颜色(可选)
      };
      this.rectangularSensor = earthCtrl.factory.createRectangularSensor(
        position,
        cylinder
      );
 
      earthCtrl.camera.flyTo(
        113.00849464328284,
        10.437567580726105,
        1101300.7027243855,
        57,
        -45,
        0,
        2
      );
    });
  },
  setQueryByFiled(name, color) {
    const filed = this.getPublickey(name);
    var objItem = mapServer.listData.filter((item) => {
      if (item.type === "Tileset") {
        return item;
      }
    });
    if (objItem.length <= 0) return;
    var tileset = objItem[0];
    getQueryEentity({
      token: getToken(),
      start: 1,
      count: 0,
      containCount: true,
      layerid: tileset.layerId,
      dbid: modelLayer.dbid,
      where: filed
    }).then((response) => {
      if (response.code != 200) return;
      var std = [];
      const items = response.data.items;
      items.map((item) => {
        std.push(item.seid);
      });
      nextTick(() => {
        if (std.length > 0) {
          this.setTilesetColorChange(tileset, std, color);
        }
      });
    });
  },
  setQueryByFiledList(list, flag) {
    const result = list[flag];
    const name = result.name;
    const color = result.color;
    const obj = "fclass_1 = '" + name + "'" + "";
    const filed = this.getPublickey(obj);
    var objItem = mapServer.listData.filter((item) => {
      if (item.type === "Tileset") {
        return item;
      }
    });
 
    if (objItem.length <= 0) return;
    var tileset = objItem[0];
    getQueryEentity({
      token: "9ce350f238ba44fda10ddfe8b80f8967",
      start: 1,
      count: 0,
      containCount: true,
      layerid: tileset.layerId,
      dbid: modelLayer.dbid,
      where: filed
    }).then((response) => {
      if (response.code != 200) return;
      console.log("response", objItem);
      var std = [];
      const items = response.data.items;
      items.map((item) => {
        // if (item.targettype == name) {
        std.push(item.seid);
        // }.
      });
      nextTick(() => {
        if (std.length > 0) {
          this.targetList.push({
            ids: std,
            color: color,
            cname: list[flag].name
          });
        }
        flag = flag + 1;
        if (flag >= list.length) {
          this.setTilesetColorChangeTarget();
        } else {
          this.setQueryByFiledList(list, flag);
        }
      });
    });
  },
  delrichTextPoint1(){
    if (this.richTextPoint1) {
      this.richTextPoint1.deleteObject();
      this.richTextPoint1 = null;
    }
  },
  setTitleSetRest() {
    this.targetList = [];
    if (this.dataSource) {
      Viewer.dataSources.remove(this.dataSource);
      this.dataSource = null;
    }
    this.delrichTextPoint1()
    if (this.wfsLayer) {
      // this.wfsLayer.removeFromMap();
      this.wfsLayer.destroy();
    }
    if (this.linePath) {
      this.linePath.clear();
      this.linePath = null;
    }
  
    if (this.rectangularSensor) {
      this.rectangularSensor.wall.forEach((wall) => {
        Viewer.entities.remove(wall);
      });
      Viewer.entities.remove(this.rectangularSensor.item);
      this.rectangularSensor = null;
    }
    var objItem = mapServer.listData.filter((item) => {
      if (item.type === "Tileset") {
        return item;
      }
    });
    if (objItem.length <= 0) return;
    var tileset = objItem[0].layer;
    tileset.style = new Cesium.Cesium3DTileStyle({
      color: {
        evaluateColor: (feature) => {
          return new Cesium.Color.fromCssColorString("#FFFFFF");
        }
      }
    });
  },
  setTilesetColorChange(model, ids, color) {
    var tileset = model.layer;
    tileset.style = new Cesium.Cesium3DTileStyle({
      color: {
        evaluateColor: (feature) => {
          const id = feature.getProperty("id");
          if (ids.indexOf(id) > -1) {
            return new SmartEarth.Cesium.Color.fromCssColorString(color);
          }
        }
      }
    });
  },
  setTilesetColorChangeTarget(color, ids) {
    var objItem = mapServer.listData.filter((item) => {
      if (item.type === "Tileset") {
        return item;
      }
    });
    if (objItem.length <= 0) return;
    var tileset = objItem[0].layer;
    const list = this.targetList;
 
    console.log(this.targetList);
 
    tileset.style = new Cesium.Cesium3DTileStyle({
      color: {
        evaluateColor: (feature) => {
          const id = feature.getProperty("id");
          for (var i in list) {
            if (list[i].ids.indexOf(id) > -1) {
              return new SmartEarth.Cesium.Color.fromCssColorString(
                list[i].color
              );
            }
          }
          // if (ids.indexOf(id) > -1) {
          //   return new SmartEarth.Cesium.Color.fromCssColorString(color);
          // }
        }
      }
    });
  },
  setAddWfsLayer() {
    this.wfsLayer = earthCtrl.factory.createWfsLayer("polygon", {
      urls: "https://cim.smartearth.cn/SEserver/wfsserver/SubicBayWeapon_wfs",
      layer: "weapons",
      outlineColor: "#ff0000",
      alpha: 0
    });
  },
  setAddWfsJson() {
    const url = this.getQueryUrl("SubicBayWeapon_wfs", "weapons");
    const that = this;
    Cesium.GeoJsonDataSource.load(url, {
      fill: Cesium.Color.fromCssColorString("#FFFFFF00"),
      stroke: Cesium.Color.fromCssColorString("#FFFFFF00"), //多边形或线的颜色
 
      strokeWidth: 0 //多边形或线 宽度
    }).then((dataSource) => {
      that.dataSource = dataSource;
      const entities = that.dataSource.entities.values;
      entities.map((item) => {
        item.polygon._material.color =
          Cesium.Color.fromCssColorString("#FFFFFF00");
        item.polygon.heightReference =
          Cesium.HeightReference.RELATIVE_TO_GROUND; // 贴地
        item.polygon.height = 0; // 距地高度0米
        var polyPositions = item.polygon.hierarchy.getValue().positions;
        var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center; //中心点
        polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
        item.position = polyCenter;
        let positions = item.polygon.hierarchy._value.positions;
        // 设置面轮廓
        item.polyline = new Cesium.PolylineGraphics({
          positions: positions,
          clampToGround: true, // 贴地
          width: 5,
          material: Cesium.Color.fromCssColorString("#FFA500")
        });
 
        const label_name = item.name ? item.name : "";
        item.label = {
          text: label_name,
          font: "500 16x sans-serif",
          style: Cesium.LabelStyle.FILL_AND_OUTLINE, // 字体样式
          fillColor: new Cesium.Color.fromCssColorString("#FFFFFF"),
          outlineWidth: 1, // 字体外圈线宽度(同样也有颜色可设置)
          outlineColor: new Cesium.Color.fromCssColorString("#FFFFFF"),
          verticalOrigin: Cesium.VerticalOrigin.BASELINE, // 垂直位置
          pixelOffset: new Cesium.Cartesian2(0, 0), // 中心位置
          disableDepthTestDistance: Number.POSITIVE_INFINITY,
          distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
            500.0,
            3000.0
          )
          // showBackground:true,
          // backgroundColor: new Cesium.Color(26 / 255, 196 / 255, 228 / 255, 1.0) //背景顔色
        };
      });
 
      Viewer.dataSources.add(that.dataSource);
    });
  },
  getTileSet() {
    var objItem = mapServer.listData.filter((item) => {
      if (item.type === "Tileset") {
        return item;
      }
    });
    if (objItem.length <= 0) {
      return null;
    }
    return objItem[0];
  },
  setQueryExtent2(res, boolen) {
    const tileset = this.getTileSet();
    if (!tileset) {
      return;
    }
    //
    const filed = this.getPublickey(res);
    getQueryEentity({
      token: getToken(),
      start: 1,
      count: 0,
      containCount: true,
      layerid: tileset.layerId,
      dbid: modelLayer.dbid,
      where: filed
    }).then((response) => {
      if (response.code != 200) return;
      const items = response.data.items[0];
      var std = [];
      const obj_val = response.data.items.filter((rs) => {
        if (
          rs.enti_uuid ==
          "2a71136119e12b31107d47f22bc5fa29532d3113d1c184e9660b5a840bf3287c"
        ) {
          return rs;
        } else {
          std.push({
            lon: rs.lon,
            lat: rs.lat
          });
        }
      });
    response.data.items.filter((rs) => {
        if (
          rs.enti_uuid !=
          "2a71136119e12b31107d47f22bc5fa29532d3113d1c184e9660b5a840bf3287c"
        ) {
          std.push({
            lon: rs.lon,
            lat: rs.lat
          });
        }  
      });
      if (boolen) {
        this.getQueryGeomExtent(obj_val[0], tileset.layerId);
      } else {
        this.getshowQueryExtentLabel(obj_val[0],std);
      }
    });
  },
  getshowQueryExtentLabel(res, coord) {
    this.richTextPoint1 = earthCtrl.factory.createRichTextPoint(
      res.name_1,
      [res.lon, res.lat],
      {
        fontColor: "#ffff00",
        fontSize: 18
      },
      "0"
    );
 
    const center = { lon: res.lon, lat: res.lat };
    const cities =  coord;
    let pathOption = {
      width: 3, //线宽(可选)
      color: "#00ffff", //线颜色(可选),
      LightSpot: true, //是否使用光点效果(可选)
      LightSpotColor: "#ffffff", //光点颜色(可选)
      height: 100
    };
    this.linePath = earthCtrl.factory.createTrailLinePath(
      center,
      cities,
      pathOption
    );
  },
  getQueryGeomExtent(items, layerid) {
    var geom = mapConfig.setPointToCrical(items.lon, items.lat, 1);
    const token = getToken();
    const url =
      config.modelBase.url +
      config.modelBase.geo +
      "/entitydbdata/query/entity";
 
    axios
      .post(
        url,
        {
          layerid: layerid,
          dbid: modelLayer.dbid,
          geometry: JSON.stringify(geom.geometry),
          returnCountOnly: true,
          token: token
        },
        {
          headers: {
            Authorization: token,
            "Content-Type": "application/x-www-form-urlencoded"
            // 'Cookie': "token=" + token,
            // 'Token': token
          }
        }
      )
      .then((response) => {
        this.getLayerModelList(url, response.data.data, geom.geometry, layerid);
      });
  },
  getLayerModelList(url, count, geom, layerid) {
    const token = getToken();
 
    axios
      .post(
        url,
        {
          token: token,
          dbid: modelLayer.dbid,
          layerid: layerid,
          start: 1,
          count: count,
          containCount: true,
          geometry: JSON.stringify(geom)
        },
        {
          headers: {
            Authorization: token,
            "Content-Type": "application/x-www-form-urlencoded"
          }
        }
      )
      .then((response) => {
        var std = [];
        const items = response.data.data.items;
        items.map((val) => {
          std.push(val.seid);
        });
 
        nextTick(() => {
          var objItem = mapServer.listData.filter((item) => {
            if (item.type === "Tileset") {
              return item;
            }
          });
          if (objItem.length <= 0) return;
          var tileset = objItem[0];
          if (std.length <= 0) return;
          this.setTilesetColorChange(tileset, std, "#FF0000");
        });
      });
  },
  setQueryExtent(res) {
    const geom = mapConfig.setPointToCrical(res.lon, res.lat, 5000);
    var arr = [];
    const coord = geom.geometry.coordinates[0];
    coord.map((item) => {
      if (arr.length == 0) {
        arr = item;
      } else {
        arr = [...arr, ...item];
      }
    });
    arr = arr.toString().replaceAll(",", " ");
    this.getQuery(this.url, arr, this.layerData);
  },
  getQuery(url, area, layer) {
    const entity = layer.entities.values;
    entity.filter((rs) => {
      rs.polygon.material = new Cesium.Color.fromCssColorString("#FFFFFF");
    });
    axios
      .get(url, {
        params: {
          version: "1.3.0",
          request: "GetFeature",
          typename: "GeoEntity",
          propertyname: "*",
          format: "json",
          filter: `<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:Intersects><ogc:PropertyName /><gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList>${area}</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></ogc:Intersects></ogc:Filter>`
        }
      })
      .then((res) => {
        const obj = res.data.features;
        obj.filter((item) => {
          entity.filter((rs) => {
            if (item.id == rs.id) {
              rs.polygon.material = Cesium.Color.RED;
            }
          });
        });
      });
  },
  setQueryTF(content, layer, name) {
    const url = this.getQueryUrl(content, layer);
    axios.get(url).then((res) => {
      const data = res.data.features;
      const obj = data.filter((item) => {
        if (item.properties.weaponname == name) {
          return item;
        }
      });
      if (obj.length <= 0) return;
      var centroid = turf.centroid(obj[0]);
      const geom = centroid.geometry.coordinates;
      const position = [geom[0], geom[1], 0];
      const cylinder = {
        radius: 1000, //半径
        angle: 30, //扫描角度(可选)
        speed: 5, //倍速(可选)
        stackPartitions: 80, //横向网格数(可选)
        slicePartitions: 80, //纵向网格数(可选)
        wallColor: "rgba(255,255,255,0)" //扫描墙颜色(可选)
      };
      const item = earthCtrl.factory.createRectangularSensor(
        position,
        cylinder
      );
      Viewer.zoomTo(item.item);
    });
  },
  getQueryUrl(content, layer) {
    return (
      "https://cim.smartearth.cn/SEserver/wfsserver/" +
      content +
      "?version=1.1.0&request=GetFeature&format=json&typename=" +
      layer
    );
  }
};
export default layerJson;