Commit 94b2ffb8 by wangzhihui

修复轨迹速度过慢问题

1 parent c361d311
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: 'wangzhihui' '1733904062@qq.com' * @Author: 'wangzhihui' '1733904062@qq.com'
* @Date: 2024-11-28 16:37:15 * @Date: 2024-11-28 16:37:15
* @LastEditors: 'wangzhihui' '1733904062@qq.com' * @LastEditors: 'wangzhihui' '1733904062@qq.com'
* @LastEditTime: 2025-01-14 17:05:20 * @LastEditTime: 2025-01-16 11:15:49
* @FilePath: \oEshield\src\utils\mapgeo.js * @FilePath: \oEshield\src\utils\mapgeo.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/ */
...@@ -10,7 +10,6 @@ const MAPGEO = { ...@@ -10,7 +10,6 @@ const MAPGEO = {
geocoder: null, geocoder: null,
getGeocoder: function () { getGeocoder: function () {
return new Promise((resolve) => { return new Promise((resolve) => {
console.log(window)
var geocoder= AMap.invoke('Geocoder'); var geocoder= AMap.invoke('Geocoder');
// AMap.plugin('AMap.Geocoder', function () {//回调函数 // AMap.plugin('AMap.Geocoder', function () {//回调函数
// var geocoder = new AMap.Geocoder({ // var geocoder = new AMap.Geocoder({
...@@ -23,6 +22,7 @@ const MAPGEO = { ...@@ -23,6 +22,7 @@ const MAPGEO = {
// }) // })
}, },
transferAddressByGroup(obj, cb) { transferAddressByGroup(obj, cb) {
console.log(obj,'obj')
if (!this.geocoder) { if (!this.geocoder) {
this.getGeocoder().then(() => { this.getGeocoder().then(() => {
this.transfer(obj, cb) this.transfer(obj, cb)
...@@ -79,7 +79,7 @@ const MAPGEO = { ...@@ -79,7 +79,7 @@ const MAPGEO = {
arr.forEach(item=>{ arr.forEach(item=>{
let o=AMap.invoke('Point',...item) let o=AMap.invoke('Point',...item)
MAPGEO.geocoder.getLocation( o,function(res){ MAPGEO.geocoder.getLocation( o,function(res){
console.log(res,'res')
setAddress(o, res); setAddress(o, res);
obj.totalNum++; obj.totalNum++;
if (obj.totalNum === obj.realNum) { if (obj.totalNum === obj.realNum) {
......
...@@ -21,6 +21,8 @@ const replay = { ...@@ -21,6 +21,8 @@ const replay = {
times: 1, times: 1,
timeoutIds: [], timeoutIds: [],
data: [], data: [],
dis:[],
distance:'',
markers: {}, markers: {},
infowins: {}, infowins: {},
speed: 1, speed: 1,
...@@ -35,27 +37,35 @@ const replay = { ...@@ -35,27 +37,35 @@ const replay = {
}, },
init(){ init(){
var replayData = [] var replayData = [];
replay.data.reduce(function(prev ,item ){
replay.data.forEach(function(item){ // console.log(prev ,item)
let prevLnglat=mapService.getLngLat(prev.blng,prev.blat)
let lnglat=mapService.getLngLat(item.blng,item.blat) let lnglat=mapService.getLngLat(item.blng,item.blat)
replay.dis.push(replay.getDistance(prevLnglat,lnglat))
replayData.push(lnglat) replayData.push(lnglat)
return item
}); });
let p1=replayData[0]; let p1=replayData[0];
let p2=replayData[replayData.length-1]; let p2=replayData[replayData.length-1];
let line = AMap.invoke('Polyline', replayData, { strokeColor: '#0b94db',strokeWeight: 6 }) let line = AMap.invoke('Polyline', replayData, { strokeColor: '#0b94db',strokeWeight: 6 })
replay.startMarker = mapService.createStartMarker(p1, AMap); replay.startMarker = mapService.createStartMarker(p1, AMap);
replay.endMarker = mapService.createEndMarker(p2, AMap); replay.endMarker = mapService.createEndMarker(p2, AMap);
replay.dis = AMap.invoke('getDistance', p1, p2)/1000 // 算出轨迹的距离(km) // replay.dis = AMap.invoke('getDistance', p1, p2)/1000 // 算出轨迹的距离(km)
AMap.invoke('setViewport',replayData); AMap.invoke('setViewport',replayData);
AMap.invoke('addOverlay', line) AMap.invoke('addOverlay', line)
AMap.invoke('addOverlay', replay.startMarker) AMap.invoke('addOverlay', replay.startMarker)
AMap.invoke('addOverlay', replay.endMarker ) AMap.invoke('addOverlay', replay.endMarker )
replay.distance=replay.dis.reduce(function (prev, cur, index, arr) {
return prev + cur;
});
// replay.distance= parseInt(replay.distance/1000)//算出轨迹的距离(km)
const firstItem = replay.data[0]; const firstItem = replay.data[0];
replay.navg= AMap.invoke('LuShu', replayData, { replay.navg= AMap.invoke('LuShu', replayData, {
defaultContent: replay.getNavgInfoContent(firstItem), defaultContent: replay.getNavgInfoContent(firstItem),
autoView: true, // 是否开启自动视野调整,如果开启那么路书在运动过程中会根据视野自动调整 autoView: true, // 是否开启自动视野调整,如果开启那么路书在运动过程中会根据视野自动调整
speed: replay.getSpeed(replay.speed, replay.dis), speed: replay.getSpeed(replay.speed, replay.distance),
icon: AMap.invoke('Icon', 'https://e-shield-old.glsx.com.cn/images/icon_car.png', AMap.invoke('Size', 36, 22),{ anchor: AMap.invoke('Size',18, 11) }), icon: AMap.invoke('Icon', 'https://e-shield-old.glsx.com.cn/images/icon_car.png', AMap.invoke('Size', 36, 22),{ anchor: AMap.invoke('Size',18, 11) }),
enableRotation: true, // 是否设置marker随着道路的走向进行旋转 enableRotation: true, // 是否设置marker随着道路的走向进行旋转
}) })
...@@ -66,18 +76,19 @@ const replay = { ...@@ -66,18 +76,19 @@ const replay = {
EventBus.$emit('uiMap.replay.initDone') EventBus.$emit('uiMap.replay.initDone')
AMap.invoke('lushuAddEventListener','move', (e) =>{ AMap.invoke('lushuAddEventListener','move', (e) =>{
this.idx = e.target.i; this.idx = e.target.i;
console.log(this.idx)
let lnglat = replayData[this.idx] let lnglat = replayData[this.idx]
let item=replay.data[this.idx] let item=replay.data[this.idx]
AMap.invoke('lushuSetContent',replay.getNavgInfoContent(item)) //设置信息窗口文案 AMap.invoke('lushuSetContent',replay.getNavgInfoContent(item)) //设置信息窗口文案
EventBus.$emit('uiMap.replay.currAddress', ''); EventBus.$emit('uiMap.replay.currAddress', '');
console.log(this.idx,replay.data.length-1)
if(this.idx >= replay.data.length-2){ if(this.idx >= replay.data.length-2){
EventBus.$emit('uiMap.replay.done'); EventBus.$emit('uiMap.replay.done');
} }
}); });
}, },
getDistance (p1, p2) {
return AMap.invoke('getDistance', p1, p2);
},
getNavgInfoContent(item){ getNavgInfoContent(item){
return `<div class="navg-info-window"> return `<div class="navg-info-window">
<div class="tit">${item.dateTime}</div> <div class="tit">${item.dateTime}</div>
...@@ -106,7 +117,9 @@ const replay = { ...@@ -106,7 +117,9 @@ const replay = {
bindEvent(){ bindEvent(){
//解析轨迹地址 //解析轨迹地址
EventBus.$on('uiMap.replay.transferAdr', function(data){ EventBus.$on('uiMap.replay.transferAdr', function(data){
// console.log(data)
replay.data = data; replay.data = data;
replay.transferAddressByGroup(); replay.transferAddressByGroup();
}); });
...@@ -237,15 +250,14 @@ const replay = { ...@@ -237,15 +250,14 @@ const replay = {
// //mapService.setFitView(MAP); // //mapService.setFitView(MAP);
// }, // },
speedEvent(idx, dis) { speedEvent(idx, dis) {
console.log(idx, dis)
let timeArr = [[40, 30, 16], [30, 20, 12], [20, 12, 8], [5, 3, 2]] // 慢 正常 快 很快 let timeArr = [[40, 30, 16], [30, 20, 12], [20, 12, 8], [5, 3, 2]] // 慢 正常 快 很快
let speed let speed
if (dis >= 100) { // 100公里以上 if (dis >= 100) { // 100公里以上
speed = Math.floor((dis / timeArr[idx][0]) * 3600) speed = Math.floor((dis / timeArr[idx][0]))
} else if (dis > 10 && dis < 100) { // 10-100公里 } else if (dis > 10 && dis < 100) { // 10-100公里
speed = Math.floor((dis / timeArr[idx][1]) * 3600) speed = Math.floor((dis / timeArr[idx][1]))
} else { // 10公里以内 } else { // 10公里以内
speed = Math.floor((dis / timeArr[idx][2]) * 3600) speed = Math.floor((dis / timeArr[idx][2]))
} }
return speed return speed
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!