uniapp app端moveAlong轨迹回放伪效果

87 阅读1分钟

小程序map中自带moveAlong实现轨迹回放; uniapp打包到apk时map组件不支持,暂时提供替代js解决通过定时写完完整数组实现类似效果,marker的移动则根据 this.growPointsOverTime(4000, points)

 growPointsOverTime(time, arr) {
      // 保留第一个点
      this.points = arr.splice(0, 2)
      const totalSteps = arr.length
      const interval = time / totalSteps
      let currentStep = 0
      const intervalId = setInterval(() => {
        this.markerMoveApp = arr[currentStep]
        //  markers 如果移动定位则坐标对应 markerMoveApp
        this.points.push(arr[currentStep])
        currentStep++
        if (currentStep >= totalSteps) {
           //  moveing配合地图显示移动完成前/完成后状体区分
          this.moving = false
          console.log('结束')
          clearInterval(intervalId)
        }
      }, interval)
    },