CESIUM例子学习(十四)——distance Display Conditions

每一个entity中的渲染要素都是可以单独控制的。如果在不同的视点距离显示不同的要素,可以通过可选属性distanceDisplayCondition来实现。代码如下:

function addBillboardAndRectangle () {
    var entity = viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(116.43299999999988, 39.915999999999954, 70),
        billboard: {
            image: "../Cesium1_71/Apps/Sandcastle/images/facility.gif",
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(2000, 2000000000)
        },
        rectangle: {
            coordinates: Cesium.Rectangle.fromDegrees(
                116.43299999999988, 39.915999999999954,
                117.45299999999988, 41.915999999999954,
            ),
            material: Cesium.Color.RED.withAlpha(0.5),
            outline: true,
            outlineColor: Cesium.Color.RED,
            classificationType: Cesium.ClassificationType.BOTH,
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 2000),
        },
    });
    viewer.flyTo(entity)
}
function addPointAndModel () {
    var position = Cesium.Cartesian3.fromDegrees(116.42299999999, 39.905999999999, 85)
    var heading = Cesium.Math.toRadians(135);
    var hpr = new Cesium.HeadingPitchRoll(heading, 0.0, 0.0);
    var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
    viewer.entities.add({
        position: position,
        orientation: orientation,
        point: {
            pixelSize: 10,
            color: Cesium.Color.YELLOW,
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(250.0),
        },
        model: {
            uri: "../Cesium1_71/Apps/SampleData/models/GroundVehicle/GroundVehicle.glb",
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 250.0),
        },
    });
}

上面代码的addBillboardAndRectangle()函数的entity包含了billboard和rectangle两个要素,当视点距离在0到2000米时显示的是rectangle;当视点距离在2000到2000000000米时,显示的是billboard。

addPointAndModel()函数中,entity包含了point和model两个要素,当视点距离在0到250米时显示的是model;当视点距离在250米以上时,显示的是point。

你可能感兴趣的:(cesium,distance,Display,Conditions,entity)