是否可以为旋转和位置分配约束?

时间:2017-02-16 21:37:41

标签: cesium

城市有100k人大。我想从仲裁高度(z值)显示我的地形(地图图层+ 3个建筑物)。是否有可能使用内置机制?

1 个答案:

答案 0 :(得分:0)

您可以挂钩时钟,每个勾选确保相机位于"允许区域"。

每次打勾,检查相机是否位于正确的位置。如果不是,请更正。

以下是限制相机高度的示例,但也可以使用相同的模式来限制位置的其他方面。

Sandcastle:http://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=c943ebc6b2d06b9a555584cd1e3f6a97

var viewer = new Cesium.Viewer('cesiumContainer');

// the max height that should be allowed in meters
var MAX_HEIGHT = 4e6;

// each clock tick ensure the camera is in the right position
viewer.clock.onTick.addEventListener(function() {
    var curHeight = viewer.scene.globe.ellipsoid.cartesianToCartographic(viewer.camera.position).height;
    var heightFromMax = curHeight - MAX_HEIGHT;

    // if the height of the camera is above the max, move the camera forward to ensure it is lower than the max
    if (heightFromMax > 0) {
        viewer.scene.camera.moveForward(heightFromMax);
        return;
    }
});
相关问题