效果图:
代码:
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);
})