地图绘制线

创建轨迹、播放、暂停轨迹播放。
LocusLayer.vue:

<template>
    <div />
</template>

<script>
export default {
  //inject接受父组件通过provide提供过来的对象:
  /*
  provide(){
    return {
      root:this
    }
  }
  */
    inject: ['root'],
    data() {
        return {
            mapView: this.root.mapView,
            locusLayer: null,
            layerId: 'locusLayer',
            temPaths: [], // 存储播放过程中路径数据
            curIndex: 0,  // 当前播放进度
            requestPath: [// 存储从后台取得的路径数据
                [120.38231107989469, 36.30461219953733],
                [120.38780424395718, 36.29752891570557],
                [120.39164944203712, 36.29133056535232],
                [120.40867824224897, 36.286460072984134],
                [120.42213649839303, 36.28928279747521]
            ]
        }
    },
    beforeDestroy() {
        this.locusLayer && this.locusLayer.destroy()
    },
    mounted() {
        this.creatGraphicPolyLine(this.requestPath)
    },
    methods: {
        // 创建图形线
        creatGraphicPolyLine(path) {
            this.locusLayer && this.locusLayer.destroy()
            this.locusLayer = new this.$esri.GraphicsLayer()
            const lineSymbol = {
                type: 'simple-line', // autocasts as new SimpleLineSymbol()
                color: '#52b9c9', // RGB color values as an array
                join: 'round',
                cap: 'square',
                // style: 'dash',
                width: 4
            }
            const polylineGraphic = new  this.$esri.Graphic({
                geometry: {
                    type: 'polyline', // autocasts as new Polyline()
                    paths: path
                },
                symbol: lineSymbol
            })
          
            this.locusLayer.add(polylineGraphic)
            this.locusLayer.id = 'pathLayer'
            this.mapView.map.add(this.locusLayer)
        },
        // 播放轨迹
        playTrack() {
            if (this.timer) {
                clearInterval(this.timer)
            }
            this.timer = setInterval(() => {
                this.temPaths.push(this.requestPath[this.curIndex])
                if (this.curIndex >= this.requestPath.length) {
                    clearInterval(this.timer)
                    this.$emit('play-finish')
                    this.curIndex = 0
                    this.temPaths = []
                    return
                }
                this.creatGraphicPolyLine(this.temPaths)
                this.curIndex++
            }, 1000)
        },
        // 暂停轨迹播放
        stopPlay() {
            if (this.timer) {
                clearInterval(this.timer)
            }
        }
    }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值