cesium 常用函数.txt

cesium 常用函数.txt
参考:https://cesium.com/cesiumjs/

一、数据计算及类型转换
    1)Cartographic类的函数
        1.WGS84坐标。
            new Cesium.Cartographic(longitude, latitude, height)
                由经度、纬度和高度定义的位置-球面坐标。
                由WGS84椭球面的经度、纬度(弧度)和高度确定的位置。
                Name	    Type	Default	Description
                longitude	Number	0.0	    optional The longitude, in radians.
                latitude	Number	0.0	    optional The latitude, in radians.
                height	    Number	0.0	    optional The height, in meters, above the ellipsoid.
                // longitude, latitude, 单位:弧度。height,距离球面的高度,单位:米。
                let position2 = new Cesium.Cartographic();
                console.log("position2:", position2);
                // position2: s {longitude: 0, latitude: 0, height: 0}

        2.根据经纬度构造WGS84坐标。
            Cesium.Cartographic.fromDegrees(longitude, latitude, height, result) → Cartographic
                从以度为单位指定的经度和纬度创建新的制图实例。结果对象中的值将以弧度表示。
                Name	    Type	    Default	Description
                longitude	Number		        The longitude, in degrees.
                latitude	Number		        The latitude, in degrees.
                height	    Number	    0.0	    optional The height, in meters, above the ellipsoid.
                result	    Cartographic		optional The object onto which to store the result.

        3.把 三维笛卡尔坐标 转换成 WGS84坐标。
            Cesium.Cartographic.fromCartesian(cartesian, ellipsoid, result) → Cartographic
                从Cartesian位置创建新的绘图实例。结果对象中的值将以弧度为单位。
                Name	    Type	    Default	        Description
                cartesian	Cartesian3		            The Cartesian position to convert to cartographic representation.
                ellipsoid	Ellipsoid	Ellipsoid.WGS84	optional The ellipsoid on which the position lies.
                result	    Cartographic		        optional The object onto which to store the result.

    2)Cartesian3 类的函数
        1.构造地球的“右手笛卡尔坐标”函数:new Cesium.Cartesian3(x, y, z),
            其中,x,y,z的单位:米。
        2.Cesium.Cartesian3.distance(left, right) → Number
        3.Cesium.Cartesian3.fromDegrees(longitude, latitude, height, ellipsoid, result) → Cartesian3
        4.Cesium.Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result) → Cartesian3
        5.Cesium.Cartesian3.subtract(left, right, result) → Cartesian3

    3)各种转换类函数
        1.度 <-> 弧度
            Cesium.Math.toRadians(degrees) → Number
            Cesium.Math.toDegrees(radians) → Number
            console.log("degree -> radian:", Cesium.Math.toRadians(180));
            // degree -> radian: 3.141592653589793
            console.log("radian -> degree:", Cesium.Math.toDegrees(3.141592653589793));
            // radian -> degree: 180

        2.根据heading构造旋转矩阵Matrix3。
            知识点:
            Heading(航向)是负z轴的旋转。Pitch(俯仰)是负y轴的旋转。Roll(滚动)是正x轴的旋转。
            函数:
            Cesium.Matrix3.fromRotationZ(angle, result) → Matrix3
            创建一个围绕z轴的旋转矩阵Matrix3。
            angle,旋转的角度,单位弧度。正角是逆时针方向的。
            示例:
            let heading = 0;
            let rotationMatrix_z = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(heading));
            console.log("8.");
            console.log("rotationMatrix_z:", rotationMatrix_z);
            // rotationMatrix_z: l {0: 1, 1: 0, 2: 0, 3: -0, 4: 1, 5: 0, 6: 0, 7: 0, 8: 1}

        3.把Matrix3 -> Matrix4。
            Cesium.Matrix4.fromRotationTranslation(rotation, translation, result) → Matrix4
            计算矩阵4实例, 从表示旋转的3*3矩阵和表示转换的cartesian 3中。
            Name	    Type	    Default	        Description
            rotation	Matrix3		                The upper left portion of the matrix representing the rotation.
            translation	Cartesian3	Cartesian3.ZERO	optional The upper right portion of the matrix representing the translation.
            result	    Matrix4		                optional The object in which the result will be stored, 
                                                        if undefined a new instance will be created.

        4.由数组构造Matrix4。
            Cesium.Matrix4.fromArray(array, startingIndex, result) → Matrix4
            从数组中的16个连续元素创建4x4矩阵。
            Name	        Type	        Default	Description
            array	        Array.<Number>		    The array whose 16 consecutive elements correspond to the positions of the matrix. 
                                                        Assumes column-major order.
            startingIndex	Number	        0	    optional The offset into the array of the first element, 
                                                        which corresponds to first column first row position in the matrix.
            result	        Matrix4		            optional The object onto which to store the result.
            示例:
            let v = [1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, 4.0];
            let m = Cesium.Matrix4.fromArray(v);
            console.log("m:", m);
            // m: c {0: 1, 1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2, 7: 2, 8: 3, 9: 3, 10: 3, 11: 3, 12: 4, 13: 4, 14: 4, 15: 4}

        5.计算Matrix4的逆矩阵。
            Cesium.Matrix4.inverse(matrix, result) → Matrix4
            使用Cramers规则计算所提供矩阵的逆。
            常用于模型加载时,求模型tileset._root.transform矩阵的逆矩阵。
            Name	Type	Description
            matrix	Matrix4	The matrix to invert.
            result	Matrix4	The object onto which to store the result.
            示例:
            i.orginMatrixInverse = Cesium.Matrix4.inverse(e._root.transform, new Cesium.Matrix4))

        6.两个矩阵相乘
            Cesium.Matrix4.multiply(left, right, result) → Matrix4
            left, Matrix4, The first matrix.
            right, Matrix4, The second matrix.
            result, Matrix4, The object onto which to store the result.
            示例:计算模型原始矩阵和其逆矩阵的乘积(也是一个同样类型的矩阵。)
            var a = Cesium.Matrix4.multiply(i._root.transform, o, new Cesium.Matrix4);

        7.计算Matrix4和cartesian 3的点乘。
            Cesium.Matrix4.multiplyByPoint(matrix, cartesian, result) → Cartesian3
            Name	    Type	    Description
            matrix	    Matrix4	    The matrix.
            cartesian	Cartesian3	The point.
            result	    Cartesian3	The object onto which to store the result.
            示例:
            t,某节点的边界球: (4) [-2254678.64016919, 4416402.06381591, 3998110.43911067, 0.13197181397185, remove: ƒ, insert: ƒ]
            var i = workModel.tileset, o = workModel.orginMatrixInverse, r = new Cesium.Cartesian3(t[0], t[1], t[2]);
            r = Cesium.Matrix4.multiplyByPoint(a, r, new Cesium.Cartesian3)
            其中,
            a是原、逆二矩阵的乘积,
            旧r是某节点包容球的球心Cartesian3坐标,
            新r是处理过的该节点包容球的球心Cartesian3坐标,待研究。
            处理可能包括:偏移、旋转等。

        8.Cartesian3 -> 位置矩阵Matrix4
            把一个实体(模型)的“三维笛卡尔位置”转换成一个4*4的矩阵(位置矩阵)。
            位置矩阵,也是实体(模型)的一种位置表示,既可以表示位置,也能表示旋转。
            Cesium.Transforms.eastNorthUpToFixedFrame(origin, ellipsoid, result) → Matrix4
            计算一个4x4变换矩阵,从一个以所提供的原点为中心的east-north-up轴的参考坐标系 到 所提供的椭球体的固定参考框架(坐标系)。
            本地轴的定义为:
            x轴指向局部东方向。
            Y轴指向“局部”“北”方向。
            z轴指向通过该位置的椭球面法线的方向。
            Name	    Type	    Default	        Description
            origin	    Cartesian3		            The center point of the local reference frame.
            ellipsoid	Ellipsoid	Ellipsoid.WGS84	optional The ellipsoid whose fixed frame is used in the transformation.
            result	    Matrix4		                optional The object onto which to store the result.
            Returns:
            The modified result parameter or a new Matrix4 instance if none was provided.
            示例:
            // 坐标转换
            // 从当地地图东-北向上坐标系的(0.0,0.0)的转换到地球的固定框架(坐标系).
            let center = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
            let transform = Cesium.Transforms.eastNorthUpToFixedFrame(center);
            console.log("center:", center);
            // center: a {x: 6378137, y: 0, z: 0}
            // 其中,x的值,就是WGS84坐标系的点{longitude: 0, latitude: 0, height: 0}的地球半径的值。
            console.log("transform:", transform);
            // transform: c {0: -0, 1: 1, 2: 0, 3: 0, 4: 0, 5: -0, 6: 1, 7: 0, 8: 1, 9: 0, 10: 0, 11: 0, 12: 6378137, 13: 0, 14: 0, 15: 1}
            console.log("Cartesian -> Cartographic:", Cesium.Cartographic.fromCartesian(center));
            // Cartesian -> Cartographic: s {longitude: 0, latitude: 0, height: 0}


