高德地图旋转功能

1. 高德地图旋转(不可以来回旋转)

<script>
 
export default {
  data() {
    return {
      num: 0,
      numFlag: true,
      map:null,
      mapAnimateControl: false
    };
  },
  mounted() {
    this.initMap();
  },
  methods: {
    initMap() {
      this.map = new AMap.Map("map", {
        zoom: 10,
        resizeEnable: true,
 
        pitch:80, // 地图俯仰角度,有效范围 0 度- 83 度
        // center: [116.397428, 39.90923],
        // layers: [new AMap.TileLayer.Satellite()],
        viewMode: '3D',
        lang: "zh_cn",
 
      });
      let currentCenter = this.map.getCenter();
      this.map.setCenter(currentCenter);
        //开启调用
      this.mapAnimateControl = true
      this.rotate()
    },
    //定义动画
    rotate() {
      window.requestAnimationFrame(()=>{
        if(this.mapAnimateControl==true){
          // 360 是旋转角度
          this.map.setRotation((this.map.getRotation()+0.02)%360);
        }
        this.rotate()
      })
    }
  },
};
</script>

2. 自己改变的(可以来回旋转)

rotate() {
      window.requestAnimationFrame(() => {
        if (this.mapAnimateControl == true) {
          if (this.numFlag) {
            // 每次旋转0.2
            this.num += 0.2;
            // 最大旋转角度是30度,超过30向回旋转
            if (this.num >= 30) {
              this.numFlag = false;
            }
          } else {
            this.num -= 0.2;
            if (this.num <= 0) {
              this.numFlag = true;
            }
          }
          // this.aMap.setRotation((this.aMap.getRotation()+0.2)%30);
          this.aMap.setRotation(this.num);
        }
        this.rotate();
      });
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值