百度地图轨迹绘制以及轨迹回放以及鼠标滑过自定义样式

news/2024/12/26 17:25:44/文章来源:https://www.cnblogs.com/menxiaojin/p/18633711

用百度地图的绘制轨迹以及相关的轨迹回放,鼠标滑过展示与否的自定义弹窗的整理

图片展示

组件代码:

<!--* @Author: menxiaojin* @Date: 2023-07-12 14:03:03* @LastEditors: menxiaojin* @LastEditTime: 2023-07-20 19:41:02
-->
<!--首页地图组件-->
<template><div class="data_map" style="height:100%;"><div class="bg_heights" style="position: relative;height:100%;"><div :id="mapId" style="width:100%;height:100%;"></div><div class="bofang"><el-button  type="primary" size="mine" @click="plackBack"  v-if="condition">播放</el-button><el-button  type="primary" size="mine" @click="suspend" v-if="suspedContinueShow">暂停</el-button><el-button  type="primary" size="mine" @click="continueMap" v-if="!suspedContinueShow">返回</el-button></div></div></div>
</template>
<style scoped lang="scss">
.bofang{position: absolute;top:20px;left:30px;z-index: 10;
}
</style>
<style lang="scss">.anchorBL{display: none;}body, html,#map {height: 100%;margin:auto ;font-family:"微软雅黑";}.divLabelMApText{width: 36px;height: 36px;text-align: center;line-height: 16px;font-size:14px;color: #ffffff;}.divOutMapA{width: 320px;height: 185px;background: url('http://218.56.180.213:8035/shopping/static/file/pic/202307/picrXBtW1uh1689581712300.png') no-repeat;background-size:100% 100%;margin-top: -50px;margin-left: -145px;.mapFlexDiv{display: flex;padding: 30px 20px;.flexLeftImg{width: 80px;height: 131px;}.flexRight{flex: 1;padding-left: 10px;padding-top: 20px;.flexRightListOne{width: 100%;// height: 30px;background: rgba(41,147,207,0.2);line-height: 20px;color: #ffffff;font-size:13px;padding: 5px 10px;}.flexRightListTwo{background: rgba(41,147,207,0.4);line-height: 20px;color: #ffffff;font-size:13px;padding: 5px 10px;margin-top: 15px;}}}}
</style>
<script type="text/ecmascript-6">import { loadBMaOne, loadBaiDuLuShu } from './map'// import { BMapGLLib } from './LuShu'// require('./LuShu');export default {props:{mapId:{type:String,default:'mapId'},zoom:{type:Number,default:17},markerArr:{type:Array,default:()=>[{imgurl: "http://218.56.180.213:8137/policeNewFormalFile/subFace/snapFace/202211/20221128/snapFace1ec55445-4abf-4a8d-a59d-17ada05b02b3-0.png",visitTime: "2022-11-28 17:03:21",longitude: 118.712444,uptownName: "中国广饶今田小商品批发市场西门",latitude: 37.43991,cameraName: "花苑路交叉口朝东500m人脸",type:'start'},{imgurl: "http://218.56.180.213:8137/policeNewFormalFile/subFace/snapFace/202211/20221128/snapFace1ec55445-4abf-4a8d-a59d-17ada05b02b3-0.png",visitTime: "2022-11-28 17:03:21",longitude: 118.713192,uptownName: "中国广饶今田小商品批发市场西门",latitude: 37.441471,cameraName: "花苑路交叉口朝东500m人脸",type:''},{imgurl: "http://218.56.180.213:8137/policeNewFormalFile/subFace/snapFace/202211/20221128/snapFace1ec55445-4abf-4a8d-a59d-17ada05b02b3-0.png",visitTime: "2022-11-28 17:03:21",longitude: 118.710435,uptownName: "中国广饶今田小商品批发市场西门",latitude: 37.441478,cameraName: "花苑路交叉口朝东500m人脸",type:''},{imgurl: "http://218.56.180.213:8137/policeNewFormalFile/subFace/snapFace/202211/20221128/snapFace1ec55445-4abf-4a8d-a59d-17ada05b02b3-0.png",visitTime: "2022-11-28 17:03:21",longitude: 118.710929,uptownName: "中国广饶今田小商品批发市场西门",latitude: 37.439616,cameraName: "花苑路交叉口朝东500m人脸",type:''},{imgurl: "http://218.56.180.213:8137/policeNewFormalFile/subFace/snapFace/202211/20221128/snapFace1ec55445-4abf-4a8d-a59d-17ada05b02b3-0.png",visitTime: "2022-11-28 17:03:21",longitude: 118.709608,uptownName: "中国广饶今田小商品批发市场西门",latitude:37.4404,cameraName: "花苑路交叉口朝东500m人脸",type:'end'},]},},data(){return {mapLoading:false,bgHeight:'668px',map:'',currentLat:118.4282,currentLon : 37.042122,getZoom:16,   //地图当前的等级peopleLocus:'',trackAni:null,iconPeople:require('../../assets/base/flow_people.png'),condition:true,suspedContinueShow:true,}},//关键
        created(){let that=this;window.bigImg=that.bigImg;},watch: {mapId: {handler: function () {let that=this;that.$nextTick(() => {loadBMaOne("ahwEn9BozQOKSBXhe02qQtCOABvFu2hr").then(() => {that.initAMap();that.initMap()})})},// 立即以obj.name的当前值触发回调immediate: true},markerArr: {handler: function(newObj, oldObj) {let that=this;that.$nextTick(() => {loadBMaOne("ahwEn9BozQOKSBXhe02qQtCOABvFu2hr").then(() => {that.initAMap();that.initMap()})})},deep: true, // 深度监听immediate: true // 会在监测开始时调用一次该处理函数
            }},methods:{initAMap(){//声明地图var mp = new BMapGL.Map(this.mapId,{minZoom: 10, maxZoom: 19});this.currentLat = this.markerArr[0].longitudethis.currentLon = this.markerArr[0].latitudemp.centerAndZoom(new BMapGL.Point(this.currentLat,this.currentLon), this.zoom);mp.enableScrollWheelZoom();this.map = mpthis.peopleMap()},/*** 画线*/drawPolyline(bMap, points) {if (points==null || points.length<=1) {return;}bMap.addOverlay(new BMapGL.Polyline(points, {strokeColor : "#D70028",strokeWeight : 6,strokeOpacity : 0.6})); // 画线// this.addArrow(points,10,Math.PI/7);
            },peopleMap(id){var that = thisthis.peopleLocus = this.mapvar data = this.markerArr;//第7步:绘制点for (var i = 0; i < data.length; i++) {var point = new BMapGL.Point(Number(data[i].longitude), Number(data[i].latitude));var myIcon;if(data[i].type=='start'){myIcon=require('../../assets/base/start.png');}else if(data[i].type=='end'){myIcon=require('../../assets/base/end.png');}else{myIcon=require('../../assets/base/ing.png');}var myIconA= new BMapGL.Icon(myIcon, new BMapGL.Size(36, 47));var marker = new BMapGL.Marker(point,{icon: myIconA});this.map.addOverlay(marker);   //添加标注点//非弹框文字标注let customOverlayA = new BMapGL.CustomOverlay(createDOMB, {point: new BMapGL.Point(Number(data[i].longitude),Number(data[i].latitude)),opacity: 0.5,properties: {index:i+1},});customOverlayA.class='label'// 自定义展示内容function createDOMB() {var div = document.createElement('div');div.style.zIndex = BMapGL.Overlay.getZIndex(this.point.lat);div.setAttribute('class','divLabelMApText')var title = document.createElement('div');div.appendChild(title);title.appendChild(document.createTextNode(this.properties.index));return div;}this.map.addOverlay(customOverlayA);//弹框let customOverlay = new BMapGL.CustomOverlay(createDOM, {point: new BMapGL.Point(Number(data[i].longitude),Number(data[i].latitude)),opacity: 0.5,// offsetY: -40,// offsetX: -120,
                        properties: {imgSrc:data[i].imgurl,longitude:data[i].longitude,latitude:data[i].latitude,id:data[i].id,time:data[i].visitTime,address:data[i].uptownName},});//鼠标滑过marker.addEventListener('mouseover', function () {let all=that.map.getOverlays()all.map(item=>{if (item.toString() === "CustomOverlay"&&item.class==undefined) {that.map.removeOverlay(item);}})that.map.addOverlay(customOverlay);});marker.addEventListener('onmouseout', function () {let all=that.map.getOverlays()all.map(item=>{if (item.toString() === "CustomOverlay"&&item.class==undefined) {that.map.removeOverlay(item);}})});//添加标注位置function createDOM() {var div = document.createElement('div');div.style.zIndex = BMapGL.Overlay.getZIndex(Number(this.properties.latitude));div.setAttribute('class','divOutMapA')//上方的topvar topDiv = document.createElement('div');topDiv.setAttribute('class','mapFlexDiv')//左侧图片var topLeft = document.createElement('img');topLeft.setAttribute('class','flexLeftImg')topLeft.src = this.properties.imgSrc;topDiv.appendChild(topLeft);//右侧展示var topRight = document.createElement('div');topRight.setAttribute('class','flexRight')topDiv.appendChild(topRight);//创建右侧的listvar listOne = document.createElement('div');listOne.setAttribute('class','flexRightListOne')listOne.appendChild(document.createTextNode('时间:'+this.properties.time));topRight.appendChild(listOne);var listTwo = document.createElement('div');listTwo.setAttribute('class','flexRightListTwo')listTwo.appendChild(document.createTextNode('地址:'+this.properties.address));topRight.appendChild(listTwo);div.appendChild(topDiv);return div;}}//绘制线var points = new Array();for (var i = 0; i < data.length; i++) {var p0 = data[i].longitude;var p1 = data[i].latitude;var thePoint1 = new BMapGL.Point(p0, p1);points.push(thePoint1);}this.drawPolyline(this.peopleLocus, points);},// 回放按钮
            plackBack(){let that=this;that.suspedContinueShow = true;that.backShow = true;let mapData=that.markerArr;loadBaiDuLuShu().then((BMapGL)=>{var marker;let bmap = new BMapGL.Map(this.mapId,{minZoom: 1, maxZoom: 20});let lng=mapData[0].longitude;let lat=mapData[0].latitude;if( (lng!=''&&lng!='undefind'&&lng!='null')&&(lat!=''&&lat!='undefind'&&lat!='null') ){bmap.centerAndZoom(new BMapGL.Point(lng, lat), this.zoom);}else{bmap.centerAndZoom(new BMapGL.Point(118.595639, 37.462191), this.zoom);}bmap.enableScrollWheelZoom(true);let path=[];for(let i=0;i<mapData.length;i++){let item={lng: mapData[i].longitude,lat: mapData[i].latitude};path.push(item)}//相关点位var point = [];for (var i = 0; i < mapData.length; i++) {point.push(new BMapGL.Point(mapData[i].longitude, mapData[i].latitude));}//线var polyline = new BMapGL.Polyline(point, {strokeColor : "#D70028",strokeWeight : 6,strokeOpacity : 0.6});bmap.addOverlay(polyline);this.trackAni = new BMapGLLib.LuShu(bmap,point,{// defaultContent:"粤A30780",//"从天安门到百度大厦"geodesic: true,autoCenter: true,autoView:true,//是否开启自动视野调整,如果开启那么路书在运动过程中会根据视野自动调整// icon  : new BMap.Icon(this.iconPeople, new BMap.Size(40,45),{anchor : new BMap.Size(40, 45)}),icon  : new BMapGL.Icon(this.iconPeople, new BMapGL.Size(31,36),{anchor : new BMapGL.Size(31, 36)}),speed: 1500,enableRotation:false,//是否设置marker随着道路的走向进行旋转// tilt: 30,// duration: 20000,// delay: 300
                    });this.trackAni.start();})},//暂停播放
            suspend(){this.suspedContinueShow = !this.suspedContinueShowthis.trackAni.pause()},//继续播放
            continueMap(){this.suspedContinueShow = !this.suspedContinueShow// this.trackAni.continue()this.$nextTick(() => {loadBMaOne("ahwEn9BozQOKSBXhe02qQtCOABvFu2hr").then(() => {this.initAMap();this.initMap()})})},//异步调用百度js
            map_load() {var load = document.createElement("script");// load.src = this.$mapUrl;// load.src=require('./LuShu')// load.src = 'http://api.map.baidu.com/api?v=2.0&ak=OwlyYKUbMwazEII5oTmBRiqOurFZe6xO';
                document.body.appendChild(load);},initMap(){window.onload = this.map_load;},},//调用方法
        mounted() {let that=this;that.$nextTick(() => {loadBMaOne("ahwEn9BozQOKSBXhe02qQtCOABvFu2hr").then(() => {that.initAMap();that.initMap()})})}}
