vue amap做轨迹回放

<div class="amap-box" id="amap-box"></div>
<div class="input-card" v-if="activeMenu == 1 && wayArr && wayArr.length > 0">
  <div class="input-item" style="display: flex;justify-content: space-between;margin: 35px 20px;">
    <a-button type="primary" icon="play-circle" @click="startAnimation()">开始</a-button>
    <a-button type="primary" icon="pause-circle" @click="pauseAnimation()">暂停</a-button>
    <a-button type="primary" icon="left-square" @click="resumeAnimation()">继续</a-button>
   </div>
  </div>

js部分

initMap() {
  let scenicLonLat = JSON.parse(sessionStorage.getItem('scenicLonLat'))
  let center = scenicLonLat.longitude && scenicLonLat.latitude ? [scenicLonLat.longitude, scenicLonLat.latitude] : [104.065735, 30.659462]
  this.map = new window.AMap.Map('amap-box', {
     pitch: 0,
     viewMode: '2D',
     showLabel: true, //不显示地图文字标记
     center: center,
     zoom: 13.3,
     features: ['bg', 'road', 'building', 'point']
    })
   },
    // 绘制轨迹
        plotMap() {
            this.clearMap()
            const that = this
            this.marker = new AMap.Marker({
                map: this.map,
                position: this.lineArr[0],
                icon: 'https://webapi.amap.com/images/car.png', //配置轨迹图片
                offset: new AMap.Pixel(-26, -13),
                autoRotation: true,
                angle: -90
            })
            if (this.lineArr && this.lineArr.length > 1) {
                const routeUrl = `https://restapi.amap.com/v3/direction/walking?key=28ed3c0bafde205c90ef61bf32862d03&origin=${this.lineArr[0][0]},${this.lineArr[0][1]}&destination=${this.lineArr[1][0]},${this.lineArr[1][1]}`
                axios.get(routeUrl).then(response => {
                    if (response.data.info == 'ok' && response.data.infocode == 10000) {
                        let arr1 = []
                        response.data.route.paths[0].steps.forEach(item => {
                            let arr = item.polyline.split(';')
                            arr1.push(arr)
                        })
                        arr1.forEach(item => {
                            item.forEach(child => {
                                child = child.split(',')
                                this.wayArr.push(child)
                            })
                        })
                        that.polyline = new AMap.Polyline({
                            map: that.map,
                            path: that.wayArr, // 这里是轨迹的坐标拼成的数组
                            showDir: true,
                            strokeColor: '#28F', //线颜色
                            strokeOpacity: 1, //线透明度
                            strokeWeight: 6, //线宽
                            strokeStyle: 'solid'
                        })
                        var passedPolyline = new AMap.Polyline({
                            map: that.map,
                            strokeColor: '#AF5', //线颜色
                            strokeWeight: 6 //线宽
                        })
                        that.marker.on('moving', function(e) {
                            passedPolyline.setPath(e.passedPath)
                        })
                        that.map.setFitView() //合适的视口

                        that.marker.moveAlong(that.wayArr, 100)
                    } else {
                        this.$message.error(`该任务未执行完成,无轨迹展示!`)
                    }
                })
            } else {
                that.map.setFitView() //合适的视口
            }
        },
        startAnimation() {
            this.marker.moveAlong(this.wayArr, 100)
        },
        pauseAnimation() {
            this.marker.pauseMove()
        },
        resumeAnimation() {
            this.marker.resumeMove()
        },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值