当前位置:   article > 正文

cesium笔记_camera.flyto

camera.flyto
 //相机高度小于10000
 //console.log(that.viewer.camera.positionCartographic.height.toFixed(0),1234)
  • 1
  • 2

2、点不飘在空中的解决办法,获取该点得高度

     //点击事件
        let handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
        handler.setInputAction((event)=> {
            let cartesian = this.viewer.scene.pickPosition(event.position);
            let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
            let lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
            let lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
            let alt = cartographic.height; // 高度
            let coordinate = {
                longitude: Number(lng.toFixed(6)),
                latitude: Number(lat.toFixed(6)),
                altitude: Number(alt.toFixed(2))
            };
            console.log(coordinate);
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

3、获取相机视角的值

    //  let handler  = new Cesium.ScreenSpaceEventHandler(this.viewer.canvas);
      // handler.setInputAction((click) => {
      //   var pick = this.viewer.scene.pick(click.position);
      //   console.log("pick", this.getCamera());
      // }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
    //将坐标转化为84坐标
    get84Cood(positon) {
      let zb = Cesium.Cartographic.fromCartesian(positon);
      let lat = Cesium.Math.toDegrees(zb.latitude);
      let lon = Cesium.Math.toDegrees(zb.longitude);
      let height = zb.height;
      return {
        lon,
        lat,
        height,
      };
    },
    //获取相机参数
    getCamera() {
      let p = this.get84Cood(this.viewer.camera.position);
      let position = [p.lon, p.lat, p.height];
      return {
        position,
        heading: this.viewer.camera.heading,
        pitch: this.viewer.camera.pitch,
        roll: this.viewer.camera.roll,
      };
    },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

4、飞行

positionList: [
        {
          longitude: 120.82563518176293,
          latitude: 28.70423608654453,
          height: 412.4324942136966,
          heading: 3.4458786294875487,
          pitch: -0.44212293097718325,
          roll: 6.283175766823213,
          duration: 3,
        },
        {
          longitude: 120.82240513541223,
          latitude: 28.70443158078275,
          height: 173.75262039052794,
          heading: 3.4458786561348362,
          pitch:  -0.442123110228803,
          roll: 6.283175704542723,
          duration: 3,
        },
        {
          longitude: 120.8239473224087,
          latitude: 28.704510072075553,
          height: 212.3752740168831,
          heading: 3.4458786576463014,
          pitch: -0.44212312039616064,
          roll: 6.283175701010101,
          duration: 3,
        },
      ],
      count:0,
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
    flyEVent() {
      if(this.positionList.length < this.count + 1){
        return
      }
      const position = this.positionList[this.count];
      this.viewer.camera.flyTo({
        destination: Cesium.Cartesian3.fromDegrees(
          position.longitude,
          position.latitude,
          position.height
        ),
        duration: 5, //飞行所用时间
        //maximumHeight: 500, //飞行高峰时的最大高度。
        //pitchAdjustHeight: 1500, //如果摄像机的飞行高于此值,请调整俯仰航向以降低俯仰,并将地球保持在视野中
        orientation: {
          heading: position.heading,
          pitch: position.pitch,
          roll: position.roll,
        },
        complete: () => {
          // 在相机移动完成后执行
          console.log("已抵达北京天安门");
          
          this.flyEVent();
        },
        easingFunction:Cesium.EasingFunction.LINEAR_NONE
      });
      this.count++;
    },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/564058
推荐阅读
相关标签
  

闽ICP备14008679号