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
"use strict";
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var mapModel = {
  flag: 0,
  defaultHeight: 0,
  layers: null,
  url: null,
  init: function init() {
    this.defaultHeight = 800;
    this.flag = 0;
    this.modelUrl = "http://localhost/pwyth/3dtile/";
    this.layers = ["洞库机库1009", "发电设施", "滑行道", "机库1009", "佳山军营1009", "雷达1009", "莲花军营1009", "联络道1009", "绿化1009", "跑道1009", "通风设施", "通讯设施", "油库1009", "战斗机1009", "阵地发射车", "阵地发射炮发射车"];
    this.setChangeModel();
  },
  setChangeModel: function setChangeModel() {
    this.defaultHeight = 400;
    var name = this.layers[this.flag];
    var url = this.modelUrl + name + "/tileset.json";
    console.log(url);
    this.addModel(url, name);
  },
  addModel: function addModel(res, name) {
    var _this = this;
 
    var height = this.defaultHeight;
    var tileset = new Cesium.Cesium3DTileset({
      url: res
    });
    var that = this;
    tileset.readyPromise.then(function (tileset) {
      tileset.name = name;
      Viewer.scene.primitives.add(tileset);
      var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center);
      var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
      var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, _this.defaultHeight);
      var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
      tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
      setTimeout(function () {
        that.setChangeModelHeight(tileset);
      }, 200); //
      //   const interVal = setInterval(() => {
      //     height = height - 10;
      //     var newHeightMatrix = Cesium.Matrix4.fromArray(
      //       new Cesium.Matrix4(),
      //       height
      //     );
      //     tileset.modelMatrix = newHeightMatrix;
      //     if (height <= 10) {
      //       clearInterval(interVal);
      //       that.addNextModel();
      //     }
      //   }, 1000);
    });
  },
  addNextModel: function addNextModel() {
    this.flag++;
 
    if (this.flag < this.layers.length) {
      this.setChangeModel();
    }
  },
  setChangeModelHeight: function setChangeModelHeight(tileset) {
    var _this2 = this;
 
    var height = 780;
    var that = this;
    var interVal = setInterval(function () {
      height = height - 20;
 
      if (height < 80) {
        clearInterval(interVal);
 
        _this2.addNextModel();
      } else {
        //3dtile模型的边界球体
        var boundingSphere = tileset.boundingSphere; //迪卡尔空间直角坐标=>地理坐标(弧度制)
 
        var cartographic_original = Cesium.Cartographic.fromCartesian(boundingSphere.center);
        var center = Cesium.Cartesian3.clone(boundingSphere.center); // 将中心点转换为WGS84经纬度
 
        var cartographic = Viewer.scene.globe.ellipsoid.cartesianToCartographic(center);
        var longitude = Cesium.Math.toDegrees(cartographic.longitude);
        var latitude = Cesium.Math.toDegrees(cartographic.latitude);
        var cartographic_offset = Cesium.Cartographic.fromDegrees(longitude, latitude, height); //地理坐标(弧度制)=>迪卡尔空间直角坐标
 
        var Cartesian3_original = Cesium.Cartesian3.fromRadians(cartographic_original.longitude, cartographic_original.latitude, cartographic_original.height);
        var Cartesian3_offset = Cesium.Cartesian3.fromRadians(cartographic_offset.longitude, cartographic_offset.latitude, cartographic_offset.height); //获得地面和offset的转换
 
        var translation = Cesium.Cartesian3.subtract(Cartesian3_offset, Cartesian3_original, new Cesium.Cartesian3()); //修改模型矩阵
 
        tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
      }
    }, 100);
  }
};
var _default = mapModel;
exports["default"] = _default;