头图

最近公司用到超图iclient引擎的能力,需要实现点击按钮定位到超图某个倾斜摄影场景的功能。超图官方提供的API只有创建实例时传递autoSetView自动定位到场景,代码如下:

// 萨尔茨堡服务地址
let url = "http://www.supermapol.com/realspace/services/3D-srsb/rest/realspace";
// 加载场景
const cbdPromise = scene.open(url, undefined, {
    autoSetView: true // 自定定位
});

但是,如果想要加载模型是不定位,点击按钮后再定位autoSetView就无法满足了。

经过一番探索后,通过如下代码实现的功能:

// 加载场景
const cbdPromise = scene.open(url, undefined, {
    autoSetView: false // 关闭自动定位
});
// 请求场景列表

axios.get(`${url}/scenes.json`)
    .then(([{ path }]) => {

      // 请求场景列表中第一个场景的相机信息,并定位。如存在多个场景需要加载多个场景后,计算多个场景的边界再进行定位
      axios.get(`${path}.json`)
          .then(({ camera: { altitude, heading, latitude, longitude, tilt } }) => {
              scene.camera.setView({
                  destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, altitude),
                  orientation: {
                      heading: Cesium.Math.toRadians(heading),
                      pitch: Cesium.Math.toRadians(tilt - 90), roll: 0.0
                  }
              });
          });
    });

Level7
87 声望0 粉丝