</script>

相关引用的map.js代码

import {messageBox} from '../../api/message'
export function loadBMap(ak) {return new Promise(function(resolve, reject) {if (typeof BMapGL !== 'undefined') {resolve(BMapGL)return true}window.onBMapCallback = function() {resolve(BMapGL)}let script = document.createElement('script')script.type = 'text/javascript'script.src ="https://api.map.baidu.com/api?v=3.0&ak=ahwEn9BozQOKSBXhe02qQtCOABvFu2hr&__ec_v__=20190126&callback=onBMapCallback"script.onerror = rejectdocument.head.appendChild(script)})
}function loadBaiDuDrawMap() {return loadBMap().then(BMapGL => {let loaded = falsetry {loaded = (BMapGLLib && BMapGLLib.DrawingManager)} catch (err) {loaded = false}if (!loaded) {let script = document.createElement('script')script.type = 'text/javascript'script.src = 'http://mapopen.cdn.bcebos.com/github/BMapGLLib/DrawingManager/src/DrawingManager.min.js'document.body.appendChild(script)let link = document.createElement('link')link.rel = 'stylesheet'link.href = 'http://mapopen.cdn.bcebos.com/github/BMapGLLib/DrawingManager/src/DrawingManager.min.css'document.body.appendChild(link)} else {}return BMapGL})}export { loadBaiDuDrawMap }// function loadBaiDuTrack() {//   return loadBMapLu().then(BMapGL => {//     let loaded = false//     try {//       loaded = (BMapGLLib && BMapGLLib.TrackAnimation)//     } catch (err) {//       // alert('还未加载完成,请再次点击')//       messageBox({//         message: '轨迹动画加载中,请再次点击!',//         type: 'warning',//         callback: action => {//         }//       })//       loaded = false//     }//     if (!loaded) {//       let script = document.createElement('script')//       script.type = 'text/javascript'//       script.src = 'http://mapopen.cdn.bcebos.com/github/BMapGLLib/TrackAnimation/src/TrackAnimation.min.js'//       // script.src = 'http://api.map.baidu.com/library/LuShu/1.2/src/LuShu_min.js'//       document.body.appendChild(script)//       let link = document.createElement('link')//       link.rel = 'stylesheet'//       // link.href = 'http://mapopen.cdn.bcebos.com/github/BMapGLLib/TrackAnimation/src/TrackAnimation.min.css'//       document.body.appendChild(link)//     } else {//     }//     return BMapGL//   })// }// export { loadBaiDuTrack }function loadBMaOne(ak) {return new Promise(function (resolve, reject) {try {resolve(BMapGL)} catch (err) {window.init = function () {resolve(BMapGL)}let script = document.createElement('script')script.type = 'text/javascript'script.src = `http://api.map.baidu.com/api?v=1.0&type=webgl&ak=${ak}&callback=init`script.onerror = rejectdocument.body.appendChild(script)}})}export { loadBMaOne }function loadBaiDuLuShu() {return loadBMaOne().then(BMapGL => {let loaded = false// console.log(BMapGL,loaded,'--==--')try {// console.log('00==',BMapGLLib)loaded = (BMapGLLib && BMapGLLib.LuShu)} catch (err) {// console.log(2)// alert('还未加载完成,请再次点击')// messageBox({//   message: '轨迹动画加载中,请再次点击!',//   type: 'warning',//   callback: action => {//   }// })
loaded = false}if (!loaded) {let script = document.createElement('script')script.type = 'text/javascript'script.src = 'https://api.map.baidu.com/library/LuShu/gl/src/LuShu_min.js'// script.src = 'http://api.map.baidu.com/library/LuShu/1.2/src/LuShu_min.js'
        document.body.appendChild(script)let link = document.createElement('link')link.rel = 'stylesheet'// link.href = 'http://mapopen.cdn.bcebos.com/github/BMapGLLib/TrackAnimation/src/TrackAnimation.min.css'
        document.body.appendChild(link)} else {}return BMapGL})}export { loadBaiDuLuShu }

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/859373.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【护网】IP WhitePass:IP过滤,白名单过滤,用于护网CDN、负载地址过滤等;

