【Cesium】创建形状基础---点、线、面、矩形、柱体、连廊、墙等

该文详细介绍了如何使用Cesium进行3D场景中的点、线、面、矩形、走廊、球体、立方体、圆柱/圆锥体和墙体等几何体的创建,包括坐标定位、颜色、材质和尺寸等属性设置。

目录

一、点创建 

二、线创建 

三、面创建

四、矩形创建

五、走廊创建

六、球体创建

七、立方体创建

八、圆柱(圆锥)体创建

九、墙体创建


一、点创建 

const entity = viewer.entities.add({
        id: 'point',
        name: "点",
        show: true,
        position: Cesium.Cartesian3.fromDegrees(108, 34, 20),
        point: {
            color: Cesium.Color.RED,
            pixelSize: 10,
            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
            disableDepthTestDistance: Number.POSITIVE_INFINITY,  // 无论如何缩放,标记点不被地形遮挡
        }
    })
    viewer.zoomTo(entity)

二、线创建 

    const entity = viewer.entities.add({
        id: 'line',
        name: "线",
        show: true,
        polyline: {
            positions: Cesium.Cartesian3.fromDegreesArray([
                19.0, 48.0, 
                20.0, 48.0, 
                20.0, 47.0,
                19.0, 47.0, 
            ]),
            width:3,
            material: Cesium.Color.BLUE.withAlpha(0.5),
        }
    })
    viewer.zoomTo(entity)

三、面创建

 

// 创建矩形
    const entity = viewer.entities.add({
        id: 'polygon',
        name: "面",
        show: true,
        polygon: {
            hierarchy: Cesium.Cartesian3.fromDegreesArray([
                19.0, 47.0, 
                19.0, 48.0, 
                20.0, 48.0, 
                20.0, 47.0, 
            ]), //参数为四个角点坐标
            material: Cesium.Color.BLUE.withAlpha(0.5)
            
        }
    })
    viewer.zoomTo(entity)

四、矩形创建

    // 创建矩形
    const entity = viewer.entities.add({
        id:'rectangle',
        name:"矩形",
        show:true,
        rectangle:{
            coordinates: Cesium.Rectangle.fromDegrees(80.0, 30.0,100.0,35.0), //参数依次为为西经、南纬、东经和北纬度数
            material: new Cesium.ColorMaterialProperty(
                Cesium.Color.BLUE.withAlpha(0.5)
            ),
        }
    })
    viewer.zoomTo(entity) // 视角进入实体场景

五、走廊创建

const entity = viewer.entities.add({
        id: 'corridor',
        name: "连廊",
        show: true,
        corridor: {   
            positions: Cesium.Cartesian3.fromDegreesArray([
                100.0, 40.0,
                105.0, 40.0,
                105.0, 35.0
            ]),  // 参数为中心线坐标,起点、拐点、终点
            width: 100000,  //通道宽度
            material: new Cesium.ColorMaterialProperty(
                Cesium.Color.BLUE.withAlpha(0.5)
            ),
        }
    })
    viewer.zoomTo(entity)

六、球体创建

const redSphere = viewer.entities.add({
        name: "球体",
        position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
        ellipsoid: {
            radii: new Cesium.Cartesian3(300000.0, 300000.0, 300000.0),   //x,y,z方向长度
            material: Cesium.Color.RED.withAlpha(0.5),
            outline: true,
            outlineColor: Cesium.Color.BLACK,
        },
    });
    viewer.zoomTo(redSphere)

七、立方体创建

const blueBox = viewer.entities.add({
        name: "Blue box",
        position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0), 
        box: {
            dimensions: new Cesium.Cartesian3(300000.0, 300000.0, 300000.0),
            material: Cesium.Color.BLUE.withAlpha(0.5),
        },
    });
    viewer.zoomTo(blueBox)

 八、圆柱(圆锥)体创建

    const redCone = viewer.entities.add({
        name: "Red cone",
        position: Cesium.Cartesian3.fromDegrees(-105.0, 40.0, 200000.0), //柱心位置
        cylinder: {
            length: 400000.0,  //圆柱体高度
            topRadius: 0.0,   // 顶面半径,与底面半径相等则为圆柱体
            bottomRadius: 200000.0, // 底面半径
            material: Cesium.Color.RED,
        },
    });
    viewer.zoomTo(redCone)

九、墙体创建

const entity = viewer.entities.add({
        id: 'wall',
        name: "墙",
        show: true,
        wall: {
            positions: Cesium.Cartesian3.fromDegreesArrayHeights([ 
                19.0, 47.0, 10000.0,
                19.0, 48.0, 10000.0,
                20.0, 48.0, 10000.0,
                20.0, 47.0, 10000.0,
                19.0, 47.0, 10000.0
            ]),  // 墙体位置及高度
            material: Cesium.Color.BLUE.withAlpha(0.5)
            
        }
    })
    viewer.zoomTo(entity)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鱼遇雨愈愉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值