首页 > 其他分享 >vue高德地图实现播放暂停功能,支持快进快退,播放倍数设置

vue高德地图实现播放暂停功能,支持快进快退,播放倍数设置

时间:2023-06-29 15:46:26浏览次数:61  
标签:播放 marker length vue currentSpot 进快 passline1 data playSpeed

高德地图实现具体功能如图

具体实现思路如下:

<div class="playAnimation">
            <table width="100%" style="" border="0">
                <tr class="info_play">
                    <td>{{ currentMileage / 10 }} KM / {{ totalMileage / 10 }} KM</td>
                    <td>{{ currentTime }} </td>
                </tr>
                <tr style="padding: 10px 10px;">
                    <td align="center" valign="middle" colspan="2" style="padding-bottom:5px;">
                        <div style="width:100%;text-align: center">
                            <ul class="nav navbar-nav flex" style="width:100%;">
                                <li class="btn"><a id="btn1" class="btn noChoice btn-xs"
                                        @click.prevent="setSpeed(2000)">慢速</a>
                                </li>
                                <li class="btn"><a id="btn2" class="btn noChoice choice btn-xs"
                                        @click.prevent="setSpeed(4000)">正常</a></li>
                                <li @click="handlerRetreat"><i class="el-icon-d-arrow-left play_icon"></i> </li>
                                <li v-if="!runFlag" @click="runFlagChange"><i class="el-icon-video-play play_icon"></i>
                                </li>
                                <li v-if="runFlag" @click="runFlagChange"><i class="el-icon-video-pause play_icon"></i>
                                </li>
                                <li @click="handlerForward"><i class="el-icon-d-arrow-right play_icon"></i> </li>

                                <li class="btn">
                                    <a id="btn3" class="btn noChoice btn-xs" @click.prevent="setSpeed(10000)">快速</a>
                                </li>
                                <li class="btn">
                                    <a id="btn4" class="btn noChoice btn-xs" @click.prevent="setSpeed(100000)">极快</a>
                                </li>
                            </ul>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
data() {
        return {
            firstArr: [116.397428, 39.90923], // 中心点/初始坐标
            // map: null,
            marker: [],
            infoWindow: [],
            showCardInfo: true,
            travelInfo: false,
            deviceInfo: true,
            waybillDetailsList: {},
            runFlag: false, // 播放/暂停控制
            start: 1,
            playSpeed: 1000,
            travelArr: [],
            len: null, //marker移动中路径数组
            // passline: [], //通过路径的数组
            passline1: [], //未通过路径数组
            currentTime: '',// mark点移动到的当前时间
            totalMileage: 0,// 轨迹总里程
            currentMileage: 0, // 轨迹当前mark点移动里程
            lineArr: [],
            currentSpot: 0,
            isEnd: false,// 标记到达了终点
        }
    },
methods: {
/**
         * 后退
         */
        handlerRetreat() {
            this.currentSpot -= 100;
            if (this.currentSpot > 0) {
                this.marker[0].setPosition([this.passline1[this.currentSpot].lng, this.passline1[this.currentSpot].lat]);
                const data = this.passline1.slice(this.currentSpot, this.passline1.length - 1);
                this.marker[0].moveAlong(data, this.playSpeed);
            } else {
                this.currentSpot = 0;
                this.marker[0].setPosition([this.passline1[0].lng, this.passline1[0].lat]);
                const data = this.passline1.slice(0, this.passline1.length - 1);
                this.marker[0].moveAlong(data, this.playSpeed);
            }
            setTimeout(() => {
                this.runFlag = true;
            }, 10);
        },
        /**
         * 前进
         */
        handlerForward() {
            this.isEnd = false;
            this.currentSpot += 100;
            if (this.currentSpot < this.passline1.length - 1) {
                this.marker[0].setPosition([this.passline1[this.currentSpot].lng, this.passline1[this.currentSpot].lat]);
                const data = this.passline1.slice(this.currentSpot, this.passline1.length - 1);
                this.marker[0].moveAlong(data, this.playSpeed);
            } else {
                this.currentSpot = this.passline1.length - 1;
                this.marker[0].setPosition([this.passline1[this.passline1.length - 1].lng, this.passline1[this.passline1.length - 1].lat]);
                const data = this.passline1.slice(this.passline1.length - 3, this.passline1.length - 1);
                this.marker[0].moveAlong(data, this.playSpeed);
                this.isEnd = true;
            }
            setTimeout(() => {
                this.runFlag = true;
            }, 10);
        },

        /**
         * 播放速度设置
         */
        setSpeed(num) {
            this.runFlag = true;
            this.playSpeed = num;
            this.currentSpot = (this.len - 1);
            this.passline1 = this.passline1.slice(this.currentSpot, this.passline1.length - 1);
            this.marker[0].moveAlong(this.passline1, this.playSpeed);
        },

        /**
         * 播放
         */
        runFlagChange() {
            this.runFlag = !this.runFlag;
            if(this.isEnd){
                this.currentSpot = 0;
            }
            if (this.runFlag) {
                if (this.start === 1) {
                    this.movePrevious();
                    this.start++;
                } else {
                    this.resumeAnimation();
                }
            } else {
                this.pauseAnimation();
            }
        },

        /**
         * 开始动画
         */
        movePrevious() {
            this.travelArr = []
            this.dataInfo.track24s.forEach((ele, index) => {
                this.travelArr.push([ele.longitude, ele.latitude])

            })
            this.passline1 = this.travelArr;

            this.marker[0].moveAlong(this.travelArr, this.playSpeed);
        },

        /**
         * 暂停动画
         */
        pauseAnimation() {
            this.marker[0].pauseMove();
        },

        /**
         * 继续动画
         */
        resumeAnimation() {
            this.marker[0].resumeMove();
        },

        /**
         * 停止动画
         */
        stopAnimation() {
            this.marker[0].stopMove();
        },

}

 

