Cesium倾斜模型单体化

前言

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

实现效果

在这里插入图片描述

实现思路

倾斜模型单体化需要数据结合代码来实现,数据生产需要采集每层的面坐标串等信息。有了数据后在Cesium中通过Entity的方式渲染出来。

关键代码

 //处理查询结果
    handleQueryResult(result) {
        //清除上一次结果
        this.clearQueryResult();
        //如果查询成功 那么返回的结果应该是一个geojson对象 类型为FeatureCollection
        let feature = result.features[0]; //取第一个要素
        if (!feature) return;
        let geometry = feature.geometry; //取要素的几何对象
        let properties = feature.properties; //取要素的属性信息
        let coordinates;
        let pointArr = [];
        if (geometry.type == "MultiPolygon") { //多面 房屋面一般不会出现空洞等现象 如果有需要另做处理
            coordinates = geometry.coordinates[0][0];
        } else if (geometry.type == "Polygon") {
            coordinates = geometry.coordinates[0];
        }

        for (let i = 0; i < coordinates.length; i++) {
            const element = coordinates[i];
            pointArr.push(element[0]);
            pointArr.push(element[1]);
            pointArr.push(0);
        }
        this.addClampFeature(pointArr);
        this.showBuildInfo(properties)
    },

    //添加贴地对象
    addClampFeature(pointArr) {
        this.clampFeature = this.viewer.entities.add({
            polygon: {
                hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(pointArr)),
                classificationType: Cesium.ClassificationType.CESIUM_3D_TILE,
                material: Cesium.Color.RED.withAlpha(0.5)
            }
        })
    },

详情参见 Cesium实战专栏

Logo

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

更多推荐