Cesium倾斜模型分层单体化

前言

目前Cesium三维项目很多是使用倾斜摄影模型,但是倾斜模型只是一张好看的皮,不能进行交互操作,所以需要后期实现单体化功能,单体化有很多种,比如楼栋单体化、分层单体化、更细的有分户单体化。

实现效果

在这里插入图片描述

实现思路

倾斜模型分层单体化需要数据结合代码来实现,数据生产需要采集每层的面坐标串、底部高程、层高、顶部高度等信息。有了数据后在Cesium中通过ClassificationPrimitive渲染出来。

关键代码

 //创建拉伸的多边形对象
    createExtrudedPolygon(id, polygonGeometry) {
        return this.viewer.scene.primitives.add(
            new Cesium.ClassificationPrimitive({
                geometryInstances: new Cesium.GeometryInstance({
                    geometry: Cesium.PolygonGeometry.createGeometry(polygonGeometry),
                    attributes: {
                        color: Cesium.ColorGeometryInstanceAttribute.fromColor(
                            Cesium.Color.fromRandom({ alpha: 0.8 })
                        ),
                        show: new Cesium.ShowGeometryInstanceAttribute(true),
                    },
                    id: id, //设置id有效 其他属性无效
                }),
                classificationType: Cesium.ClassificationType.CESIUM_3D_TILE,
            })
        );
    },

详情参见 Cesium实战专栏

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