二、模型(3dtiles)的加载、定位、样式设置
    1)模型加载、移除
        1.this.tileset = new Cesium.Cesium3DTileset({
                url: this.url
            });
        2.this.viewer.scene.primitives.add(this.tileset);
        3.viewer.scene.primitives.remove(this.tileset)

    2)模型、构件定位
        1.构造新的边界球,用于定位模型或节点。
            new Cesium.BoundingSphere(center, radius)
            具有中心和半径的边界球。所有数值的单位:米
            Name	Type	    Default	        Description
            center	Cartesian3	Cartesian3.ZERO	optional The center of the bounding sphere.
            radius	Number	    0.0	            optional The radius of the bounding sphere.

        2.Cartesian3常量。
            Cesium.Cartesian3.ZERO : Cartesian3
            初始化为(0.0、0.0、0.0)的不可变的cartesian 3实例。

        3.定位3dtileset或其构件/节点,视图飞行到某处。
            viewer.camera.flyToBoundingSphere(boundingSphere, options)
            viewer.camera.flyToBoundingSphere(this.tileset.boundingSphere)
            viewer.camera.flyToBoundingSphere(n, {duration: .5})
            viewer.camera.flyTo({destination: Cesium.Cartesian3.fromDegrees(this.location.x, this.location.y, this.location.z + 1e3)})

    3)样式设置、还原
        1.节点定位时,3d tileset的样式设置。
            new Cesium.Cesium3DTileStyle(style)
            i.style = new Cesium.Cesium3DTileStyle({
                color: {
                    conditions: [
                        ["${id} ==='" + e + "'", "rgb(255, 255, 255)"],  // 想看到的节点正常显示。
                        ["true", "rgba(255, 200, 200,0.2)"]  // 其他节点,相对透明。
                    ]
                }
            })
            resetStyle: function() {
                if (this.tileset) {
                    this.tileset.style = undefined;
                }
            }





  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值