我門封裝傾斜攝影圖層
首先看定義
export interface PTile3dLayer{
}
export interface PMaxtrix {
position?:{
x:number,?//模型中心X軸坐標(經(jīng)度轴术,單位:十進制度)
y:number,?//模型中心Y軸坐標(緯度韧掩,單位:十進制度)
z:number//模型中心Z軸坐標(高程鸠窗,單位:米)
},
rotate?:{
x:number,//X軸(經(jīng)度)方向旋轉(zhuǎn)角度(單位:度)
y:number,//Y軸(緯度)方向旋轉(zhuǎn)角度(單位:度)
z:number//Z軸(高程)方向旋轉(zhuǎn)角度(單位:度)
},
scale? :{
x:number,//X軸
y:number,//Y軸
z:number//Z軸
}
}
主類
```javascript
import { Layer } from "../Layer";
import { PMaxtrix } from "./PTile3dLayer";
export class Tile3dLayer extends Layer {
private _tileVisibleCallback: any = null;
private _customShader: any = null;
constructor(option: any) {
super(option.name);
new Cesium.Cesium3DTileset(option).readyPromise.then((tileset: any) => {
this.cesiumObj = tileset;
this.callLoadEndCesiumObj();
});
}
protected _addToMap(map: any) {
map.scene.primitives.add(this.cesiumObj);
}
public?autoToGround() {
}
protected _removeByMap(destroy: boolean =?true) {
if (this.cesiumObj) {
this.map.scene.primitives.remove(this.cesiumObj);
this.cesiumObj =?null;
}
}
private _bindVisibleEvent() {
this._tileVisibleCallback &&?this._tileVisibleCallback()
this._tileVisibleCallback =?this.cesiumObj.tileVisible.addEventListener(
this._updateTile,
this
)
}
private _updateTile(tile: any) {
let content = tile.content
for (let i =?0; i < content.featuresLength; i++) {
let feature = content.getFeature(i)
let model = feature.content._model
if (this._customShader && model && model._sourcePrograms && model._rendererResources) {
Object.keys(model._sourcePrograms).forEach(key => {
let program = model._sourcePrograms[key]
model._rendererResources.sourceShaders[program.fragmentShader] =?this._customShader
})
model._shouldRegenerateShaders =?true
}
}
}
setPosition(x: number, y: number, z: number) {
const position = Cesium.Cartesian3.fromDegrees(x, y, z);
const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position);
this.cesiumObj._root.transform = modelMatrix;
?更多參考?https://xiaozhuanlan.com/topic/8329645170