免责声明 由于传播、利用本公众号夜组安全所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,公众号夜组安全及作者不为此承担任何责任,一旦造成后果请自行承担!如有侵权烦请告知,我们会立即删除并致歉。谢谢!所有工具安全性自测!!!工具介绍 在护…

async/await 异步连接通讯设备

1. 在项目中遇到,获取上下两把扫码枪的结果,但是只有其中一把扫码枪能扫码,因为码可能在上面也可能在下面2. 起初我是用的同步的方法,先使用下面的扫码枪,再使用上面的扫码枪,扫码枪扫描超时为1秒,但是这样的缺点就是会浪费一把扫码枪扫描的时间3. 为了节约时间,将方法…

智谱开源CogAgent的最新模型CogAgent-9B-20241220,全面领先所有开闭源GUI Agent模型

在现代数字世界中,图形用户界面(GUI)是人机交互的核心。然而,尽管大型语言模型(LLM)如ChatGPT在处理文本任务上表现出色,但在理解和操作GUI方面仍面临挑战,因此最近一年来,在学界和大模型社区中,越来越多的研究者和开发者们开始关注VLM-based GUI Agent。2023年12月,…

会话相关的常用查询

ORACLE常用的与会话相关的查询 目录ORACLE常用的与会话相关的查询查看当前锁的信息:查看当前正在执行的sqlORACLE的监听日志(listener.log)Listener log locationFor oracle 9i/10gFor oracle 11g/12c或者通过 lsnrctl status 也可以查看位置或者11g可以通过 adrci 命令List…

