【Cesium for Supermap】S3MTiles图层box裁剪

文章介绍了如何在CesiumViewer中添加SuperMapServer的S3M缓存服务,展示如何设置裁剪盒来控制3D视图,并通过flyToBoundingSphere方法定位到特定图层。
摘要由CSDN通过智能技术生成

效果图:

代码:

        let viewer = new Cesium.Viewer('cesiumContainer');
        // 添加SuperMap iServer发布的S3M缓存服务
        let promise = viewer.scene.addS3MTilesLayerByScp("http://www.supermapol.com/realspace/services/3D-BIMbuilding/rest/realspace/datas/BIMbuilding/config",
            {name: "layerName"}
        );
        // 加载完成执行回调,定位到该图层
        promise.then(function (layer) {
            let ceterCartesianPosition = layer._position;
            let boundingSphere = new Cesium.BoundingSphere(ceterCartesianPosition, 200);
            let camera = viewer.scene.camera;
            camera.flyToBoundingSphere(boundingSphere);

            // 用于裁剪的盒子(S3MTiles图层和盒子重合部分会被裁剪调)
            let position = Cesium.Cartesian3.fromDegrees(116.47232967469, 39.9149481801, 17);
            let heading = Cesium.Math.toRadians(10);
            let hpr = new Cesium.HeadingPitchRoll(heading, 0, 0);
            let orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
            viewer.entities.add(new Cesium.Entity({
                // 此点在box体的中心
                position: position,
                // 转动盒子方向(heading,pitch,roll)
                orientation: orientation,
                box: {
                    dimensions: new Cesium.Cartesian3(50, 50, 10),
                    material: Cesium.Color.fromAlpha(Cesium.Color.BLUE, 0.1),
                    outline: true,
                    outlineColor: Cesium.Color.AQUA,
                }
            }));

            // 裁剪参数指定裁剪模式。 裁剪模式包括以下几类:
            // clip_behind_any_plane:裁剪掉位于任何裁剪面后面的部分。
            // clip_behind_all_plane:裁剪掉位于所有裁剪面后面的部分。
            // only_keep_line:只保留裁剪线,裁剪掉其他部分。
            let clipMode = 'clip_behind_all_plane';
            let boxOption = {
                dimensions: new Cesium.Cartesian3(50, 50, 10),
                position: position,
                clipMode: clipMode,
                heading: heading
            };
            layer.setCustomClipBox(boxOption);

        })

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值