标签:播放,marker,length,vue,currentSpot,进快,passline1,data,playSpeed
From: https://www.cnblogs.com/web-aqin/p/17514360.html

相关文章

  • 光脚丫思考Vue3与实战:第05章 计算属性和侦听器 第03节 计算属性的其他玩法
    下面是本文的屏幕录像的在线视频:温馨提示:1、视频下载:线上视频被压缩处理,可以下载高清版本:链接:https://pan.baidu.com/s/1h600_BRR9O2Lr87zVQNgEw 提取码:dgpu 2、示例代码:https://pan.baidu.com/s/1rCqbY_j35FcRWRZbuOfHqg 提取码:79kh 下图是文章大纲:一、概述本篇文章介绍了V......
  • Vue.js项目在IE11白屏报错
    一、概述项目使用vue/cli4脚手架搭建的前端项目,vue版本为2.6.10。但开发环境的IE11打开显示白屏,F12打开显示:查明报错原因是:I.E.不支持ES6语法。二、解决方案(一)解决方案11、安装如下的依赖包:npminstall--save-devbabel-polyfill或npminstall--save@babel-polyfill2、mai......
  • 教你如何用Vue3搭配Spring Framework
    摘要:在本文中,我们将介绍如何使用Vue3和SpringFramework进行开发,并创建一个简单的TodoList应用程序。本文分享自华为云社区《Vue3搭配SpringFramework开发【Vue3应用程序实战】》,作者:黎燃。一、介绍Vue3和SpringFramework都是现代Web应用程序开发中最流行的框架之一。Vue3是一个......
  • 使用vue cli 5.0 在vscode中运行vue命令报错
       1、运行 vue--version  报错  2、在cmd命令行执行 vue--version 正常  3、在终端中输入  get-ExecutionPolicy,查看当前权限  4、执行 set-executionpolicyremotesigned  命令设置为可用模式,但是报错  5、使用管理员打开powe......
  • 图书商城项目练习①管理后台Vue2/ElementUI
    本系列文章是为学习Vue的项目练习笔记,尽量详细记录一下一个完整项目的开发过程。面向初学者,本人也是初学者,搬砖技术还不成熟。项目在技术上前端为主,包含一些后端代码,从基础的数据库(Sqlite)、到后端服务Node.js(Express),再到Web端的Vue,包含服务端、管理后台、商城网站、小程序/App,分......
  • vue列表页返回数组错误Invalid prop: type check failed for prop "data". Expected A
    一个vue列表页接收后端数组时是这样写的:this.list=response.data返回如下错误:Invalidprop:typecheckfailedforprop"data".ExpectedArray,gotObject意思是希望返回一个数组但实际得到一个对象Object,网上大多是初始化userList=[]或userList=null解决的,但......
  • 前端Vue自定义简单通用省市区选择器picker地区选择器picker 收获地址界面模版
    前端Vue自定义简单通用省市区选择器picker地区选择器picker收获地址界面模版,下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13266效果图如下:代码实现如下:cc-selectDity使用方法<!--省市区选择show:是否显示 @sureSelectArea:确认事件......
  • Vue Router 源码分析
    专栏分享:vue2源码专栏,玩具项目专栏,硬核......
  • vue2+element-ui国际化实战不刷新页面
    背景有的时候我们做的项目需要支持中英文切换,那么我们就需要使用到vue-i18n插件步骤安装以及挂载安装vue-i18n依赖npmivue-i18n@8在src同级的目录下创建language文件下,在language文件夹下新增3个文件(index.js,en.js,zh.js)index.jsimportVuefrom"vue";importVu......
  • 在vue文件中使用 deep深度选择器
    使用场景有的时候我们需要在父组件中去修改第三方组件或者子组件的样式就会使用到deep深度选择器。比如:App组件中定义了.title的样式,也想让Test子组件中的.title也应用对应的样式App.vue<template><divclass="app"><h1>app组件</h1><divclass="title">这是app......