VMware——mac下设置虚拟机共享文件夹

前言 按着VMware软件给的提示,设置好共享文件夹之后,在linux目录下没有看到文件夹,就想到了可能是没挂载的原因。 内容 基本的操作直接参考官方的即可,这里不做描述,直接贴图了,官方给的教程缺少了比较关键的一步,不过可能认为这个是常识,就没有放在文档里吧。 基础步骤…

LVS(Linux Virtual Server)备忘录

(241226) 基础内容 LVS 是 Linux Virtual Server ,Linux 虚拟服务器;是一个虚拟的服务器集群【多台机器 LB IP】。LVS 集群分为三层结构: 负载调度器(load balancer):它是整个LVS 集群对外的前端机器,负责将client请求发送到一组服务器【多台LB IP】上执行,而client端认…

数字化工厂 制造业转型升级的必由之路 珠海先达

随着“工业4.0”理念的全球传播,制造业正经历着一场前所未有的变革。在这场变革中,数字化工厂作为通往智能制造的重要阶段,成为了众多企业竞相追逐的目标。数字化工厂不仅提升了生产效率,还优化了产品设计、生产流程和管理方式,为企业在激烈的市场竞争中赢得了先机。 一、…

适合小团队协作的开源在线项目管理系统推荐【任务管理与进度追踪】

