"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;
|