This commit is contained in:
tx 2024-12-27 10:29:51 +08:00
parent fcaba878f5
commit 7c86916a53
2 changed files with 177 additions and 41 deletions

View File

@ -1,5 +1,5 @@
<template>
<div class="place-search-map" :style="{ width: width, height: height }" v-loading="loading">
<div class="place-search-map" :style="{ width: width, height: height }" >
<div id="container"></div>
<!-- 轨迹回放控制面板 -->
@ -72,6 +72,10 @@
<span class="label">锁状态:</span>
<span class="value">{{ currentLockStatus }}</span>
</div>
<div class="info-item">
<span class="label">电门:</span>
<span class="value">{{ currentEleLock }}</span>
</div>
</div>
</div>
</div>
@ -162,7 +166,8 @@ export default {
parkingPolygons: [],
currentStatus: '',
currentBattery: '',
currentLockStatus: ''
currentLockStatus: '',
currentEleLock: ''
}
},
@ -175,7 +180,7 @@ export default {
//
await this.getAreas()
//
} catch (error) {
console.error('初始化失败:', error)
this.$message.error('初始化失败')
@ -217,6 +222,35 @@ export default {
});
});
},
clearTrackData() {
if (this.polyline) {
this.map.remove(this.polyline);
}
if (this.passedPolyline) {
this.map.remove(this.passedPolyline);
}
if (this.marker) {
this.map.remove(this.marker);
}
//
if (this.startMarker) {
this.map.remove(this.startMarker);
}
if (this.endMarker) {
this.map.remove(this.endMarker);
}
this.trackPoints = [];
this.currentProgress = 0;
this.currentPoint = null;
this.currentPointTime = '';
this.currentSpeed = '0.00';
this.location = '';
this.currentStatus = '';
this.currentBattery = '';
this.currentLockStatus = '';
this.currentEleLock = ''
},
formatStatus(status) {
const statusMap = {
'0': '仓库中',
@ -256,7 +290,7 @@ export default {
initMarker() {
this.removeAllMarker()
if (this.currentLng != null && this.currentLat != null) {
this.updateTrackData()
this.updateTrackData()
this.addArea(JSON.parse(this.area.boundaryStr) || []);
//
this.parkingList.forEach(parking => {
@ -576,6 +610,11 @@ export default {
async updateTrackData() {
try {
//
this.stopPlayback()
//
this.clearTrackData()
const params = {
sn: this.deviceSn,
startTime: this.startTime,
@ -586,23 +625,26 @@ export default {
if (res.code === 200) {
if (!res.data?.length) {
this.$message.warning('该时间段内无轨迹数据')
this.clearTrackData()
return
}
//
//
this.trackPoints = res.data.map(point => ({
latitude: parseFloat(point.latitude),
longitude: parseFloat(point.longitude),
time: point.at,
status: point.status,
onlineStatus: point.onlineStatus
onlineStatus: point.onlineStatus,
bat: point.bat,
lockStatus: point.lockStatus,
q: point.q
}))
// 线
// 线
this.drawTrackLine()
//
this.resetPlayback()
//
this.currentProgress = 0
this.updateMapPoint(0)
}
} catch (error) {
console.error("获取轨迹数据失败:", error)
@ -610,6 +652,48 @@ export default {
}
},
clearTrackData() {
//
if (this.playbackTimer) {
clearInterval(this.playbackTimer)
this.playbackTimer = null
}
//
if (this.polyline) {
this.map.remove(this.polyline)
this.polyline = null
}
if (this.passedPolyline) {
this.map.remove(this.passedPolyline)
this.passedPolyline = null
}
if (this.marker) {
this.map.remove(this.marker)
this.marker = null
}
if (this.startMarker) {
this.map.remove(this.startMarker)
this.startMarker = null
}
if (this.endMarker) {
this.map.remove(this.endMarker)
this.endMarker = null
}
//
this.trackPoints = []
this.currentProgress = 0
this.currentPoint = null
this.currentPointTime = ''
this.currentSpeed = '0.00'
this.location = ''
this.currentStatus = ''
this.currentBattery = ''
this.currentLockStatus = ''
this.currentEleLock = ''
this.isPlaying = false
},
processTrackData(data) {
this.trackPoints = data.map(point => ({
latitude: parseFloat(point.latitude),
@ -631,6 +715,12 @@ export default {
if (this.polyline) {
this.map.remove(this.polyline)
}
if (this.passedPolyline) {
this.map.remove(this.passedPolyline)
}
if (this.marker) {
this.map.remove(this.marker)
}
// 线
this.polyline = new this.AMap.Polyline({
@ -701,6 +791,7 @@ export default {
this.currentStatus = ''
this.currentBattery = ''
this.currentLockStatus = ''
this.currentEleLock = ''
},
updateMapPoint(index) {
@ -710,43 +801,91 @@ export default {
this.currentPoint = point
this.currentPointTime = point.time
this.location = `${point.longitude}, ${point.latitude}`
//
console.log(point,'pointpointpoint');
//
this.currentStatus = this.formatStatus(point.status)
this.currentBattery = point.bta == null ? '未知' : (point.bta / 10).toFixed(1) + 'V'
this.currentBattery = point.bat == null ? '未知' : (point.bat / 10).toFixed(1) + 'V'
this.currentLockStatus = point.lockStatus == '0' ? '关锁' : '开锁'
this.currentEleLock = point.q == null ? '未知' : (point.q == '0' ? '关锁' : '开锁')
//
if (index > 0) {
const prevPoint = this.trackPoints[index - 1]
const distance = this.calculateDistance(
// 使 Haversine
const distance = this.calculateHaversineDistance(
prevPoint.latitude,
prevPoint.longitude,
point.latitude,
point.longitude
)
const timeGap = (new Date(point.time) - new Date(prevPoint.time)) / 1000
this.currentSpeed = timeGap > 0 ? ((distance / timeGap) * 3.6).toFixed(1) : '0.00'
//
const timeGap = (new Date(point.time) - new Date(prevPoint.time)) / (1000 * 3600)
// /
this.currentSpeed = timeGap > 0 ? (distance / timeGap).toFixed(2) : '0.00'
} else {
this.currentSpeed = '0.00'
}
// 线
this.updatePassedPolyline(index)
this.updateMarkerPosition(point)
//
if (!this.marker) {
this.marker = new this.AMap.Marker({
position: [point.longitude, point.latitude],
icon: this.getMarkerIcon(point.status, point.onlineStatus),
offset: new this.AMap.Pixel(-12.5, -19.5)
})
this.map.add(this.marker)
} else {
this.marker.setPosition([point.longitude, point.latitude])
this.marker.setIcon(this.getMarkerIcon(point.status, point.onlineStatus))
}
},
// Haversine
calculateHaversineDistance(lat1, lon1, lat2, lon2) {
//
const R = 6371
//
const dLat = this.toRad(lat2 - lat1)
const dLon = this.toRad(lon2 - lon1)
const radLat1 = this.toRad(lat1)
const radLat2 = this.toRad(lat2)
// Haversine
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(radLat1) * Math.cos(radLat2)
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
//
return R * c
},
//
toRad(degrees) {
return degrees * Math.PI / 180
},
updatePassedPolyline(index) {
const passedPath = this.trackPoints
.slice(0, index + 1)
.map(p => [p.longitude, p.latitude])
if (!this.passedPolyline) {
this.passedPolyline = new this.AMap.Polyline({
path: passedPath,
strokeColor: "#AF5",
strokeWeight: 6
})
this.map.add(this.passedPolyline)
} else {
this.passedPolyline.setPath(passedPath)
// 线
if (this.passedPolyline) {
this.map.remove(this.passedPolyline)
}
// 线
this.passedPolyline = new this.AMap.Polyline({
path: passedPath,
strokeColor: "#AF5",
strokeWeight: 6
})
this.map.add(this.passedPolyline)
},
updateMarkerPosition(point) {
@ -770,17 +909,14 @@ export default {
},
startPlayback() {
if (this.playbackTimer) return
if (this.playbackTimer) {
clearInterval(this.playbackTimer)
}
this.playbackTimer = setInterval(() => {
if (this.currentProgress >= this.trackPoints.length - 1) {
this.pausePlayback()
this.isPlaying = false
//
setTimeout(() => {
this.currentProgress = 0
this.updateMapPoint(0)
}, 1000)
return
}
this.currentProgress++
@ -794,12 +930,12 @@ export default {
this.playbackTimer = null
}
},
stopPlayback() {
this.pausePlayback()
if (this.playbackTimer) {
clearInterval(this.playbackTimer)
this.playbackTimer = null
}
this.isPlaying = false
this.currentProgress = 0
this.updateMapPoint(0) //
},
changeSpeed(direction) {
@ -852,13 +988,15 @@ export default {
},
onSliderChange(value) {
this.stopPlayback() //
this.currentProgress = value
this.updateMapPoint(value)
},
onSliderChanging(value) {
// this.stopPlayback() //
this.updateMapPoint(value)
}
},
}
}
</script>

View File

@ -1349,7 +1349,7 @@ handleAreaChange(val) {
// this.fetchData(response.data.deptId)
// this.open = true;
// this.title = "1";
if (response.data.deptId) {
selectAreaListByDeptId(response.data.deptId).then((res) => {
// 1: 使Vue.set
setTimeout(() => {
@ -1375,9 +1375,7 @@ handleAreaChange(val) {
}).finally(() => {
this.isUpdating = false;
});
} else {
this.isUpdating = false;
}
});
},
handleListing(row) {