feat():合并

dev
chentaisen 2024-10-08 09:21:24 +08:00
parent 4daecfda92
commit 8ee741606c
1 changed files with 32 additions and 34 deletions

View File

@ -6,7 +6,7 @@
<script>
import { getDataByRedis } from "@/api/car/ListManager";
import { getDataByRedis } from '@/api/car/ListManager'
export default {
data() {
@ -14,10 +14,10 @@ export default {
map: null,
polyline: null,
carMarker: null,
carVin: this.$route.query.carVin || null ,
carVin: this.$route.query.carVin || null,
intervalId: null,
data: {}, //
};
data: {} //
}
},
created() {
// fetchData
@ -26,26 +26,26 @@ export default {
methods: {
async fetchData() {
try {
const res = await getDataByRedis(this.carVin);
this.data = res.data;
const res = await getDataByRedis(this.carVin)
this.data = res.data
//
this.updateCarMarker();
this.updateCarMarker()
} catch (error) {
console.error("Error fetching vehicle data:", error);
console.error('Error fetching vehicle data:', error)
}
},
initMap() {
this.map = new AMap.Map('map', {
center: [116.397428, 39.90923], //
zoom: 20, //
});
zoom: 20 //
})
this.polyline = new AMap.Polyline({
map: this.map,
path: [], //
strokeColor: '#3366FF',
strokeWeight: 5,
});
strokeWeight: 5
})
//
this.carMarker = new AMap.Marker({
@ -53,43 +53,41 @@ export default {
position: [116.397428, 39.90923], //
icon: 'https://webapi.amap.com/images/car.png',
offset: new AMap.Pixel(-26, -13),
autoRotation: true,
});
autoRotation: true
})
},
updateCarMarker() {
if (this.data.longitude && this.data.latitude) {
const newPoint = [this.data.longitude, this.data.latitude];
const newPoint = [this.data.longitude, this.data.latitude]
//
this.carMarker.setPosition(newPoint);
this.carMarker.setPosition(newPoint)
// 线
const path = this.polyline.getPath();
path.push(new AMap.LngLat(this.data.longitude, this.data.latitude));
this.polyline.setPath(path);
const path = this.polyline.getPath()
path.push(new AMap.LngLat(this.data.longitude, this.data.latitude))
this.polyline.setPath(path)
//
this.map.setCenter(newPoint);
this.map.setCenter(newPoint)
}
},
}
},
mounted() {
this.$store.dispatch('app/toggleSideBarHide',true);
document.querySelector('.navbar').style.display = 'none';
document.querySelector('.tags-view-container').style.display = 'none';
this.$store.dispatch('app/toggleSideBarHide', true)
document.querySelector('.navbar').style.display = 'none'
document.querySelector('.tags-view-container').style.display = 'none'
const script = document.createElement('script');
script.src = 'https://webapi.amap.com/maps?v=1.4.15&key=7df1851ffb059e1e75c31b9bcd892b6b';
const script = document.createElement('script')
script.src = 'https://webapi.amap.com/maps?v=1.4.15&key=7df1851ffb059e1e75c31b9bcd892b6b'
script.onload = () => {
this.initMap();
};
document.head.appendChild(script);
this.initMap();
this.initMap()
}
document.head.appendChild(script)
this.initMap()
}
},
};
}
</script>