美文网首页
cesium 图层构建的那些事 (十八)

cesium 图层构建的那些事 (十八)

作者: haibalai | 来源:发表于2022-08-02 11:59 被阅读0次

    我门封装倾斜摄影图层

    首先看定义

    export interface PTile3dLayer{

    }

    export interface PMaxtrix {

    position?:{

    x:number, //模型中心X轴坐标(经度,单位:十进制度)

    y:number, //模型中心Y轴坐标(纬度,单位:十进制度)

    z:number//模型中心Z轴坐标(高程,单位:米)

    },

    rotate?:{

    x:number,//X轴(经度)方向旋转角度(单位:度)

    y:number,//Y轴(纬度)方向旋转角度(单位:度)

    z:number//Z轴(高程)方向旋转角度(单位:度)

    },

    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

    相关文章

      网友评论

          本文标题:cesium 图层构建的那些事 (十八)

          本文链接:https://www.haomeiwen.com/subject/jfiswrtx.html