地图播放轨迹

vue—等待数据请求,异步操作,等待数据画路线,画完路线异步实例lushu,实例好lushu后开始播放。在每次播放前都清除一次_marker和polyline

.catch(err => {
          console.log(err);
        })

接住,
methods中的方法

methods:{
    //播放轨迹
    playTrack(isRun, beisuValue) {
      this.beisuValue = beisuValue;
      let map = this.bmap;
      if (this.newPolyline) {
        this.newPolyline.hide();
        map.removeOverlay(this.newPolyline);
        this.newPolyline = null;
      }
      if (this.lushu) {
        map.removeOverlay(this.lushu._marker);
        this.lushu.stop();
        this.lushu = null;
      }

      if (isRun) {
        let start = parseInt(
          new Date(
            `${this.startOptions.startDate} ${this.startOptions.startHour}:${
              this.startOptions.startMinute
            }:${this.startOptions.startSecond}`
          ).getTime() / 1000
        );

        let end = parseInt(
          new Date(
            `${this.endOptions.endDate} ${this.endOptions.endHour}:${
              this.endOptions.endMinute
            }:${this.endOptions.endSecond}`
          ).getTime() / 1000
        );
        let vehicle_id = this.carDetail.vehicle_id;
        // console.log(vehicle_id);
        // console.log(start);
        // console.log(end);
        this.TbBusinessQyClwzByVIdAndTime({
          vehicle_id,
          start,
          end
          // vehicle_id: 20170652,
          // start: 1525622413,
          // end: 1525646815
        });
      }
    },
    watchplayTrack() {
      let map = this.bmap;
      // var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, {
      //   scale: 0.5, //图标缩放大小
      //   strokeColor: "#fff", //设置矢量图标的线填充颜色
      //   strokeWeight: "2" //设置线宽
      // });
      // let iconSequence = new BMap.IconSequence(sy, "10", "25");
      new Promise((res, rej) => {
        var pointArr = this.tracksData;
        // console.log(this.tracksData);
        if (pointArr && pointArr.length > 0) {
          let arrPois = pointArr.map(val => {
            let opo = new BMap.Point(val.longitude, val.latitude);
            return opo;
          });
          let newPolyline = new BMap.Polyline(arrPois, {
            strokeColor: "#d4237a",
            strokeWeight: "8", //折线的宽度,以像素为单位
            strokeOpacity: 0.8 //折线的透明度,取值范围0 - 1
            // icons: [iconSequence]
          });
          this.newPolyline = newPolyline;
          map.setViewport(arrPois);
          map.addOverlay(newPolyline);
          res(arrPois);
        } else {
          throw "没有数据";
        }
      })
        .then(arrPois => {
          if (arrPois && arrPois.length > 0) {
            let lushu = new BMapLib.LuShu(map, arrPois, {
              autoView: true, //是否开启自动视野调整,如果开启那么路书在运动过程中会根据视野自动调整
              icon: new BMap.Icon(
                "http://lbsyun.baidu.com/jsdemo/img/car.png",
                new BMap.Size(52, 26),
                { anchor: new BMap.Size(27, 13) }
              ),
              speed: 5000 * this.beisuValue,
              enableRotation: true, //是否设置marker随着道路的走向进行旋转
              landmarkPois: []
            });

            this.lushu = lushu;
            this.lushu.start();
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
}

watch中的代码

watch:{
    tracksData() {
      this.watchplayTrack();
    },
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值