cesium第一视角/上帝视角以及解除视角锁定

第一视角效果:

function event1() {
  viewer.scene.screenSpaceCameraController.enableZoom = false; //. 禁止视角缩放
  viewer.scene.screenSpaceCameraController.enableRotate = false; //禁止左键拖动视角
  viewer.scene.screenSpaceCameraController.enableTilt = false; //禁止中键旋转视角
  person.event1Timer = setInterval(() => {
    window.swpecesium.addEntity.transform({
      id: "mode_2",
      position: {
        lon: person.position.lon,
        lat: (person.position.lat += 0.001),
        alt: 1200,
      },
    });
    //第一视角核心代码------------
    let headingPitchRoll = new Cesium.HeadingPitchRoll();
    var center = Cesium.Cartesian3.fromDegrees(
      person.position.lon,
      person.position.lat,
      1200
    );
    viewer.camera.lookAt(
      center,
      new Cesium.HeadingPitchRange(
        headingPitchRoll.heading,
        headingPitchRoll.pitch,
        50
      )
    );
  }, 100);
}

上帝视角:

function event2() {
  viewer.scene.screenSpaceCameraController.enableZoom = false; //. 禁止视角缩放
  viewer.scene.screenSpaceCameraController.enableRotate = false; //禁止左键拖动视角
  viewer.scene.screenSpaceCameraController.enableTilt = false; //禁止中键旋转视角
  person.event2Timer = setInterval(() => {
    window.swpecesium.addEntity.transform({
      id: "mode_2",
      position: {
        lon: person.position.lon,
        lat: (person.position.lat += 0.001),
        alt: 1200,
      },
    });
    // 更新相机位置(上帝视角)
    // 1. Using a cartesian offset
    var center2 = Cesium.Cartesian3.fromDegrees(
      person.position.lon,
      person.position.lat
    );
    viewer.camera.lookAt(center2, new Cesium.Cartesian3(0.0, 0, 1500));
  }, 100);
}

解除视角锁定

viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

你可能感兴趣的:(cesium,前端,javascript)