对于小团队而言,高效协作是项目顺利推进的关键所在,而一款契合的开源在线项目管理系统,无疑能在任务管理与进度追踪方面发挥巨大作用,助力团队成员有条不紊地开展工作,提升整体效率。当下市场上有诸多此类优秀的开源工具可供选择,本文就将为小团队推荐几款,帮助大家找到…

Centos7创建LVM磁盘管理

Centos7创建LVM磁盘管理 2019-06-02阅读 3840 环境介绍 在centos7下需要挂载两个新的磁盘。为了方便后续的扩容方便,决定将这其设置为LVM管理的方式。 查看一下当前有哪些新增的数据盘,如下: [root@runsdata-test-0004 ~]# df -h Filesystem Size Used Avail Use% Mou…

iostat命令详解

iostat命令详解 简介 iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息。用户可以通过指定统计的次数和时间来获得所需的统计信息。 iostat可以提供更丰富的IO性能状态数据,i…

学习笔记(四十九):Text常用场景

1、设置文本断行及折行Text(this.content).fontSize(14).textAlign(TextAlign.End).textOverflow({ overflow: TextOverflow.Ellipsis }).wordBreak(WordBreak.BREAK_WORD).maxLines(this.contentMaxLine) 作者:听着music睡出处:http://www.cnblogs.com/xqxacm/Android交流群…

VS2022 + OpenSSL 3.0实现DES、AES、RSA加密

​ 一、DES加密 #include <openssl/des.h> #include <cstdio> #include <iostream> #include <cstdlib> #include <iomanip> #define MAX_LINE 1024 #pragma warning(disable : 4996)using namespace std;signed main() {const_DES_cblock key …